MainFlowControl.cpp 59 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784
  1. #include "MainFlowControl.h"
  2. #include <string>
  3. #include <vector>
  4. #include "string.h"
  5. #include "esp_log.h"
  6. #include <esp_timer.h>
  7. #include <iomanip>
  8. #include <sstream>
  9. #include "../../include/defines.h"
  10. #include "Helper.h"
  11. #include "statusled.h"
  12. #include "esp_camera.h"
  13. #include "time_sntp.h"
  14. #include "ClassControllCamera.h"
  15. #include "ClassFlowControll.h"
  16. #include "ClassLogFile.h"
  17. #include "server_GPIO.h"
  18. #include "server_file.h"
  19. #include "read_wlanini.h"
  20. #include "connect_wlan.h"
  21. #include "psram.h"
  22. // support IDF 5.x
  23. #ifndef portTICK_RATE_MS
  24. #define portTICK_RATE_MS portTICK_PERIOD_MS
  25. #endif
  26. ClassFlowControll flowctrl;
  27. camera_flow_config_temp_t CFstatus;
  28. TaskHandle_t xHandletask_autodoFlow = NULL;
  29. bool bTaskAutoFlowCreated = false;
  30. bool flowisrunning = false;
  31. long auto_interval = 0;
  32. bool autostartIsEnabled = false;
  33. int countRounds = 0;
  34. bool isPlannedReboot = false;
  35. static const char *TAG = "MAINCTRL";
  36. // #define DEBUG_DETAIL_ON
  37. void CheckIsPlannedReboot(void)
  38. {
  39. FILE *pfile;
  40. if ((pfile = fopen("/sdcard/reboot.txt", "r")) == NULL)
  41. {
  42. // LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "Initial boot or not a planned reboot");
  43. isPlannedReboot = false;
  44. }
  45. else
  46. {
  47. LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "Planned reboot");
  48. DeleteFile("/sdcard/reboot.txt"); // Prevent Boot Loop!!!
  49. isPlannedReboot = true;
  50. }
  51. }
  52. bool getIsPlannedReboot(void)
  53. {
  54. return isPlannedReboot;
  55. }
  56. int getCountFlowRounds(void)
  57. {
  58. return countRounds;
  59. }
  60. esp_err_t GetJPG(std::string _filename, httpd_req_t *req)
  61. {
  62. return flowctrl.GetJPGStream(_filename, req);
  63. }
  64. esp_err_t GetRawJPG(httpd_req_t *req)
  65. {
  66. return flowctrl.SendRawJPG(req);
  67. }
  68. bool isSetupModusActive(void)
  69. {
  70. return flowctrl.getStatusSetupModus();
  71. }
  72. void DeleteMainFlowTask(void)
  73. {
  74. #ifdef DEBUG_DETAIL_ON
  75. ESP_LOGD(TAG, "DeleteMainFlowTask: xHandletask_autodoFlow: %ld", (long)xHandletask_autodoFlow);
  76. #endif
  77. if (xHandletask_autodoFlow != NULL)
  78. {
  79. vTaskDelete(xHandletask_autodoFlow);
  80. xHandletask_autodoFlow = NULL;
  81. }
  82. #ifdef DEBUG_DETAIL_ON
  83. ESP_LOGD(TAG, "Killed: xHandletask_autodoFlow");
  84. #endif
  85. }
  86. void doInit(void)
  87. {
  88. #ifdef DEBUG_DETAIL_ON
  89. ESP_LOGD(TAG, "Start flowctrl.InitFlow(config);");
  90. #endif
  91. flowctrl.InitFlow(CONFIG_FILE);
  92. #ifdef DEBUG_DETAIL_ON
  93. ESP_LOGD(TAG, "Finished flowctrl.InitFlow(config);");
  94. #endif
  95. /* GPIO handler has to be initialized before MQTT init to ensure proper topic subscription */
  96. gpio_handler_init();
  97. #ifdef ENABLE_MQTT
  98. flowctrl.StartMQTTService();
  99. #endif // ENABLE_MQTT
  100. }
  101. bool doflow(void)
  102. {
  103. std::string zw_time = getCurrentTimeString(LOGFILE_TIME_FORMAT);
  104. ESP_LOGD(TAG, "doflow - start %s", zw_time.c_str());
  105. flowisrunning = true;
  106. flowctrl.doFlow(zw_time);
  107. flowisrunning = false;
  108. #ifdef DEBUG_DETAIL_ON
  109. ESP_LOGD(TAG, "doflow - end %s", zw_time.c_str());
  110. #endif
  111. return true;
  112. }
  113. esp_err_t setCCstatusToCFstatus(void)
  114. {
  115. CFstatus.CamSensor_id = CCstatus.CamSensor_id;
  116. CFstatus.ImageFrameSize = CCstatus.ImageFrameSize;
  117. CFstatus.ImageGainceiling = CCstatus.ImageGainceiling;
  118. CFstatus.ImageQuality = CCstatus.ImageQuality;
  119. CFstatus.ImageBrightness = CCstatus.ImageBrightness;
  120. CFstatus.ImageContrast = CCstatus.ImageContrast;
  121. CFstatus.ImageSaturation = CCstatus.ImageSaturation;
  122. CFstatus.ImageSharpness = CCstatus.ImageSharpness;
  123. CFstatus.ImageAutoSharpness = CCstatus.ImageAutoSharpness;
  124. CFstatus.ImageWbMode = CCstatus.ImageWbMode;
  125. CFstatus.ImageAwb = CCstatus.ImageAwb;
  126. CFstatus.ImageAwbGain = CCstatus.ImageAwbGain;
  127. CFstatus.ImageAec = CCstatus.ImageAec;
  128. CFstatus.ImageAec2 = CCstatus.ImageAec2;
  129. CFstatus.ImageAeLevel = CCstatus.ImageAeLevel;
  130. CFstatus.ImageAecValue = CCstatus.ImageAecValue;
  131. CFstatus.ImageAgc = CCstatus.ImageAgc;
  132. CFstatus.ImageAgcGain = CCstatus.ImageAgcGain;
  133. CFstatus.ImageBpc = CCstatus.ImageBpc;
  134. CFstatus.ImageWpc = CCstatus.ImageWpc;
  135. CFstatus.ImageRawGma = CCstatus.ImageRawGma;
  136. CFstatus.ImageLenc = CCstatus.ImageLenc;
  137. CFstatus.ImageSpecialEffect = CCstatus.ImageSpecialEffect;
  138. CFstatus.ImageHmirror = CCstatus.ImageHmirror;
  139. CFstatus.ImageVflip = CCstatus.ImageVflip;
  140. CFstatus.ImageDcw = CCstatus.ImageDcw;
  141. CFstatus.ImageDenoiseLevel = CCstatus.ImageDenoiseLevel;
  142. CFstatus.ImageLedIntensity = CCstatus.ImageLedIntensity;
  143. CFstatus.ImageZoomEnabled = CCstatus.ImageZoomEnabled;
  144. CFstatus.ImageZoomOffsetX = CCstatus.ImageZoomOffsetX;
  145. CFstatus.ImageZoomOffsetY = CCstatus.ImageZoomOffsetY;
  146. CFstatus.ImageZoomSize = CCstatus.ImageZoomSize;
  147. CFstatus.WaitBeforePicture = CCstatus.WaitBeforePicture;
  148. return ESP_OK;
  149. }
  150. esp_err_t setCFstatusToCCstatus(void)
  151. {
  152. // CCstatus.CamSensor_id = CFstatus.CamSensor_id;
  153. CCstatus.ImageFrameSize = CFstatus.ImageFrameSize;
  154. CCstatus.ImageGainceiling = CFstatus.ImageGainceiling;
  155. CCstatus.ImageQuality = CFstatus.ImageQuality;
  156. CCstatus.ImageBrightness = CFstatus.ImageBrightness;
  157. CCstatus.ImageContrast = CFstatus.ImageContrast;
  158. CCstatus.ImageSaturation = CFstatus.ImageSaturation;
  159. CCstatus.ImageSharpness = CFstatus.ImageSharpness;
  160. CCstatus.ImageAutoSharpness = CFstatus.ImageAutoSharpness;
  161. CCstatus.ImageWbMode = CFstatus.ImageWbMode;
  162. CCstatus.ImageAwb = CFstatus.ImageAwb;
  163. CCstatus.ImageAwbGain = CFstatus.ImageAwbGain;
  164. CCstatus.ImageAec = CFstatus.ImageAec;
  165. CCstatus.ImageAec2 = CFstatus.ImageAec2;
  166. CCstatus.ImageAeLevel = CFstatus.ImageAeLevel;
  167. CCstatus.ImageAecValue = CFstatus.ImageAecValue;
  168. CCstatus.ImageAgc = CFstatus.ImageAgc;
  169. CCstatus.ImageAgcGain = CFstatus.ImageAgcGain;
  170. CCstatus.ImageBpc = CFstatus.ImageBpc;
  171. CCstatus.ImageWpc = CFstatus.ImageWpc;
  172. CCstatus.ImageRawGma = CFstatus.ImageRawGma;
  173. CCstatus.ImageLenc = CFstatus.ImageLenc;
  174. CCstatus.ImageSpecialEffect = CFstatus.ImageSpecialEffect;
  175. CCstatus.ImageHmirror = CFstatus.ImageHmirror;
  176. CCstatus.ImageVflip = CFstatus.ImageVflip;
  177. CCstatus.ImageDcw = CFstatus.ImageDcw;
  178. CCstatus.ImageDenoiseLevel = CFstatus.ImageDenoiseLevel;
  179. CCstatus.ImageLedIntensity = CFstatus.ImageLedIntensity;
  180. CCstatus.ImageZoomEnabled = CFstatus.ImageZoomEnabled;
  181. CCstatus.ImageZoomOffsetX = CFstatus.ImageZoomOffsetX;
  182. CCstatus.ImageZoomOffsetY = CFstatus.ImageZoomOffsetY;
  183. CCstatus.ImageZoomSize = CFstatus.ImageZoomSize;
  184. CCstatus.WaitBeforePicture = CFstatus.WaitBeforePicture;
  185. return ESP_OK;
  186. }
  187. esp_err_t setCFstatusToCam(void)
  188. {
  189. sensor_t *s = esp_camera_sensor_get();
  190. if (s != NULL)
  191. {
  192. s->set_framesize(s, CFstatus.ImageFrameSize);
  193. s->set_quality(s, CFstatus.ImageQuality); // 0 - 63
  194. s->set_brightness(s, CFstatus.ImageBrightness); // -2 to 2
  195. s->set_contrast(s, CFstatus.ImageContrast); // -2 to 2
  196. s->set_saturation(s, CFstatus.ImageSaturation); // -2 to 2
  197. // s->set_sharpness(s, CFstatus.ImageSharpness); // auto-sharpness is not officially supported, default to 0
  198. Camera.SetCamSharpness(CFstatus.ImageAutoSharpness, CFstatus.ImageSharpness);
  199. s->set_denoise(s, CFstatus.ImageDenoiseLevel); // The OV2640 does not support it, OV3660 and OV5640 (0 to 8)
  200. s->set_special_effect(s, CFstatus.ImageSpecialEffect); // 0 to 6 (0 - No Effect, 1 - Negative, 2 - Grayscale, 3 - Red Tint, 4 - Green Tint, 5 - Blue Tint, 6 - Sepia)
  201. s->set_wb_mode(s, CFstatus.ImageWbMode); // 0 to 4 - if awb_gain enabled (0 - Auto, 1 - Sunny, 2 - Cloudy, 3 - Office, 4 - Home)
  202. s->set_ae_level(s, CFstatus.ImageAeLevel); // -2 to 2
  203. s->set_aec_value(s, CFstatus.ImageAecValue); // 0 to 1200
  204. s->set_agc_gain(s, CFstatus.ImageAgcGain); // 0 to 30
  205. // s->set_gainceiling(s, CFstatus.ImageGainceiling); // Image gain (GAINCEILING_x2, x4, x8, x16, x32, x64 or x128)
  206. Camera.ov5640_set_gainceiling(s, CFstatus.ImageGainceiling);
  207. s->set_lenc(s, CFstatus.ImageLenc); // 0 = disable , 1 = enable
  208. s->set_gain_ctrl(s, CFstatus.ImageAgc); // 0 = disable , 1 = enable
  209. s->set_exposure_ctrl(s, CFstatus.ImageAec); // 0 = disable , 1 = enable
  210. s->set_hmirror(s, CFstatus.ImageHmirror); // 0 = disable , 1 = enable
  211. s->set_vflip(s, CFstatus.ImageVflip); // 0 = disable , 1 = enable
  212. s->set_aec2(s, CFstatus.ImageAec2); // 0 = disable , 1 = enable
  213. s->set_bpc(s, CFstatus.ImageBpc); // 0 = disable , 1 = enable
  214. s->set_wpc(s, CFstatus.ImageWpc); // 0 = disable , 1 = enable
  215. s->set_raw_gma(s, CFstatus.ImageRawGma); // 0 = disable , 1 = enable
  216. s->set_awb_gain(s, CFstatus.ImageAwbGain); // 0 = disable , 1 = enable
  217. s->set_whitebal(s, CFstatus.ImageAwb); // 0 = disable , 1 = enable
  218. s->set_dcw(s, CFstatus.ImageDcw); // 0 = disable , 1 = enable
  219. TickType_t xDelay2 = 100 / portTICK_PERIOD_MS;
  220. vTaskDelay(xDelay2);
  221. return ESP_OK;
  222. }
  223. else
  224. {
  225. return ESP_FAIL;
  226. }
  227. }
  228. esp_err_t handler_get_heap(httpd_req_t *req)
  229. {
  230. #ifdef DEBUG_DETAIL_ON
  231. LogFile.WriteHeapInfo("handler_get_heap - Start");
  232. ESP_LOGD(TAG, "handler_get_heap uri: %s", req->uri);
  233. #endif
  234. std::string zw = "Heap info:<br>" + getESPHeapInfo();
  235. #ifdef TASK_ANALYSIS_ON
  236. char *pcTaskList = (char *)calloc_psram_heap(std::string(TAG) + "->pcTaskList", 1, sizeof(char) * 768, MALLOC_CAP_8BIT | MALLOC_CAP_SPIRAM);
  237. if (pcTaskList)
  238. {
  239. vTaskList(pcTaskList);
  240. zw = zw + "<br><br>Task info:<br><pre>Name | State | Prio | Lowest stacksize | Creation order | CPU (-1=NoAffinity)<br>" + std::string(pcTaskList) + "</pre>";
  241. free_psram_heap(std::string(TAG) + "->pcTaskList", pcTaskList);
  242. }
  243. else
  244. {
  245. zw = zw + "<br><br>Task info:<br>ERROR - Allocation of TaskList buffer in PSRAM failed";
  246. }
  247. #endif
  248. httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*");
  249. if (zw.length() > 0)
  250. {
  251. httpd_resp_send(req, zw.c_str(), zw.length());
  252. }
  253. else
  254. {
  255. httpd_resp_send(req, NULL, 0);
  256. }
  257. #ifdef DEBUG_DETAIL_ON
  258. LogFile.WriteHeapInfo("handler_get_heap - Done");
  259. #endif
  260. return ESP_OK;
  261. }
  262. esp_err_t handler_init(httpd_req_t *req)
  263. {
  264. #ifdef DEBUG_DETAIL_ON
  265. LogFile.WriteHeapInfo("handler_init - Start");
  266. ESP_LOGD(TAG, "handler_doinit uri: %s", req->uri);
  267. #endif
  268. httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*");
  269. const char *resp_str = "Init started<br>";
  270. httpd_resp_send(req, resp_str, HTTPD_RESP_USE_STRLEN);
  271. doInit();
  272. resp_str = "Init done<br>";
  273. httpd_resp_send(req, resp_str, HTTPD_RESP_USE_STRLEN);
  274. #ifdef DEBUG_DETAIL_ON
  275. LogFile.WriteHeapInfo("handler_init - Done");
  276. #endif
  277. return ESP_OK;
  278. }
  279. esp_err_t handler_stream(httpd_req_t *req)
  280. {
  281. #ifdef DEBUG_DETAIL_ON
  282. LogFile.WriteHeapInfo("handler_stream - Start");
  283. ESP_LOGD(TAG, "handler_stream uri: %s", req->uri);
  284. #endif
  285. char _query[50];
  286. char _value[10];
  287. bool flashlightOn = false;
  288. if (httpd_req_get_url_query_str(req, _query, 50) == ESP_OK)
  289. {
  290. // ESP_LOGD(TAG, "Query: %s", _query);
  291. if (httpd_query_key_value(_query, "flashlight", _value, 10) == ESP_OK)
  292. {
  293. #ifdef DEBUG_DETAIL_ON
  294. ESP_LOGD(TAG, "flashlight is found%s", _value);
  295. #endif
  296. if (strlen(_value) > 0)
  297. {
  298. flashlightOn = true;
  299. }
  300. }
  301. }
  302. Camera.CaptureToStream(req, flashlightOn);
  303. #ifdef DEBUG_DETAIL_ON
  304. LogFile.WriteHeapInfo("handler_stream - Done");
  305. #endif
  306. return ESP_OK;
  307. }
  308. esp_err_t handler_flow_start(httpd_req_t *req)
  309. {
  310. #ifdef DEBUG_DETAIL_ON
  311. LogFile.WriteHeapInfo("handler_flow_start - Start");
  312. #endif
  313. ESP_LOGD(TAG, "handler_flow_start uri: %s", req->uri);
  314. httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*");
  315. if (autostartIsEnabled)
  316. {
  317. xTaskAbortDelay(xHandletask_autodoFlow); // Delay will be aborted if task is in blocked (waiting) state. If task is already running, no action
  318. LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "Flow start triggered by REST API /flow_start");
  319. const char *resp_str = "The flow is going to be started immediately or is already running";
  320. httpd_resp_send(req, resp_str, HTTPD_RESP_USE_STRLEN);
  321. }
  322. else
  323. {
  324. LogFile.WriteToFile(ESP_LOG_WARN, TAG, "Flow start triggered by REST API, but flow is not active!");
  325. const char *resp_str = "WARNING: Flow start triggered by REST API, but flow is not active";
  326. httpd_resp_send(req, resp_str, HTTPD_RESP_USE_STRLEN);
  327. }
  328. #ifdef DEBUG_DETAIL_ON
  329. LogFile.WriteHeapInfo("handler_flow_start - Done");
  330. #endif
  331. return ESP_OK;
  332. }
  333. #ifdef ENABLE_MQTT
  334. esp_err_t MQTTCtrlFlowStart(std::string _topic)
  335. {
  336. #ifdef DEBUG_DETAIL_ON
  337. LogFile.WriteHeapInfo("MQTTCtrlFlowStart - Start");
  338. #endif
  339. ESP_LOGD(TAG, "MQTTCtrlFlowStart: topic %s", _topic.c_str());
  340. if (autostartIsEnabled)
  341. {
  342. xTaskAbortDelay(xHandletask_autodoFlow); // Delay will be aborted if task is in blocked (waiting) state. If task is already running, no action
  343. LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "Flow start triggered by MQTT topic " + _topic);
  344. }
  345. else
  346. {
  347. LogFile.WriteToFile(ESP_LOG_WARN, TAG, "Flow start triggered by MQTT topic " + _topic + ", but flow is not active!");
  348. }
  349. #ifdef DEBUG_DETAIL_ON
  350. LogFile.WriteHeapInfo("MQTTCtrlFlowStart - Done");
  351. #endif
  352. return ESP_OK;
  353. }
  354. #endif // ENABLE_MQTT
  355. esp_err_t handler_json(httpd_req_t *req)
  356. {
  357. #ifdef DEBUG_DETAIL_ON
  358. LogFile.WriteHeapInfo("handler_json - Start");
  359. #endif
  360. ESP_LOGD(TAG, "handler_JSON uri: %s", req->uri);
  361. if (bTaskAutoFlowCreated)
  362. {
  363. httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*");
  364. httpd_resp_set_type(req, "application/json");
  365. std::string zw = flowctrl.getJSON();
  366. if (zw.length() > 0)
  367. {
  368. httpd_resp_send(req, zw.c_str(), zw.length());
  369. }
  370. else
  371. {
  372. httpd_resp_send(req, NULL, 0);
  373. }
  374. }
  375. else
  376. {
  377. httpd_resp_send_err(req, HTTPD_403_FORBIDDEN, "Flow not (yet) started: REST API /json not yet available!");
  378. return ESP_ERR_NOT_FOUND;
  379. }
  380. #ifdef DEBUG_DETAIL_ON
  381. LogFile.WriteHeapInfo("handler_JSON - Done");
  382. #endif
  383. return ESP_OK;
  384. }
  385. /**
  386. * Generates a http response containing the OpenMetrics (https://openmetrics.io/) text wire format
  387. * according to https://github.com/OpenObservability/OpenMetrics/blob/main/specification/OpenMetrics.md#text-format.
  388. *
  389. * A MetricFamily with a Metric for each Sequence is provided. If no valid value is available, the metric is not provided.
  390. * MetricPoints are provided without a timestamp. Additional metrics with some device information is also provided.
  391. *
  392. * The metric name prefix is 'ai_on_the_edge_device_'.
  393. *
  394. * example configuration for Prometheus (`prometheus.yml`):
  395. *
  396. * - job_name: watermeter
  397. * static_configs:
  398. * - targets: ['watermeter.fritz.box']
  399. *
  400. */
  401. esp_err_t handler_openmetrics(httpd_req_t *req)
  402. {
  403. #ifdef DEBUG_DETAIL_ON
  404. LogFile.WriteHeapInfo("handler_openmetrics - Start");
  405. #endif
  406. ESP_LOGD(TAG, "handler_openmetrics uri: %s", req->uri);
  407. if (bTaskAutoFlowCreated)
  408. {
  409. httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*");
  410. httpd_resp_set_type(req, "text/plain"); // application/openmetrics-text is not yet supported by prometheus so we use text/plain for now
  411. const string metricNamePrefix = "ai_on_the_edge_device";
  412. // get current measurement (flow)
  413. string response = createSequenceMetrics(metricNamePrefix, flowctrl.getNumbers());
  414. // CPU Temperature
  415. response += createMetric(metricNamePrefix + "_cpu_temperature_celsius", "current cpu temperature in celsius", "gauge", std::to_string((int)temperatureRead()));
  416. // WiFi signal strength
  417. response += createMetric(metricNamePrefix + "_rssi_dbm", "current WiFi signal strength in dBm", "gauge", std::to_string(get_WIFI_RSSI()));
  418. // memory info
  419. response += createMetric(metricNamePrefix + "_memory_heap_free_bytes", "available heap memory", "gauge", std::to_string(getESPHeapSize()));
  420. // device uptime
  421. response += createMetric(metricNamePrefix + "_uptime_seconds", "device uptime in seconds", "gauge", std::to_string((long)getUpTime()));
  422. // data aquisition round
  423. response += createMetric(metricNamePrefix + "_rounds_total", "data aquisition rounds since device startup", "counter", std::to_string(countRounds));
  424. // the response always contains at least the metadata (HELP, TYPE) for the MetricFamily so no length check is needed
  425. httpd_resp_send(req, response.c_str(), response.length());
  426. }
  427. else
  428. {
  429. httpd_resp_send_err(req, HTTPD_403_FORBIDDEN, "Flow not (yet) started: REST API /metrics not yet available!");
  430. return ESP_ERR_NOT_FOUND;
  431. }
  432. #ifdef DEBUG_DETAIL_ON
  433. LogFile.WriteHeapInfo("handler_openmetrics - Done");
  434. #endif
  435. return ESP_OK;
  436. }
  437. esp_err_t handler_wasserzaehler(httpd_req_t *req)
  438. {
  439. #ifdef DEBUG_DETAIL_ON
  440. LogFile.WriteHeapInfo("handler water counter - Start");
  441. #endif
  442. if (bTaskAutoFlowCreated)
  443. {
  444. bool _rawValue = false;
  445. bool _noerror = false;
  446. bool _all = false;
  447. std::string _type = "value";
  448. std::string zw;
  449. ESP_LOGD(TAG, "handler water counter uri: %s", req->uri);
  450. char _query[100];
  451. char _size[10];
  452. if (httpd_req_get_url_query_str(req, _query, 100) == ESP_OK)
  453. {
  454. // ESP_LOGD(TAG, "Query: %s", _query);
  455. if (httpd_query_key_value(_query, "all", _size, 10) == ESP_OK)
  456. {
  457. #ifdef DEBUG_DETAIL_ON
  458. ESP_LOGD(TAG, "all is found%s", _size);
  459. #endif
  460. _all = true;
  461. }
  462. if (httpd_query_key_value(_query, "type", _size, 10) == ESP_OK)
  463. {
  464. #ifdef DEBUG_DETAIL_ON
  465. ESP_LOGD(TAG, "all is found: %s", _size);
  466. #endif
  467. _type = std::string(_size);
  468. }
  469. if (httpd_query_key_value(_query, "rawvalue", _size, 10) == ESP_OK)
  470. {
  471. #ifdef DEBUG_DETAIL_ON
  472. ESP_LOGD(TAG, "rawvalue is found: %s", _size);
  473. #endif
  474. _rawValue = true;
  475. }
  476. if (httpd_query_key_value(_query, "noerror", _size, 10) == ESP_OK)
  477. {
  478. #ifdef DEBUG_DETAIL_ON
  479. ESP_LOGD(TAG, "noerror is found: %s", _size);
  480. #endif
  481. _noerror = true;
  482. }
  483. }
  484. httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*");
  485. if (_all)
  486. {
  487. httpd_resp_set_type(req, "text/plain");
  488. ESP_LOGD(TAG, "TYPE: %s", _type.c_str());
  489. int _intype = READOUT_TYPE_VALUE;
  490. if (_type == "prevalue")
  491. {
  492. _intype = READOUT_TYPE_PREVALUE;
  493. }
  494. if (_type == "raw")
  495. {
  496. _intype = READOUT_TYPE_RAWVALUE;
  497. }
  498. if (_type == "error")
  499. {
  500. _intype = READOUT_TYPE_ERROR;
  501. }
  502. zw = flowctrl.getReadoutAll(_intype);
  503. ESP_LOGD(TAG, "ZW: %s", zw.c_str());
  504. if (zw.length() > 0)
  505. {
  506. httpd_resp_send(req, zw.c_str(), zw.length());
  507. }
  508. return ESP_OK;
  509. }
  510. std::string *status = flowctrl.getActStatus();
  511. std::string query = std::string(_query);
  512. // ESP_LOGD(TAG, "Query: %s, query.c_str());
  513. if (query.find("full") != std::string::npos)
  514. {
  515. std::string txt;
  516. txt = "<body style=\"font-family: arial\">";
  517. if ((countRounds <= 1) && (*status != std::string("Flow finished")))
  518. {
  519. // First round not completed yet
  520. txt += "<h3>Please wait for the first round to complete!</h3><h3>Current state: " + *status + "</h3>\n";
  521. }
  522. else
  523. {
  524. txt += "<h3>Value</h3>";
  525. }
  526. httpd_resp_sendstr_chunk(req, txt.c_str());
  527. }
  528. zw = flowctrl.getReadout(_rawValue, _noerror, 0);
  529. if (zw.length() > 0)
  530. {
  531. httpd_resp_sendstr_chunk(req, zw.c_str());
  532. }
  533. if (query.find("full") != std::string::npos)
  534. {
  535. std::string txt, zw;
  536. if ((countRounds <= 1) && (*status != std::string("Flow finished")))
  537. {
  538. // First round not completed yet
  539. // Nothing to do
  540. }
  541. else
  542. {
  543. /* Digital ROIs */
  544. txt = "<body style=\"font-family: arial\">";
  545. txt += "<hr><h3>Recognized Digit ROIs (previous round)</h3>\n";
  546. txt += "<table style=\"border-spacing: 5px\"><tr style=\"text-align: center; vertical-align: top;\">\n";
  547. std::vector<HTMLInfo *> htmlinfodig;
  548. htmlinfodig = flowctrl.GetAllDigital();
  549. for (int i = 0; i < htmlinfodig.size(); ++i)
  550. {
  551. if (flowctrl.GetTypeDigital() == Digital)
  552. {
  553. // Numbers greater than 10 and less than 0 indicate NaN, since a Roi can only have values ​​from 0 to 9.
  554. if ((htmlinfodig[i]->val >= 10) || (htmlinfodig[i]->val < 0))
  555. {
  556. zw = "NaN";
  557. }
  558. else
  559. {
  560. zw = std::to_string((int)htmlinfodig[i]->val);
  561. }
  562. txt += "<td style=\"width: 100px\"><h4>" + zw + "</h4><p><img src=\"/img_tmp/" + htmlinfodig[i]->filename + "\"></p></td>\n";
  563. }
  564. else
  565. {
  566. std::stringstream stream;
  567. stream << std::fixed << std::setprecision(1) << htmlinfodig[i]->val;
  568. zw = stream.str();
  569. // Numbers greater than 10 and less than 0 indicate NaN, since a Roi can only have values ​​from 0 to 9.
  570. if ((std::stod(zw) >= 10) || (std::stod(zw) < 0))
  571. {
  572. zw = "NaN";
  573. }
  574. txt += "<td style=\"width: 100px\"><h4>" + zw + "</h4><p><img src=\"/img_tmp/" + htmlinfodig[i]->filename + "\"></p></td>\n";
  575. }
  576. delete htmlinfodig[i];
  577. }
  578. htmlinfodig.clear();
  579. txt += "</tr></table>\n";
  580. httpd_resp_sendstr_chunk(req, txt.c_str());
  581. /* Analog ROIs */
  582. txt = "<hr><h3>Recognized Analog ROIs (previous round)</h3>\n";
  583. txt += "<table style=\"border-spacing: 5px\"><tr style=\"text-align: center; vertical-align: top;\">\n";
  584. std::vector<HTMLInfo *> htmlinfoana;
  585. htmlinfoana = flowctrl.GetAllAnalog();
  586. for (int i = 0; i < htmlinfoana.size(); ++i)
  587. {
  588. std::stringstream stream;
  589. stream << std::fixed << std::setprecision(1) << htmlinfoana[i]->val;
  590. zw = stream.str();
  591. // Numbers greater than 10 and less than 0 indicate NaN, since a Roi can only have values ​​from 0 to 9.
  592. if ((std::stod(zw) >= 10) || (std::stod(zw) < 0))
  593. {
  594. zw = "NaN";
  595. }
  596. txt += "<td style=\"width: 150px;\"><h4>" + zw + "</h4><p><img src=\"/img_tmp/" + htmlinfoana[i]->filename + "\"></p></td>\n";
  597. delete htmlinfoana[i];
  598. }
  599. htmlinfoana.clear();
  600. txt += "</tr>\n</table>\n";
  601. httpd_resp_sendstr_chunk(req, txt.c_str());
  602. /* Full Image
  603. * Only show it after the image got taken */
  604. txt = "<hr><h3>Full Image (current round)</h3>\n";
  605. if ((*status == std::string("Initialization")) ||
  606. (*status == std::string("Initialization (delayed)")) ||
  607. (*status == std::string("Take Image")))
  608. {
  609. txt += "<p>Current state: " + *status + "</p>\n";
  610. }
  611. else
  612. {
  613. txt += "<img src=\"/img_tmp/alg_roi.jpg\">\n";
  614. }
  615. httpd_resp_sendstr_chunk(req, txt.c_str());
  616. }
  617. }
  618. /* Respond with an empty chunk to signal HTTP response completion */
  619. httpd_resp_sendstr_chunk(req, NULL);
  620. }
  621. else
  622. {
  623. httpd_resp_send_err(req, HTTPD_403_FORBIDDEN, "Flow not (yet) started: REST API /value not available!");
  624. return ESP_ERR_NOT_FOUND;
  625. }
  626. #ifdef DEBUG_DETAIL_ON
  627. LogFile.WriteHeapInfo("handler_wasserzaehler - Done");
  628. #endif
  629. return ESP_OK;
  630. }
  631. esp_err_t handler_editflow(httpd_req_t *req)
  632. {
  633. #ifdef DEBUG_DETAIL_ON
  634. LogFile.WriteHeapInfo("handler_editflow - Start");
  635. #endif
  636. ESP_LOGD(TAG, "handler_editflow uri: %s", req->uri);
  637. char _query[200];
  638. char _valuechar[30];
  639. std::string _task;
  640. if (httpd_req_get_url_query_str(req, _query, 200) == ESP_OK)
  641. {
  642. if (httpd_query_key_value(_query, "task", _valuechar, 30) == ESP_OK)
  643. {
  644. #ifdef DEBUG_DETAIL_ON
  645. ESP_LOGD(TAG, "task is found: %s", _valuechar);
  646. #endif
  647. _task = std::string(_valuechar);
  648. }
  649. }
  650. if (_task.compare("namenumbers") == 0)
  651. {
  652. ESP_LOGD(TAG, "Get NUMBER list");
  653. return get_numbers_file_handler(req);
  654. }
  655. if (_task.compare("data") == 0)
  656. {
  657. ESP_LOGD(TAG, "Get data list");
  658. return get_data_file_handler(req);
  659. }
  660. if (_task.compare("tflite") == 0)
  661. {
  662. ESP_LOGD(TAG, "Get tflite list");
  663. return get_tflite_file_handler(req);
  664. }
  665. if (_task.compare("copy") == 0)
  666. {
  667. std::string in, out, zw;
  668. httpd_query_key_value(_query, "in", _valuechar, 30);
  669. in = std::string(_valuechar);
  670. httpd_query_key_value(_query, "out", _valuechar, 30);
  671. out = std::string(_valuechar);
  672. #ifdef DEBUG_DETAIL_ON
  673. ESP_LOGD(TAG, "in: %s", in.c_str());
  674. ESP_LOGD(TAG, "out: %s", out.c_str());
  675. #endif
  676. in = "/sdcard" + in;
  677. out = "/sdcard" + out;
  678. CopyFile(in, out);
  679. zw = "Copy Done";
  680. httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*");
  681. httpd_resp_send(req, zw.c_str(), zw.length());
  682. }
  683. if (_task.compare("cutref") == 0)
  684. {
  685. std::string in, out, zw;
  686. int x = 0, y = 0, dx = 20, dy = 20;
  687. bool enhance = false;
  688. httpd_query_key_value(_query, "in", _valuechar, 30);
  689. in = std::string(_valuechar);
  690. httpd_query_key_value(_query, "out", _valuechar, 30);
  691. out = std::string(_valuechar);
  692. httpd_query_key_value(_query, "x", _valuechar, 30);
  693. std::string _x = std::string(_valuechar);
  694. if (isStringNumeric(_x))
  695. {
  696. x = std::stoi(_x);
  697. }
  698. httpd_query_key_value(_query, "y", _valuechar, 30);
  699. std::string _y = std::string(_valuechar);
  700. if (isStringNumeric(_y))
  701. {
  702. y = std::stoi(_y);
  703. }
  704. httpd_query_key_value(_query, "dx", _valuechar, 30);
  705. std::string _dx = std::string(_valuechar);
  706. if (isStringNumeric(_dx))
  707. {
  708. dx = std::stoi(_dx);
  709. }
  710. httpd_query_key_value(_query, "dy", _valuechar, 30);
  711. std::string _dy = std::string(_valuechar);
  712. if (isStringNumeric(_dy))
  713. {
  714. dy = std::stoi(_dy);
  715. }
  716. #ifdef DEBUG_DETAIL_ON
  717. ESP_LOGD(TAG, "in: %s", in.c_str());
  718. ESP_LOGD(TAG, "out: %s", out.c_str());
  719. ESP_LOGD(TAG, "x: %s", _x.c_str());
  720. ESP_LOGD(TAG, "y: %s", _y.c_str());
  721. ESP_LOGD(TAG, "dx: %s", _dx.c_str());
  722. ESP_LOGD(TAG, "dy: %s", _dy.c_str());
  723. #endif
  724. if (httpd_query_key_value(_query, "enhance", _valuechar, 10) == ESP_OK)
  725. {
  726. string _enhance = std::string(_valuechar);
  727. if (_enhance.compare("true") == 0)
  728. {
  729. enhance = true;
  730. }
  731. }
  732. in = "/sdcard" + in;
  733. out = "/sdcard" + out;
  734. std::string out2 = out.substr(0, out.length() - 4) + "_org.jpg";
  735. if ((flowctrl.SetupModeActive || (*flowctrl.getActStatus() == std::string("Flow finished"))) && psram_init_shared_memory_for_take_image_step())
  736. {
  737. LogFile.WriteToFile(ESP_LOG_INFO, TAG, "Taking image for Alignment Mark Update...");
  738. CAlignAndCutImage *caic = new CAlignAndCutImage("cutref", in);
  739. caic->CutAndSave(out2, x, y, dx, dy);
  740. delete caic;
  741. CImageBasis *cim = new CImageBasis("cutref", out2);
  742. if (enhance)
  743. {
  744. cim->Contrast(90);
  745. }
  746. cim->SaveToFile(out);
  747. delete cim;
  748. psram_deinit_shared_memory_for_take_image_step();
  749. zw = "CutImage Done";
  750. }
  751. else
  752. {
  753. LogFile.WriteToFile(ESP_LOG_WARN, TAG, std::string("Taking image for Alignment Mark not possible while device") + " is busy with a round (Current State: '" + *flowctrl.getActStatus() + "')!");
  754. zw = "Device Busy";
  755. }
  756. httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*");
  757. httpd_resp_send(req, zw.c_str(), zw.length());
  758. }
  759. // wird beim Erstellen eines neuen Referenzbildes aufgerufen
  760. std::string *sys_status = flowctrl.getActStatus();
  761. if ((sys_status->c_str() != std::string("Take Image")) && (sys_status->c_str() != std::string("Aligning")))
  762. {
  763. if ((_task.compare("test_take") == 0) || (_task.compare("cam_settings") == 0))
  764. {
  765. std::string _host = "";
  766. // laden der aktuellen Kameraeinstellungen(CCstatus) in den Zwischenspeicher(CFstatus)
  767. setCCstatusToCFstatus(); // CCstatus >>> CFstatus
  768. if (httpd_query_key_value(_query, "host", _valuechar, 30) == ESP_OK)
  769. {
  770. _host = std::string(_valuechar);
  771. }
  772. if (httpd_query_key_value(_query, "waitb", _valuechar, 30) == ESP_OK)
  773. {
  774. std::string _waitb = std::string(_valuechar);
  775. if (isStringNumeric(_waitb))
  776. {
  777. CFstatus.WaitBeforePicture = std::stoi(_valuechar);
  778. }
  779. }
  780. if (httpd_query_key_value(_query, "aecgc", _valuechar, 30) == ESP_OK)
  781. {
  782. std::string _aecgc = std::string(_valuechar);
  783. if (isStringNumeric(_aecgc))
  784. {
  785. int _aecgc_ = std::stoi(_valuechar);
  786. switch (_aecgc_)
  787. {
  788. case 1:
  789. CFstatus.ImageGainceiling = GAINCEILING_4X;
  790. break;
  791. case 2:
  792. CFstatus.ImageGainceiling = GAINCEILING_8X;
  793. break;
  794. case 3:
  795. CFstatus.ImageGainceiling = GAINCEILING_16X;
  796. break;
  797. case 4:
  798. CFstatus.ImageGainceiling = GAINCEILING_32X;
  799. break;
  800. case 5:
  801. CFstatus.ImageGainceiling = GAINCEILING_64X;
  802. break;
  803. case 6:
  804. CFstatus.ImageGainceiling = GAINCEILING_128X;
  805. break;
  806. default:
  807. CFstatus.ImageGainceiling = GAINCEILING_2X;
  808. }
  809. }
  810. }
  811. if (httpd_query_key_value(_query, "qual", _valuechar, 30) == ESP_OK)
  812. {
  813. std::string _qual = std::string(_valuechar);
  814. if (isStringNumeric(_qual))
  815. {
  816. int _qual_ = std::stoi(_valuechar);
  817. CFstatus.ImageQuality = clipInt(_qual_, 63, 6);
  818. }
  819. }
  820. if (httpd_query_key_value(_query, "bri", _valuechar, 30) == ESP_OK)
  821. {
  822. std::string _bri = std::string(_valuechar);
  823. if (isStringNumeric(_bri))
  824. {
  825. int _bri_ = std::stoi(_valuechar);
  826. CFstatus.ImageBrightness = clipInt(_bri_, 2, -2);
  827. }
  828. }
  829. if (httpd_query_key_value(_query, "con", _valuechar, 30) == ESP_OK)
  830. {
  831. std::string _con = std::string(_valuechar);
  832. if (isStringNumeric(_con))
  833. {
  834. int _con_ = std::stoi(_valuechar);
  835. CFstatus.ImageContrast = clipInt(_con_, 2, -2);
  836. }
  837. }
  838. if (httpd_query_key_value(_query, "sat", _valuechar, 30) == ESP_OK)
  839. {
  840. std::string _sat = std::string(_valuechar);
  841. if (isStringNumeric(_sat))
  842. {
  843. int _sat_ = std::stoi(_valuechar);
  844. CFstatus.ImageSaturation = clipInt(_sat_, 2, -2);
  845. }
  846. }
  847. if (httpd_query_key_value(_query, "shp", _valuechar, 30) == ESP_OK)
  848. {
  849. std::string _shp = std::string(_valuechar);
  850. if (isStringNumeric(_shp))
  851. {
  852. int _shp_ = std::stoi(_valuechar);
  853. if (CCstatus.CamSensor_id == OV2640_PID)
  854. {
  855. CFstatus.ImageSharpness = clipInt(_shp_, 2, -2);
  856. }
  857. else
  858. {
  859. CFstatus.ImageSharpness = clipInt(_shp_, 3, -3);
  860. }
  861. }
  862. }
  863. if (httpd_query_key_value(_query, "ashp", _valuechar, 30) == ESP_OK)
  864. {
  865. std::string _ashp = std::string(_valuechar);
  866. CFstatus.ImageAutoSharpness = alphanumericToBoolean(_ashp);
  867. }
  868. if (httpd_query_key_value(_query, "spe", _valuechar, 30) == ESP_OK)
  869. {
  870. std::string _spe = std::string(_valuechar);
  871. if (isStringNumeric(_spe))
  872. {
  873. int _spe_ = std::stoi(_valuechar);
  874. CFstatus.ImageSpecialEffect = clipInt(_spe_, 6, 0);
  875. }
  876. }
  877. if (httpd_query_key_value(_query, "wbm", _valuechar, 30) == ESP_OK)
  878. {
  879. std::string _wbm = std::string(_valuechar);
  880. if (isStringNumeric(_wbm))
  881. {
  882. int _wbm_ = std::stoi(_valuechar);
  883. CFstatus.ImageWbMode = clipInt(_wbm_, 4, 0);
  884. }
  885. }
  886. if (httpd_query_key_value(_query, "awb", _valuechar, 30) == ESP_OK)
  887. {
  888. std::string _awb = std::string(_valuechar);
  889. CFstatus.ImageAwb = alphanumericToBoolean(_awb);
  890. }
  891. if (httpd_query_key_value(_query, "awbg", _valuechar, 30) == ESP_OK)
  892. {
  893. std::string _awbg = std::string(_valuechar);
  894. CFstatus.ImageAwbGain = alphanumericToBoolean(_awbg);
  895. }
  896. if (httpd_query_key_value(_query, "aec", _valuechar, 30) == ESP_OK)
  897. {
  898. std::string _aec = std::string(_valuechar);
  899. CFstatus.ImageAec = alphanumericToBoolean(_aec);
  900. }
  901. if (httpd_query_key_value(_query, "aec2", _valuechar, 30) == ESP_OK)
  902. {
  903. std::string _aec2 = std::string(_valuechar);
  904. CFstatus.ImageAec2 = alphanumericToBoolean(_aec2);
  905. }
  906. if (httpd_query_key_value(_query, "ael", _valuechar, 30) == ESP_OK)
  907. {
  908. std::string _ael = std::string(_valuechar);
  909. if (isStringNumeric(_ael))
  910. {
  911. int _ael_ = std::stoi(_valuechar);
  912. if (CCstatus.CamSensor_id == OV2640_PID)
  913. {
  914. CFstatus.ImageAeLevel = clipInt(_ael_, 2, -2);
  915. }
  916. else
  917. {
  918. CFstatus.ImageAeLevel = clipInt(_ael_, 5, -5);
  919. }
  920. }
  921. }
  922. if (httpd_query_key_value(_query, "aecv", _valuechar, 30) == ESP_OK)
  923. {
  924. std::string _aecv = std::string(_valuechar);
  925. if (isStringNumeric(_aecv))
  926. {
  927. int _aecv_ = std::stoi(_valuechar);
  928. CFstatus.ImageAecValue = clipInt(_aecv_, 1200, 0);
  929. }
  930. }
  931. if (httpd_query_key_value(_query, "agc", _valuechar, 30) == ESP_OK)
  932. {
  933. std::string _agc = std::string(_valuechar);
  934. CFstatus.ImageAgc = alphanumericToBoolean(_agc);
  935. }
  936. if (httpd_query_key_value(_query, "agcg", _valuechar, 30) == ESP_OK)
  937. {
  938. std::string _agcg = std::string(_valuechar);
  939. if (isStringNumeric(_agcg))
  940. {
  941. int _agcg_ = std::stoi(_valuechar);
  942. CFstatus.ImageAgcGain = clipInt(_agcg_, 30, 0);
  943. }
  944. }
  945. if (httpd_query_key_value(_query, "bpc", _valuechar, 30) == ESP_OK)
  946. {
  947. std::string _bpc = std::string(_valuechar);
  948. CFstatus.ImageBpc = alphanumericToBoolean(_bpc);
  949. }
  950. if (httpd_query_key_value(_query, "wpc", _valuechar, 30) == ESP_OK)
  951. {
  952. std::string _wpc = std::string(_valuechar);
  953. CFstatus.ImageWpc = alphanumericToBoolean(_wpc);
  954. }
  955. if (httpd_query_key_value(_query, "rgma", _valuechar, 30) == ESP_OK)
  956. {
  957. std::string _rgma = std::string(_valuechar);
  958. CFstatus.ImageRawGma = alphanumericToBoolean(_rgma);
  959. }
  960. if (httpd_query_key_value(_query, "lenc", _valuechar, 30) == ESP_OK)
  961. {
  962. std::string _lenc = std::string(_valuechar);
  963. CFstatus.ImageLenc = alphanumericToBoolean(_lenc);
  964. }
  965. if (httpd_query_key_value(_query, "mirror", _valuechar, 30) == ESP_OK)
  966. {
  967. std::string _mirror = std::string(_valuechar);
  968. CFstatus.ImageHmirror = alphanumericToBoolean(_mirror);
  969. }
  970. if (httpd_query_key_value(_query, "flip", _valuechar, 30) == ESP_OK)
  971. {
  972. std::string _flip = std::string(_valuechar);
  973. CFstatus.ImageVflip = alphanumericToBoolean(_flip);
  974. }
  975. if (httpd_query_key_value(_query, "dcw", _valuechar, 30) == ESP_OK)
  976. {
  977. std::string _dcw = std::string(_valuechar);
  978. CFstatus.ImageDcw = alphanumericToBoolean(_dcw);
  979. }
  980. if (httpd_query_key_value(_query, "den", _valuechar, 30) == ESP_OK)
  981. {
  982. std::string _idlv = std::string(_valuechar);
  983. if (isStringNumeric(_idlv))
  984. {
  985. int _ImageDenoiseLevel = std::stoi(_valuechar);
  986. if (CCstatus.CamSensor_id == OV2640_PID)
  987. {
  988. CCstatus.ImageDenoiseLevel = 0;
  989. }
  990. else
  991. {
  992. CFstatus.ImageDenoiseLevel = clipInt(_ImageDenoiseLevel, 8, 0);
  993. }
  994. }
  995. }
  996. if (httpd_query_key_value(_query, "zoom", _valuechar, 30) == ESP_OK)
  997. {
  998. std::string _zoom = std::string(_valuechar);
  999. CFstatus.ImageZoomEnabled = alphanumericToBoolean(_zoom);
  1000. }
  1001. if (httpd_query_key_value(_query, "zoomx", _valuechar, 30) == ESP_OK)
  1002. {
  1003. std::string _zoomx = std::string(_valuechar);
  1004. if (isStringNumeric(_zoomx))
  1005. {
  1006. int _ImageZoomOffsetX = std::stoi(_valuechar);
  1007. if (CCstatus.CamSensor_id == OV2640_PID)
  1008. {
  1009. CFstatus.ImageZoomOffsetX = clipInt(_ImageZoomOffsetX, 480, -480);
  1010. }
  1011. else if (CCstatus.CamSensor_id == OV3660_PID)
  1012. {
  1013. CFstatus.ImageZoomOffsetX = clipInt(_ImageZoomOffsetX, 704, -704);
  1014. }
  1015. else if (CCstatus.CamSensor_id == OV5640_PID)
  1016. {
  1017. CFstatus.ImageZoomOffsetX = clipInt(_ImageZoomOffsetX, 960, -960);
  1018. }
  1019. }
  1020. }
  1021. if (httpd_query_key_value(_query, "zoomy", _valuechar, 30) == ESP_OK)
  1022. {
  1023. std::string _zoomy = std::string(_valuechar);
  1024. if (isStringNumeric(_zoomy))
  1025. {
  1026. int _ImageZoomOffsetY = std::stoi(_valuechar);
  1027. if (CCstatus.CamSensor_id == OV2640_PID)
  1028. {
  1029. CFstatus.ImageZoomOffsetY = clipInt(_ImageZoomOffsetY, 360, -360);
  1030. }
  1031. else if (CCstatus.CamSensor_id == OV3660_PID)
  1032. {
  1033. CFstatus.ImageZoomOffsetY = clipInt(_ImageZoomOffsetY, 528, -528);
  1034. }
  1035. else if (CCstatus.CamSensor_id == OV5640_PID)
  1036. {
  1037. CFstatus.ImageZoomOffsetY = clipInt(_ImageZoomOffsetY, 720, -720);
  1038. }
  1039. }
  1040. }
  1041. if (httpd_query_key_value(_query, "zooms", _valuechar, 30) == ESP_OK)
  1042. {
  1043. std::string _zooms = std::string(_valuechar);
  1044. if (isStringNumeric(_zooms))
  1045. {
  1046. int _ImageZoomSize = std::stoi(_valuechar);
  1047. if (CCstatus.CamSensor_id == OV2640_PID)
  1048. {
  1049. CFstatus.ImageZoomSize = clipInt(_ImageZoomSize, 29, 0);
  1050. }
  1051. else if (CCstatus.CamSensor_id == OV3660_PID)
  1052. {
  1053. CFstatus.ImageZoomSize = clipInt(_ImageZoomSize, 43, 0);
  1054. }
  1055. else if (CCstatus.CamSensor_id == OV5640_PID)
  1056. {
  1057. CFstatus.ImageZoomSize = clipInt(_ImageZoomSize, 59, 0);
  1058. }
  1059. }
  1060. }
  1061. if (httpd_query_key_value(_query, "ledi", _valuechar, 30) == ESP_OK)
  1062. {
  1063. std::string _ledi = std::string(_valuechar);
  1064. if (isStringNumeric(_ledi))
  1065. {
  1066. float _ImageLedIntensity = std::stof(_valuechar);
  1067. Camera.SetLEDIntensity(_ImageLedIntensity);
  1068. CFstatus.ImageLedIntensity = CCstatus.ImageLedIntensity;
  1069. }
  1070. }
  1071. if (_task.compare("cam_settings") == 0)
  1072. {
  1073. // wird aufgerufen, wenn das Referenzbild + Kameraeinstellungen gespeichert wurden
  1074. setCFstatusToCCstatus(); // CFstatus >>> CCstatus
  1075. // Kameraeinstellungen wurden verädert
  1076. CFstatus.changedCameraSettings = true;
  1077. ESP_LOGD(TAG, "Cam Settings set");
  1078. std::string _zw = "CamSettingsSet";
  1079. httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*");
  1080. httpd_resp_send(req, _zw.c_str(), _zw.length());
  1081. }
  1082. else
  1083. {
  1084. // wird aufgerufen, wenn ein neues Referenzbild erstellt oder aktualisiert wurde
  1085. // CFstatus >>> Kamera
  1086. setCFstatusToCam();
  1087. Camera.SetQualityZoomSize(CFstatus.ImageQuality, CFstatus.ImageFrameSize, CFstatus.ImageZoomEnabled, CFstatus.ImageZoomOffsetX, CFstatus.ImageZoomOffsetY, CFstatus.ImageZoomSize, CFstatus.ImageVflip);
  1088. // Camera.SetZoomSize(CFstatus.ImageZoomEnabled, CFstatus.ImageZoomOffsetX, CFstatus.ImageZoomOffsetY, CFstatus.ImageZoomSize, CFstatus.ImageVflip);
  1089. // Kameraeinstellungen wurden verädert
  1090. CFstatus.changedCameraSettings = true;
  1091. ESP_LOGD(TAG, "test_take - vor TakeImage");
  1092. std::string image_temp = flowctrl.doSingleStep("[TakeImage]", _host);
  1093. httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*");
  1094. httpd_resp_send(req, image_temp.c_str(), image_temp.length());
  1095. }
  1096. }
  1097. if (_task.compare("test_align") == 0)
  1098. {
  1099. std::string _host = "";
  1100. if (httpd_query_key_value(_query, "host", _valuechar, 30) == ESP_OK)
  1101. {
  1102. _host = std::string(_valuechar);
  1103. }
  1104. std::string zw = flowctrl.doSingleStep("[Alignment]", _host);
  1105. httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*");
  1106. httpd_resp_send(req, zw.c_str(), zw.length());
  1107. }
  1108. }
  1109. else
  1110. {
  1111. std::string _zw = "DeviceIsBusy";
  1112. httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*");
  1113. httpd_resp_send(req, _zw.c_str(), _zw.length());
  1114. }
  1115. #ifdef DEBUG_DETAIL_ON
  1116. LogFile.WriteHeapInfo("handler_editflow - Done");
  1117. #endif
  1118. return ESP_OK;
  1119. }
  1120. esp_err_t handler_statusflow(httpd_req_t *req)
  1121. {
  1122. #ifdef DEBUG_DETAIL_ON
  1123. LogFile.WriteHeapInfo("handler_statusflow - Start");
  1124. #endif
  1125. const char *resp_str;
  1126. httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*");
  1127. if (bTaskAutoFlowCreated)
  1128. {
  1129. #ifdef DEBUG_DETAIL_ON
  1130. ESP_LOGD(TAG, "handler_statusflow: %s", req->uri);
  1131. #endif
  1132. string *zw = flowctrl.getActStatusWithTime();
  1133. resp_str = zw->c_str();
  1134. httpd_resp_send(req, resp_str, HTTPD_RESP_USE_STRLEN);
  1135. }
  1136. else
  1137. {
  1138. resp_str = "Flow task not yet created";
  1139. httpd_resp_send(req, resp_str, HTTPD_RESP_USE_STRLEN);
  1140. }
  1141. #ifdef DEBUG_DETAIL_ON
  1142. LogFile.WriteHeapInfo("handler_statusflow - Done");
  1143. #endif
  1144. return ESP_OK;
  1145. }
  1146. esp_err_t handler_cputemp(httpd_req_t *req)
  1147. {
  1148. #ifdef DEBUG_DETAIL_ON
  1149. LogFile.WriteHeapInfo("handler_cputemp - Start");
  1150. #endif
  1151. httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*");
  1152. httpd_resp_send(req, std::to_string((int)temperatureRead()).c_str(), HTTPD_RESP_USE_STRLEN);
  1153. #ifdef DEBUG_DETAIL_ON
  1154. LogFile.WriteHeapInfo("handler_cputemp - End");
  1155. #endif
  1156. return ESP_OK;
  1157. }
  1158. esp_err_t handler_rssi(httpd_req_t *req)
  1159. {
  1160. #ifdef DEBUG_DETAIL_ON
  1161. LogFile.WriteHeapInfo("handler_rssi - Start");
  1162. #endif
  1163. if (getWIFIisConnected())
  1164. {
  1165. httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*");
  1166. httpd_resp_send(req, std::to_string(get_WIFI_RSSI()).c_str(), HTTPD_RESP_USE_STRLEN);
  1167. }
  1168. else
  1169. {
  1170. httpd_resp_send_err(req, HTTPD_403_FORBIDDEN, "WIFI not (yet) connected: REST API /rssi not available!");
  1171. return ESP_ERR_NOT_FOUND;
  1172. }
  1173. #ifdef DEBUG_DETAIL_ON
  1174. LogFile.WriteHeapInfo("handler_rssi - End");
  1175. #endif
  1176. return ESP_OK;
  1177. }
  1178. esp_err_t handler_uptime(httpd_req_t *req)
  1179. {
  1180. #ifdef DEBUG_DETAIL_ON
  1181. LogFile.WriteHeapInfo("handler_uptime - Start");
  1182. #endif
  1183. std::string formatedUptime = getFormatedUptime(false);
  1184. httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*");
  1185. httpd_resp_send(req, formatedUptime.c_str(), formatedUptime.length());
  1186. #ifdef DEBUG_DETAIL_ON
  1187. LogFile.WriteHeapInfo("handler_uptime - End");
  1188. #endif
  1189. return ESP_OK;
  1190. }
  1191. esp_err_t handler_prevalue(httpd_req_t *req)
  1192. {
  1193. #ifdef DEBUG_DETAIL_ON
  1194. LogFile.WriteHeapInfo("handler_prevalue - Start");
  1195. ESP_LOGD(TAG, "handler_prevalue: %s", req->uri);
  1196. #endif
  1197. // Default usage message when handler gets called without any parameter
  1198. const std::string RESTUsageInfo =
  1199. "00: Handler usage:<br>"
  1200. "- To retrieve actual PreValue, please provide only a numbersname, e.g. /setPreValue?numbers=main<br>"
  1201. "- To set PreValue to a new value, please provide a numbersname and a value, e.g. /setPreValue?numbers=main&value=1234.5678<br>"
  1202. "NOTE:<br>"
  1203. "value >= 0.0: Set PreValue to provided value<br>"
  1204. "value < 0.0: Set PreValue to actual RAW value (as long RAW value is a valid number, without N)";
  1205. // Default return error message when no return is programmed
  1206. std::string sReturnMessage = "E90: Uninitialized";
  1207. char _query[100];
  1208. char _numbersname[50] = "default";
  1209. char _value[20] = "";
  1210. httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*");
  1211. if (httpd_req_get_url_query_str(req, _query, 100) == ESP_OK)
  1212. {
  1213. #ifdef DEBUG_DETAIL_ON
  1214. ESP_LOGD(TAG, "Query: %s", _query);
  1215. #endif
  1216. if (httpd_query_key_value(_query, "numbers", _numbersname, 50) != ESP_OK)
  1217. {
  1218. // If request is incomplete
  1219. sReturnMessage = "E91: Query parameter incomplete or not valid!<br> "
  1220. "Call /setPreValue to show REST API usage info and/or check documentation";
  1221. httpd_resp_send(req, sReturnMessage.c_str(), sReturnMessage.length());
  1222. return ESP_FAIL;
  1223. }
  1224. if (httpd_query_key_value(_query, "value", _value, 20) == ESP_OK)
  1225. {
  1226. #ifdef DEBUG_DETAIL_ON
  1227. ESP_LOGD(TAG, "Value: %s", _value);
  1228. #endif
  1229. }
  1230. }
  1231. else
  1232. {
  1233. // if no parameter is provided, print handler usage
  1234. httpd_resp_send(req, RESTUsageInfo.c_str(), RESTUsageInfo.length());
  1235. return ESP_OK;
  1236. }
  1237. if (strlen(_value) == 0)
  1238. {
  1239. // If no value is povided --> return actual PreValue
  1240. sReturnMessage = flowctrl.GetPrevalue(std::string(_numbersname));
  1241. if (sReturnMessage.empty())
  1242. {
  1243. sReturnMessage = "E92: Numbers name not found";
  1244. httpd_resp_send(req, sReturnMessage.c_str(), sReturnMessage.length());
  1245. return ESP_FAIL;
  1246. }
  1247. }
  1248. else
  1249. {
  1250. // New value is positive: Set PreValue to provided value and return value
  1251. // New value is negative and actual RAW value is a valid number: Set PreValue to RAW value and return value
  1252. LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "REST API handler_prevalue called: numbersname: " + std::string(_numbersname) + ", value: " + std::string(_value));
  1253. if (!flowctrl.UpdatePrevalue(_value, _numbersname, true))
  1254. {
  1255. sReturnMessage = "E93: Update request rejected. Please check device logs for more details";
  1256. httpd_resp_send(req, sReturnMessage.c_str(), sReturnMessage.length());
  1257. return ESP_FAIL;
  1258. }
  1259. sReturnMessage = flowctrl.GetPrevalue(std::string(_numbersname));
  1260. if (sReturnMessage.empty())
  1261. {
  1262. sReturnMessage = "E94: Numbers name not found";
  1263. httpd_resp_send(req, sReturnMessage.c_str(), sReturnMessage.length());
  1264. return ESP_FAIL;
  1265. }
  1266. }
  1267. httpd_resp_send(req, sReturnMessage.c_str(), sReturnMessage.length());
  1268. #ifdef DEBUG_DETAIL_ON
  1269. LogFile.WriteHeapInfo("handler_prevalue - End");
  1270. #endif
  1271. return ESP_OK;
  1272. }
  1273. void task_autodoFlow(void *pvParameter)
  1274. {
  1275. int64_t fr_start, fr_delta_ms;
  1276. bTaskAutoFlowCreated = true;
  1277. if (!isPlannedReboot && (esp_reset_reason() == ESP_RST_PANIC))
  1278. {
  1279. flowctrl.setActStatus("Initialization (delayed)");
  1280. // #ifdef ENABLE_MQTT
  1281. // MQTTPublish(mqttServer_getMainTopic() + "/" + "status", "Initialization (delayed)", false); // Right now, not possible -> MQTT Service is going to be started later
  1282. // #endif //ENABLE_MQTT
  1283. vTaskDelay(60 * 5000 / portTICK_PERIOD_MS); // Wait 5 minutes to give time to do an OTA update or fetch the log
  1284. }
  1285. ESP_LOGD(TAG, "task_autodoFlow: start");
  1286. doInit();
  1287. flowctrl.setAutoStartInterval(auto_interval);
  1288. autostartIsEnabled = flowctrl.getIsAutoStart();
  1289. if (isSetupModusActive())
  1290. {
  1291. LogFile.WriteToFile(ESP_LOG_INFO, TAG, "We are in Setup Mode -> Not starting Auto Flow!");
  1292. autostartIsEnabled = false;
  1293. // 15.7.0 Setup Wizard cannot take a Reference Picture #2953
  1294. // std::string zw_time = getCurrentTimeString(LOGFILE_TIME_FORMAT);
  1295. // flowctrl.doFlowTakeImageOnly(zw_time);
  1296. }
  1297. if (autostartIsEnabled)
  1298. {
  1299. LogFile.WriteToFile(ESP_LOG_INFO, TAG, "Starting Flow...");
  1300. }
  1301. else
  1302. {
  1303. LogFile.WriteToFile(ESP_LOG_INFO, TAG, "Autostart is not enabled -> Not starting Flow");
  1304. }
  1305. while (autostartIsEnabled)
  1306. {
  1307. LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "----------------------------------------------------------------"); // Clear separation between runs
  1308. time_t roundStartTime = getUpTime();
  1309. std::string _zw = "Round #" + std::to_string(++countRounds) + " started";
  1310. LogFile.WriteToFile(ESP_LOG_INFO, TAG, _zw);
  1311. fr_start = esp_timer_get_time();
  1312. if (flowisrunning)
  1313. {
  1314. #ifdef DEBUG_DETAIL_ON
  1315. ESP_LOGD(TAG, "Autoflow: doFlow is already running!");
  1316. #endif
  1317. }
  1318. else
  1319. {
  1320. #ifdef DEBUG_DETAIL_ON
  1321. ESP_LOGD(TAG, "Autoflow: doFlow is started");
  1322. #endif
  1323. flowisrunning = true;
  1324. doflow();
  1325. #ifdef DEBUG_DETAIL_ON
  1326. ESP_LOGD(TAG, "Remove older log files");
  1327. #endif
  1328. LogFile.RemoveOldLogFile();
  1329. LogFile.RemoveOldDataLog();
  1330. }
  1331. // Round finished -> Logfile
  1332. LogFile.WriteToFile(ESP_LOG_INFO, TAG, "Round #" + std::to_string(countRounds) + " completed (" + std::to_string(getUpTime() - roundStartTime) + " seconds)");
  1333. // CPU Temp -> Logfile
  1334. LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "CPU Temperature: " + std::to_string((int)temperatureRead()) + "°C");
  1335. // WIFI Signal Strength (RSSI) -> Logfile
  1336. LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "WIFI Signal (RSSI): " + std::to_string(get_WIFI_RSSI()) + "dBm");
  1337. // Check if time is synchronized (if NTP is configured)
  1338. if (getUseNtp() && !getTimeIsSet())
  1339. {
  1340. LogFile.WriteToFile(ESP_LOG_WARN, TAG, "Time server is configured, but time is not yet set!");
  1341. StatusLED(TIME_CHECK, 1, false);
  1342. }
  1343. #if (defined WLAN_USE_MESH_ROAMING && defined WLAN_USE_MESH_ROAMING_ACTIVATE_CLIENT_TRIGGERED_QUERIES)
  1344. wifiRoamingQuery();
  1345. #endif
  1346. // Scan channels and check if an AP with better RSSI is available, then disconnect and try to reconnect to AP with better RSSI
  1347. // NOTE: Keep this direct before the following task delay, because scan is done in blocking mode and this takes ca. 1,5 - 2s.
  1348. #ifdef WLAN_USE_ROAMING_BY_SCANNING
  1349. wifiRoamByScanning();
  1350. #endif
  1351. fr_delta_ms = (esp_timer_get_time() - fr_start) / 1000;
  1352. if (auto_interval > fr_delta_ms)
  1353. {
  1354. const TickType_t xDelay = (auto_interval - fr_delta_ms) / portTICK_PERIOD_MS;
  1355. ESP_LOGD(TAG, "Autoflow: sleep for: %ldms", (long)xDelay);
  1356. vTaskDelay(xDelay);
  1357. }
  1358. }
  1359. while (1)
  1360. {
  1361. // Keep flow task running to handle necessary sub tasks like reboot handler, etc..
  1362. vTaskDelay(2000 / portTICK_PERIOD_MS);
  1363. }
  1364. vTaskDelete(NULL); // Delete this task if it exits from the loop above
  1365. xHandletask_autodoFlow = NULL;
  1366. ESP_LOGD(TAG, "task_autodoFlow: end");
  1367. }
  1368. void InitializeFlowTask(void)
  1369. {
  1370. BaseType_t xReturned;
  1371. ESP_LOGD(TAG, "getESPHeapInfo: %s", getESPHeapInfo().c_str());
  1372. uint32_t stackSize = 16 * 1024;
  1373. xReturned = xTaskCreatePinnedToCore(&task_autodoFlow, "task_autodoFlow", stackSize, NULL, tskIDLE_PRIORITY + 2, &xHandletask_autodoFlow, 0);
  1374. if (xReturned != pdPASS)
  1375. {
  1376. LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "Creation task_autodoFlow failed. Requested stack size:" + std::to_string(stackSize));
  1377. LogFile.WriteHeapInfo("Creation task_autodoFlow failed");
  1378. }
  1379. ESP_LOGD(TAG, "getESPHeapInfo: %s", getESPHeapInfo().c_str());
  1380. }
  1381. void register_server_main_flow_task_uri(httpd_handle_t server)
  1382. {
  1383. ESP_LOGI(TAG, "server_main_flow_task - Registering URI handlers");
  1384. httpd_uri_t camuri = {};
  1385. camuri.method = HTTP_GET;
  1386. camuri.uri = "/doinit";
  1387. camuri.handler = handler_init;
  1388. camuri.user_ctx = (void *)"Light On";
  1389. httpd_register_uri_handler(server, &camuri);
  1390. // Legacy API => New: "/setPreValue"
  1391. camuri.uri = "/setPreValue.html";
  1392. camuri.handler = handler_prevalue;
  1393. camuri.user_ctx = (void *)"Prevalue";
  1394. httpd_register_uri_handler(server, &camuri);
  1395. camuri.uri = "/setPreValue";
  1396. camuri.handler = handler_prevalue;
  1397. camuri.user_ctx = (void *)"Prevalue";
  1398. httpd_register_uri_handler(server, &camuri);
  1399. camuri.uri = "/flow_start";
  1400. camuri.handler = handler_flow_start;
  1401. camuri.user_ctx = (void *)"Flow Start";
  1402. httpd_register_uri_handler(server, &camuri);
  1403. camuri.uri = "/statusflow.html";
  1404. camuri.handler = handler_statusflow;
  1405. camuri.user_ctx = (void *)"Light Off";
  1406. httpd_register_uri_handler(server, &camuri);
  1407. camuri.uri = "/statusflow";
  1408. camuri.handler = handler_statusflow;
  1409. camuri.user_ctx = (void *)"Light Off";
  1410. httpd_register_uri_handler(server, &camuri);
  1411. // Legacy API => New: "/cpu_temperature"
  1412. camuri.uri = "/cputemp.html";
  1413. camuri.handler = handler_cputemp;
  1414. camuri.user_ctx = (void *)"Light Off";
  1415. httpd_register_uri_handler(server, &camuri);
  1416. camuri.uri = "/cpu_temperature";
  1417. camuri.handler = handler_cputemp;
  1418. camuri.user_ctx = (void *)"Light Off";
  1419. httpd_register_uri_handler(server, &camuri);
  1420. // Legacy API => New: "/rssi"
  1421. camuri.uri = "/rssi.html";
  1422. camuri.handler = handler_rssi;
  1423. camuri.user_ctx = (void *)"Light Off";
  1424. httpd_register_uri_handler(server, &camuri);
  1425. camuri.uri = "/rssi";
  1426. camuri.handler = handler_rssi;
  1427. camuri.user_ctx = (void *)"Light Off";
  1428. httpd_register_uri_handler(server, &camuri);
  1429. camuri.uri = "/uptime";
  1430. camuri.handler = handler_uptime;
  1431. camuri.user_ctx = (void *)"Light Off";
  1432. httpd_register_uri_handler(server, &camuri);
  1433. camuri.uri = "/editflow";
  1434. camuri.handler = handler_editflow;
  1435. camuri.user_ctx = (void *)"EditFlow";
  1436. httpd_register_uri_handler(server, &camuri);
  1437. // Legacy API => New: "/value"
  1438. camuri.uri = "/value.html";
  1439. camuri.handler = handler_wasserzaehler;
  1440. camuri.user_ctx = (void *)"Value";
  1441. httpd_register_uri_handler(server, &camuri);
  1442. camuri.uri = "/value";
  1443. camuri.handler = handler_wasserzaehler;
  1444. camuri.user_ctx = (void *)"Value";
  1445. httpd_register_uri_handler(server, &camuri);
  1446. // Legacy API => New: "/value"
  1447. camuri.uri = "/wasserzaehler.html";
  1448. camuri.handler = handler_wasserzaehler;
  1449. camuri.user_ctx = (void *)"Wasserzaehler";
  1450. httpd_register_uri_handler(server, &camuri);
  1451. camuri.uri = "/json";
  1452. camuri.handler = handler_json;
  1453. camuri.user_ctx = (void *)"JSON";
  1454. httpd_register_uri_handler(server, &camuri);
  1455. camuri.uri = "/heap";
  1456. camuri.handler = handler_get_heap;
  1457. camuri.user_ctx = (void *)"Heap";
  1458. httpd_register_uri_handler(server, &camuri);
  1459. camuri.uri = "/stream";
  1460. camuri.handler = handler_stream;
  1461. camuri.user_ctx = (void *)"stream";
  1462. httpd_register_uri_handler(server, &camuri);
  1463. /** will handle metrics requests */
  1464. camuri.uri = "/metrics";
  1465. camuri.handler = handler_openmetrics;
  1466. camuri.user_ctx = (void *)"metrics";
  1467. httpd_register_uri_handler(server, &camuri);
  1468. /** when adding a new handler, make sure to increment the value for config.max_uri_handlers in `main/server_main.cpp` */
  1469. }