MainFlowControl.cpp 58 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767
  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 and aligned */
  604. txt = "<hr><h3>Aligned 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. int _aecgc = std::stoi(_valuechar);
  783. switch (_aecgc)
  784. {
  785. case 1: CFstatus.ImageGainceiling = GAINCEILING_4X; break;
  786. case 2: CFstatus.ImageGainceiling = GAINCEILING_8X; break;
  787. case 3: CFstatus.ImageGainceiling = GAINCEILING_16X; break;
  788. case 4: CFstatus.ImageGainceiling = GAINCEILING_32X; break;
  789. case 5: CFstatus.ImageGainceiling = GAINCEILING_64X; break;
  790. case 6: CFstatus.ImageGainceiling = GAINCEILING_128X; break;
  791. default: CFstatus.ImageGainceiling = GAINCEILING_2X;
  792. }
  793. }
  794. if (httpd_query_key_value(_query, "qual", _valuechar, 30) == ESP_OK)
  795. {
  796. std::string _qual = std::string(_valuechar);
  797. if (isStringNumeric(_qual))
  798. {
  799. int _qual_ = std::stoi(_valuechar);
  800. CFstatus.ImageQuality = clipInt(_qual_, 63, 6);
  801. }
  802. }
  803. if (httpd_query_key_value(_query, "bri", _valuechar, 30) == ESP_OK)
  804. {
  805. std::string _bri = std::string(_valuechar);
  806. if (isStringNumeric(_bri))
  807. {
  808. int _bri_ = std::stoi(_valuechar);
  809. CFstatus.ImageBrightness = clipInt(_bri_, 2, -2);
  810. }
  811. }
  812. if (httpd_query_key_value(_query, "con", _valuechar, 30) == ESP_OK)
  813. {
  814. std::string _con = std::string(_valuechar);
  815. if (isStringNumeric(_con))
  816. {
  817. int _con_ = std::stoi(_valuechar);
  818. CFstatus.ImageContrast = clipInt(_con_, 2, -2);
  819. }
  820. }
  821. if (httpd_query_key_value(_query, "sat", _valuechar, 30) == ESP_OK)
  822. {
  823. std::string _sat = std::string(_valuechar);
  824. if (isStringNumeric(_sat))
  825. {
  826. int _sat_ = std::stoi(_valuechar);
  827. CFstatus.ImageSaturation = clipInt(_sat_, 2, -2);
  828. }
  829. }
  830. if (httpd_query_key_value(_query, "shp", _valuechar, 30) == ESP_OK)
  831. {
  832. std::string _shp = std::string(_valuechar);
  833. if (isStringNumeric(_shp))
  834. {
  835. int _shp_ = std::stoi(_valuechar);
  836. if (CCstatus.CamSensor_id == OV2640_PID)
  837. {
  838. CFstatus.ImageSharpness = clipInt(_shp_, 2, -2);
  839. }
  840. else
  841. {
  842. CFstatus.ImageSharpness = clipInt(_shp_, 3, -3);
  843. }
  844. }
  845. }
  846. if (httpd_query_key_value(_query, "ashp", _valuechar, 30) == ESP_OK)
  847. {
  848. std::string _ashp = std::string(_valuechar);
  849. CFstatus.ImageAutoSharpness = alphanumericToBoolean(_ashp);
  850. }
  851. if (httpd_query_key_value(_query, "spe", _valuechar, 30) == ESP_OK)
  852. {
  853. std::string _spe = std::string(_valuechar);
  854. if (isStringNumeric(_spe))
  855. {
  856. int _spe_ = std::stoi(_valuechar);
  857. CFstatus.ImageSpecialEffect = clipInt(_spe_, 6, 0);
  858. }
  859. }
  860. if (httpd_query_key_value(_query, "wbm", _valuechar, 30) == ESP_OK)
  861. {
  862. std::string _wbm = std::string(_valuechar);
  863. if (isStringNumeric(_wbm))
  864. {
  865. int _wbm_ = std::stoi(_valuechar);
  866. CFstatus.ImageWbMode = clipInt(_wbm_, 4, 0);
  867. }
  868. }
  869. if (httpd_query_key_value(_query, "awb", _valuechar, 30) == ESP_OK)
  870. {
  871. std::string _awb = std::string(_valuechar);
  872. CFstatus.ImageAwb = alphanumericToBoolean(_awb);
  873. }
  874. if (httpd_query_key_value(_query, "awbg", _valuechar, 30) == ESP_OK)
  875. {
  876. std::string _awbg = std::string(_valuechar);
  877. CFstatus.ImageAwbGain = alphanumericToBoolean(_awbg);
  878. }
  879. if (httpd_query_key_value(_query, "aec", _valuechar, 30) == ESP_OK)
  880. {
  881. std::string _aec = std::string(_valuechar);
  882. CFstatus.ImageAec = alphanumericToBoolean(_aec);
  883. }
  884. if (httpd_query_key_value(_query, "aec2", _valuechar, 30) == ESP_OK)
  885. {
  886. std::string _aec2 = std::string(_valuechar);
  887. CFstatus.ImageAec2 = alphanumericToBoolean(_aec2);
  888. }
  889. if (httpd_query_key_value(_query, "ael", _valuechar, 30) == ESP_OK)
  890. {
  891. std::string _ael = std::string(_valuechar);
  892. if (isStringNumeric(_ael))
  893. {
  894. int _ael_ = std::stoi(_valuechar);
  895. if (CCstatus.CamSensor_id == OV2640_PID)
  896. {
  897. CFstatus.ImageAeLevel = clipInt(_ael_, 2, -2);
  898. }
  899. else
  900. {
  901. CFstatus.ImageAeLevel = clipInt(_ael_, 5, -5);
  902. }
  903. }
  904. }
  905. if (httpd_query_key_value(_query, "aecv", _valuechar, 30) == ESP_OK)
  906. {
  907. std::string _aecv = std::string(_valuechar);
  908. if (isStringNumeric(_aecv))
  909. {
  910. int _aecv_ = std::stoi(_valuechar);
  911. CFstatus.ImageAecValue = clipInt(_aecv_, 1200, 0);
  912. }
  913. }
  914. if (httpd_query_key_value(_query, "agc", _valuechar, 30) == ESP_OK)
  915. {
  916. std::string _agc = std::string(_valuechar);
  917. CFstatus.ImageAgc = alphanumericToBoolean(_agc);
  918. }
  919. if (httpd_query_key_value(_query, "agcg", _valuechar, 30) == ESP_OK)
  920. {
  921. std::string _agcg = std::string(_valuechar);
  922. if (isStringNumeric(_agcg))
  923. {
  924. int _agcg_ = std::stoi(_valuechar);
  925. CFstatus.ImageAgcGain = clipInt(_agcg_, 30, 0);
  926. }
  927. }
  928. if (httpd_query_key_value(_query, "bpc", _valuechar, 30) == ESP_OK)
  929. {
  930. std::string _bpc = std::string(_valuechar);
  931. CFstatus.ImageBpc = alphanumericToBoolean(_bpc);
  932. }
  933. if (httpd_query_key_value(_query, "wpc", _valuechar, 30) == ESP_OK)
  934. {
  935. std::string _wpc = std::string(_valuechar);
  936. CFstatus.ImageWpc = alphanumericToBoolean(_wpc);
  937. }
  938. if (httpd_query_key_value(_query, "rgma", _valuechar, 30) == ESP_OK)
  939. {
  940. std::string _rgma = std::string(_valuechar);
  941. CFstatus.ImageRawGma = alphanumericToBoolean(_rgma);
  942. }
  943. if (httpd_query_key_value(_query, "lenc", _valuechar, 30) == ESP_OK)
  944. {
  945. std::string _lenc = std::string(_valuechar);
  946. CFstatus.ImageLenc = alphanumericToBoolean(_lenc);
  947. }
  948. if (httpd_query_key_value(_query, "mirror", _valuechar, 30) == ESP_OK)
  949. {
  950. std::string _mirror = std::string(_valuechar);
  951. CFstatus.ImageHmirror = alphanumericToBoolean(_mirror);
  952. }
  953. if (httpd_query_key_value(_query, "flip", _valuechar, 30) == ESP_OK)
  954. {
  955. std::string _flip = std::string(_valuechar);
  956. CFstatus.ImageVflip = alphanumericToBoolean(_flip);
  957. }
  958. if (httpd_query_key_value(_query, "dcw", _valuechar, 30) == ESP_OK)
  959. {
  960. std::string _dcw = std::string(_valuechar);
  961. CFstatus.ImageDcw = alphanumericToBoolean(_dcw);
  962. }
  963. if (httpd_query_key_value(_query, "den", _valuechar, 30) == ESP_OK)
  964. {
  965. std::string _idlv = std::string(_valuechar);
  966. if (isStringNumeric(_idlv))
  967. {
  968. int _ImageDenoiseLevel = std::stoi(_valuechar);
  969. if (CCstatus.CamSensor_id == OV2640_PID)
  970. {
  971. CCstatus.ImageDenoiseLevel = 0;
  972. }
  973. else
  974. {
  975. CFstatus.ImageDenoiseLevel = clipInt(_ImageDenoiseLevel, 8, 0);
  976. }
  977. }
  978. }
  979. if (httpd_query_key_value(_query, "zoom", _valuechar, 30) == ESP_OK)
  980. {
  981. std::string _zoom = std::string(_valuechar);
  982. CFstatus.ImageZoomEnabled = alphanumericToBoolean(_zoom);
  983. }
  984. if (httpd_query_key_value(_query, "zoomx", _valuechar, 30) == ESP_OK)
  985. {
  986. std::string _zoomx = std::string(_valuechar);
  987. if (isStringNumeric(_zoomx))
  988. {
  989. int _ImageZoomOffsetX = std::stoi(_valuechar);
  990. if (CCstatus.CamSensor_id == OV2640_PID)
  991. {
  992. CFstatus.ImageZoomOffsetX = clipInt(_ImageZoomOffsetX, 480, -480);
  993. }
  994. else if (CCstatus.CamSensor_id == OV3660_PID)
  995. {
  996. CFstatus.ImageZoomOffsetX = clipInt(_ImageZoomOffsetX, 704, -704);
  997. }
  998. else if (CCstatus.CamSensor_id == OV5640_PID)
  999. {
  1000. CFstatus.ImageZoomOffsetX = clipInt(_ImageZoomOffsetX, 960, -960);
  1001. }
  1002. }
  1003. }
  1004. if (httpd_query_key_value(_query, "zoomy", _valuechar, 30) == ESP_OK)
  1005. {
  1006. std::string _zoomy = std::string(_valuechar);
  1007. if (isStringNumeric(_zoomy))
  1008. {
  1009. int _ImageZoomOffsetY = std::stoi(_valuechar);
  1010. if (CCstatus.CamSensor_id == OV2640_PID)
  1011. {
  1012. CFstatus.ImageZoomOffsetY = clipInt(_ImageZoomOffsetY, 360, -360);
  1013. }
  1014. else if (CCstatus.CamSensor_id == OV3660_PID)
  1015. {
  1016. CFstatus.ImageZoomOffsetY = clipInt(_ImageZoomOffsetY, 528, -528);
  1017. }
  1018. else if (CCstatus.CamSensor_id == OV5640_PID)
  1019. {
  1020. CFstatus.ImageZoomOffsetY = clipInt(_ImageZoomOffsetY, 720, -720);
  1021. }
  1022. }
  1023. }
  1024. if (httpd_query_key_value(_query, "zooms", _valuechar, 30) == ESP_OK)
  1025. {
  1026. std::string _zooms = std::string(_valuechar);
  1027. if (isStringNumeric(_zooms))
  1028. {
  1029. int _ImageZoomSize = std::stoi(_valuechar);
  1030. if (CCstatus.CamSensor_id == OV2640_PID)
  1031. {
  1032. CFstatus.ImageZoomSize = clipInt(_ImageZoomSize, 29, 0);
  1033. }
  1034. else if (CCstatus.CamSensor_id == OV3660_PID)
  1035. {
  1036. CFstatus.ImageZoomSize = clipInt(_ImageZoomSize, 43, 0);
  1037. }
  1038. else if (CCstatus.CamSensor_id == OV5640_PID)
  1039. {
  1040. CFstatus.ImageZoomSize = clipInt(_ImageZoomSize, 59, 0);
  1041. }
  1042. }
  1043. }
  1044. if (httpd_query_key_value(_query, "ledi", _valuechar, 30) == ESP_OK)
  1045. {
  1046. std::string _ledi = std::string(_valuechar);
  1047. if (isStringNumeric(_ledi))
  1048. {
  1049. float _ImageLedIntensity = std::stof(_valuechar);
  1050. Camera.SetLEDIntensity(_ImageLedIntensity);
  1051. CFstatus.ImageLedIntensity = CCstatus.ImageLedIntensity;
  1052. }
  1053. }
  1054. if (_task.compare("cam_settings") == 0)
  1055. {
  1056. // wird aufgerufen, wenn das Referenzbild + Kameraeinstellungen gespeichert wurden
  1057. setCFstatusToCCstatus(); // CFstatus >>> CCstatus
  1058. // Kameraeinstellungen wurden verädert
  1059. CFstatus.changedCameraSettings = true;
  1060. ESP_LOGD(TAG, "Cam Settings set");
  1061. std::string _zw = "CamSettingsSet";
  1062. httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*");
  1063. httpd_resp_send(req, _zw.c_str(), _zw.length());
  1064. }
  1065. else
  1066. {
  1067. // wird aufgerufen, wenn ein neues Referenzbild erstellt oder aktualisiert wurde
  1068. // CFstatus >>> Kamera
  1069. setCFstatusToCam();
  1070. Camera.SetQualityZoomSize(CFstatus.ImageQuality, CFstatus.ImageFrameSize, CFstatus.ImageZoomEnabled, CFstatus.ImageZoomOffsetX, CFstatus.ImageZoomOffsetY, CFstatus.ImageZoomSize, CFstatus.ImageVflip);
  1071. // Camera.SetZoomSize(CFstatus.ImageZoomEnabled, CFstatus.ImageZoomOffsetX, CFstatus.ImageZoomOffsetY, CFstatus.ImageZoomSize, CFstatus.ImageVflip);
  1072. // Kameraeinstellungen wurden verädert
  1073. CFstatus.changedCameraSettings = true;
  1074. ESP_LOGD(TAG, "test_take - vor TakeImage");
  1075. std::string image_temp = flowctrl.doSingleStep("[TakeImage]", _host);
  1076. httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*");
  1077. httpd_resp_send(req, image_temp.c_str(), image_temp.length());
  1078. }
  1079. }
  1080. if (_task.compare("test_align") == 0)
  1081. {
  1082. std::string _host = "";
  1083. if (httpd_query_key_value(_query, "host", _valuechar, 30) == ESP_OK)
  1084. {
  1085. _host = std::string(_valuechar);
  1086. }
  1087. std::string zw = flowctrl.doSingleStep("[Alignment]", _host);
  1088. httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*");
  1089. httpd_resp_send(req, zw.c_str(), zw.length());
  1090. }
  1091. }
  1092. else
  1093. {
  1094. std::string _zw = "DeviceIsBusy";
  1095. httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*");
  1096. httpd_resp_send(req, _zw.c_str(), _zw.length());
  1097. }
  1098. #ifdef DEBUG_DETAIL_ON
  1099. LogFile.WriteHeapInfo("handler_editflow - Done");
  1100. #endif
  1101. return ESP_OK;
  1102. }
  1103. esp_err_t handler_statusflow(httpd_req_t *req)
  1104. {
  1105. #ifdef DEBUG_DETAIL_ON
  1106. LogFile.WriteHeapInfo("handler_statusflow - Start");
  1107. #endif
  1108. const char *resp_str;
  1109. httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*");
  1110. if (bTaskAutoFlowCreated)
  1111. {
  1112. #ifdef DEBUG_DETAIL_ON
  1113. ESP_LOGD(TAG, "handler_statusflow: %s", req->uri);
  1114. #endif
  1115. string *zw = flowctrl.getActStatusWithTime();
  1116. resp_str = zw->c_str();
  1117. httpd_resp_send(req, resp_str, HTTPD_RESP_USE_STRLEN);
  1118. }
  1119. else
  1120. {
  1121. resp_str = "Flow task not yet created";
  1122. httpd_resp_send(req, resp_str, HTTPD_RESP_USE_STRLEN);
  1123. }
  1124. #ifdef DEBUG_DETAIL_ON
  1125. LogFile.WriteHeapInfo("handler_statusflow - Done");
  1126. #endif
  1127. return ESP_OK;
  1128. }
  1129. esp_err_t handler_cputemp(httpd_req_t *req)
  1130. {
  1131. #ifdef DEBUG_DETAIL_ON
  1132. LogFile.WriteHeapInfo("handler_cputemp - Start");
  1133. #endif
  1134. httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*");
  1135. httpd_resp_send(req, std::to_string((int)temperatureRead()).c_str(), HTTPD_RESP_USE_STRLEN);
  1136. #ifdef DEBUG_DETAIL_ON
  1137. LogFile.WriteHeapInfo("handler_cputemp - End");
  1138. #endif
  1139. return ESP_OK;
  1140. }
  1141. esp_err_t handler_rssi(httpd_req_t *req)
  1142. {
  1143. #ifdef DEBUG_DETAIL_ON
  1144. LogFile.WriteHeapInfo("handler_rssi - Start");
  1145. #endif
  1146. if (getWIFIisConnected())
  1147. {
  1148. httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*");
  1149. httpd_resp_send(req, std::to_string(get_WIFI_RSSI()).c_str(), HTTPD_RESP_USE_STRLEN);
  1150. }
  1151. else
  1152. {
  1153. httpd_resp_send_err(req, HTTPD_403_FORBIDDEN, "WIFI not (yet) connected: REST API /rssi not available!");
  1154. return ESP_ERR_NOT_FOUND;
  1155. }
  1156. #ifdef DEBUG_DETAIL_ON
  1157. LogFile.WriteHeapInfo("handler_rssi - End");
  1158. #endif
  1159. return ESP_OK;
  1160. }
  1161. esp_err_t handler_uptime(httpd_req_t *req)
  1162. {
  1163. #ifdef DEBUG_DETAIL_ON
  1164. LogFile.WriteHeapInfo("handler_uptime - Start");
  1165. #endif
  1166. std::string formatedUptime = getFormatedUptime(false);
  1167. httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*");
  1168. httpd_resp_send(req, formatedUptime.c_str(), formatedUptime.length());
  1169. #ifdef DEBUG_DETAIL_ON
  1170. LogFile.WriteHeapInfo("handler_uptime - End");
  1171. #endif
  1172. return ESP_OK;
  1173. }
  1174. esp_err_t handler_prevalue(httpd_req_t *req)
  1175. {
  1176. #ifdef DEBUG_DETAIL_ON
  1177. LogFile.WriteHeapInfo("handler_prevalue - Start");
  1178. ESP_LOGD(TAG, "handler_prevalue: %s", req->uri);
  1179. #endif
  1180. // Default usage message when handler gets called without any parameter
  1181. const std::string RESTUsageInfo =
  1182. "00: Handler usage:<br>"
  1183. "- To retrieve actual PreValue, please provide only a numbersname, e.g. /setPreValue?numbers=main<br>"
  1184. "- To set PreValue to a new value, please provide a numbersname and a value, e.g. /setPreValue?numbers=main&value=1234.5678<br>"
  1185. "NOTE:<br>"
  1186. "value >= 0.0: Set PreValue to provided value<br>"
  1187. "value < 0.0: Set PreValue to actual RAW value (as long RAW value is a valid number, without N)";
  1188. // Default return error message when no return is programmed
  1189. std::string sReturnMessage = "E90: Uninitialized";
  1190. char _query[100];
  1191. char _numbersname[50] = "default";
  1192. char _value[20] = "";
  1193. httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*");
  1194. if (httpd_req_get_url_query_str(req, _query, 100) == ESP_OK)
  1195. {
  1196. #ifdef DEBUG_DETAIL_ON
  1197. ESP_LOGD(TAG, "Query: %s", _query);
  1198. #endif
  1199. if (httpd_query_key_value(_query, "numbers", _numbersname, 50) != ESP_OK)
  1200. {
  1201. // If request is incomplete
  1202. sReturnMessage = "E91: Query parameter incomplete or not valid!<br> "
  1203. "Call /setPreValue to show REST API usage info and/or check documentation";
  1204. httpd_resp_send(req, sReturnMessage.c_str(), sReturnMessage.length());
  1205. return ESP_FAIL;
  1206. }
  1207. if (httpd_query_key_value(_query, "value", _value, 20) == ESP_OK)
  1208. {
  1209. #ifdef DEBUG_DETAIL_ON
  1210. ESP_LOGD(TAG, "Value: %s", _value);
  1211. #endif
  1212. }
  1213. }
  1214. else
  1215. {
  1216. // if no parameter is provided, print handler usage
  1217. httpd_resp_send(req, RESTUsageInfo.c_str(), RESTUsageInfo.length());
  1218. return ESP_OK;
  1219. }
  1220. if (strlen(_value) == 0)
  1221. {
  1222. // If no value is povided --> return actual PreValue
  1223. sReturnMessage = flowctrl.GetPrevalue(std::string(_numbersname));
  1224. if (sReturnMessage.empty())
  1225. {
  1226. sReturnMessage = "E92: Numbers name not found";
  1227. httpd_resp_send(req, sReturnMessage.c_str(), sReturnMessage.length());
  1228. return ESP_FAIL;
  1229. }
  1230. }
  1231. else
  1232. {
  1233. // New value is positive: Set PreValue to provided value and return value
  1234. // New value is negative and actual RAW value is a valid number: Set PreValue to RAW value and return value
  1235. LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "REST API handler_prevalue called: numbersname: " + std::string(_numbersname) + ", value: " + std::string(_value));
  1236. if (!flowctrl.UpdatePrevalue(_value, _numbersname, true))
  1237. {
  1238. sReturnMessage = "E93: Update request rejected. Please check device logs for more details";
  1239. httpd_resp_send(req, sReturnMessage.c_str(), sReturnMessage.length());
  1240. return ESP_FAIL;
  1241. }
  1242. sReturnMessage = flowctrl.GetPrevalue(std::string(_numbersname));
  1243. if (sReturnMessage.empty())
  1244. {
  1245. sReturnMessage = "E94: Numbers name not found";
  1246. httpd_resp_send(req, sReturnMessage.c_str(), sReturnMessage.length());
  1247. return ESP_FAIL;
  1248. }
  1249. }
  1250. httpd_resp_send(req, sReturnMessage.c_str(), sReturnMessage.length());
  1251. #ifdef DEBUG_DETAIL_ON
  1252. LogFile.WriteHeapInfo("handler_prevalue - End");
  1253. #endif
  1254. return ESP_OK;
  1255. }
  1256. void task_autodoFlow(void *pvParameter)
  1257. {
  1258. int64_t fr_start, fr_delta_ms;
  1259. bTaskAutoFlowCreated = true;
  1260. if (!isPlannedReboot && (esp_reset_reason() == ESP_RST_PANIC))
  1261. {
  1262. flowctrl.setActStatus("Initialization (delayed)");
  1263. // #ifdef ENABLE_MQTT
  1264. // MQTTPublish(mqttServer_getMainTopic() + "/" + "status", "Initialization (delayed)", false); // Right now, not possible -> MQTT Service is going to be started later
  1265. // #endif //ENABLE_MQTT
  1266. vTaskDelay(60 * 5000 / portTICK_PERIOD_MS); // Wait 5 minutes to give time to do an OTA update or fetch the log
  1267. }
  1268. ESP_LOGD(TAG, "task_autodoFlow: start");
  1269. doInit();
  1270. flowctrl.setAutoStartInterval(auto_interval);
  1271. autostartIsEnabled = flowctrl.getIsAutoStart();
  1272. if (isSetupModusActive())
  1273. {
  1274. LogFile.WriteToFile(ESP_LOG_INFO, TAG, "We are in Setup Mode -> Not starting Auto Flow!");
  1275. autostartIsEnabled = false;
  1276. // 15.7.0 Setup Wizard cannot take a Reference Picture #2953
  1277. // std::string zw_time = getCurrentTimeString(LOGFILE_TIME_FORMAT);
  1278. // flowctrl.doFlowTakeImageOnly(zw_time);
  1279. }
  1280. if (autostartIsEnabled)
  1281. {
  1282. LogFile.WriteToFile(ESP_LOG_INFO, TAG, "Starting Flow...");
  1283. }
  1284. else
  1285. {
  1286. LogFile.WriteToFile(ESP_LOG_INFO, TAG, "Autostart is not enabled -> Not starting Flow");
  1287. }
  1288. while (autostartIsEnabled)
  1289. {
  1290. LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "----------------------------------------------------------------"); // Clear separation between runs
  1291. time_t roundStartTime = getUpTime();
  1292. std::string _zw = "Round #" + std::to_string(++countRounds) + " started";
  1293. LogFile.WriteToFile(ESP_LOG_INFO, TAG, _zw);
  1294. fr_start = esp_timer_get_time();
  1295. if (flowisrunning)
  1296. {
  1297. #ifdef DEBUG_DETAIL_ON
  1298. ESP_LOGD(TAG, "Autoflow: doFlow is already running!");
  1299. #endif
  1300. }
  1301. else
  1302. {
  1303. #ifdef DEBUG_DETAIL_ON
  1304. ESP_LOGD(TAG, "Autoflow: doFlow is started");
  1305. #endif
  1306. flowisrunning = true;
  1307. doflow();
  1308. #ifdef DEBUG_DETAIL_ON
  1309. ESP_LOGD(TAG, "Remove older log files");
  1310. #endif
  1311. LogFile.RemoveOldLogFile();
  1312. LogFile.RemoveOldDataLog();
  1313. }
  1314. // Round finished -> Logfile
  1315. LogFile.WriteToFile(ESP_LOG_INFO, TAG, "Round #" + std::to_string(countRounds) + " completed (" + std::to_string(getUpTime() - roundStartTime) + " seconds)");
  1316. // CPU Temp -> Logfile
  1317. LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "CPU Temperature: " + std::to_string((int)temperatureRead()) + "°C");
  1318. // WIFI Signal Strength (RSSI) -> Logfile
  1319. LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "WIFI Signal (RSSI): " + std::to_string(get_WIFI_RSSI()) + "dBm");
  1320. // Check if time is synchronized (if NTP is configured)
  1321. if (getUseNtp() && !getTimeIsSet())
  1322. {
  1323. LogFile.WriteToFile(ESP_LOG_WARN, TAG, "Time server is configured, but time is not yet set!");
  1324. StatusLED(TIME_CHECK, 1, false);
  1325. }
  1326. #if (defined WLAN_USE_MESH_ROAMING && defined WLAN_USE_MESH_ROAMING_ACTIVATE_CLIENT_TRIGGERED_QUERIES)
  1327. wifiRoamingQuery();
  1328. #endif
  1329. // Scan channels and check if an AP with better RSSI is available, then disconnect and try to reconnect to AP with better RSSI
  1330. // NOTE: Keep this direct before the following task delay, because scan is done in blocking mode and this takes ca. 1,5 - 2s.
  1331. #ifdef WLAN_USE_ROAMING_BY_SCANNING
  1332. wifiRoamByScanning();
  1333. #endif
  1334. fr_delta_ms = (esp_timer_get_time() - fr_start) / 1000;
  1335. if (auto_interval > fr_delta_ms)
  1336. {
  1337. const TickType_t xDelay = (auto_interval - fr_delta_ms) / portTICK_PERIOD_MS;
  1338. ESP_LOGD(TAG, "Autoflow: sleep for: %ldms", (long)xDelay);
  1339. vTaskDelay(xDelay);
  1340. }
  1341. }
  1342. while (1)
  1343. {
  1344. // Keep flow task running to handle necessary sub tasks like reboot handler, etc..
  1345. vTaskDelay(2000 / portTICK_PERIOD_MS);
  1346. }
  1347. vTaskDelete(NULL); // Delete this task if it exits from the loop above
  1348. xHandletask_autodoFlow = NULL;
  1349. ESP_LOGD(TAG, "task_autodoFlow: end");
  1350. }
  1351. void InitializeFlowTask(void)
  1352. {
  1353. BaseType_t xReturned;
  1354. ESP_LOGD(TAG, "getESPHeapInfo: %s", getESPHeapInfo().c_str());
  1355. uint32_t stackSize = 16 * 1024;
  1356. xReturned = xTaskCreatePinnedToCore(&task_autodoFlow, "task_autodoFlow", stackSize, NULL, tskIDLE_PRIORITY + 2, &xHandletask_autodoFlow, 0);
  1357. if (xReturned != pdPASS)
  1358. {
  1359. LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "Creation task_autodoFlow failed. Requested stack size:" + std::to_string(stackSize));
  1360. LogFile.WriteHeapInfo("Creation task_autodoFlow failed");
  1361. }
  1362. ESP_LOGD(TAG, "getESPHeapInfo: %s", getESPHeapInfo().c_str());
  1363. }
  1364. void register_server_main_flow_task_uri(httpd_handle_t server)
  1365. {
  1366. ESP_LOGI(TAG, "server_main_flow_task - Registering URI handlers");
  1367. httpd_uri_t camuri = {};
  1368. camuri.method = HTTP_GET;
  1369. camuri.uri = "/doinit";
  1370. camuri.handler = handler_init;
  1371. camuri.user_ctx = (void *)"Light On";
  1372. httpd_register_uri_handler(server, &camuri);
  1373. // Legacy API => New: "/setPreValue"
  1374. camuri.uri = "/setPreValue.html";
  1375. camuri.handler = handler_prevalue;
  1376. camuri.user_ctx = (void *)"Prevalue";
  1377. httpd_register_uri_handler(server, &camuri);
  1378. camuri.uri = "/setPreValue";
  1379. camuri.handler = handler_prevalue;
  1380. camuri.user_ctx = (void *)"Prevalue";
  1381. httpd_register_uri_handler(server, &camuri);
  1382. camuri.uri = "/flow_start";
  1383. camuri.handler = handler_flow_start;
  1384. camuri.user_ctx = (void *)"Flow Start";
  1385. httpd_register_uri_handler(server, &camuri);
  1386. camuri.uri = "/statusflow.html";
  1387. camuri.handler = handler_statusflow;
  1388. camuri.user_ctx = (void *)"Light Off";
  1389. httpd_register_uri_handler(server, &camuri);
  1390. camuri.uri = "/statusflow";
  1391. camuri.handler = handler_statusflow;
  1392. camuri.user_ctx = (void *)"Light Off";
  1393. httpd_register_uri_handler(server, &camuri);
  1394. // Legacy API => New: "/cpu_temperature"
  1395. camuri.uri = "/cputemp.html";
  1396. camuri.handler = handler_cputemp;
  1397. camuri.user_ctx = (void *)"Light Off";
  1398. httpd_register_uri_handler(server, &camuri);
  1399. camuri.uri = "/cpu_temperature";
  1400. camuri.handler = handler_cputemp;
  1401. camuri.user_ctx = (void *)"Light Off";
  1402. httpd_register_uri_handler(server, &camuri);
  1403. // Legacy API => New: "/rssi"
  1404. camuri.uri = "/rssi.html";
  1405. camuri.handler = handler_rssi;
  1406. camuri.user_ctx = (void *)"Light Off";
  1407. httpd_register_uri_handler(server, &camuri);
  1408. camuri.uri = "/rssi";
  1409. camuri.handler = handler_rssi;
  1410. camuri.user_ctx = (void *)"Light Off";
  1411. httpd_register_uri_handler(server, &camuri);
  1412. camuri.uri = "/uptime";
  1413. camuri.handler = handler_uptime;
  1414. camuri.user_ctx = (void *)"Light Off";
  1415. httpd_register_uri_handler(server, &camuri);
  1416. camuri.uri = "/editflow";
  1417. camuri.handler = handler_editflow;
  1418. camuri.user_ctx = (void *)"EditFlow";
  1419. httpd_register_uri_handler(server, &camuri);
  1420. // Legacy API => New: "/value"
  1421. camuri.uri = "/value.html";
  1422. camuri.handler = handler_wasserzaehler;
  1423. camuri.user_ctx = (void *)"Value";
  1424. httpd_register_uri_handler(server, &camuri);
  1425. camuri.uri = "/value";
  1426. camuri.handler = handler_wasserzaehler;
  1427. camuri.user_ctx = (void *)"Value";
  1428. httpd_register_uri_handler(server, &camuri);
  1429. // Legacy API => New: "/value"
  1430. camuri.uri = "/wasserzaehler.html";
  1431. camuri.handler = handler_wasserzaehler;
  1432. camuri.user_ctx = (void *)"Wasserzaehler";
  1433. httpd_register_uri_handler(server, &camuri);
  1434. camuri.uri = "/json";
  1435. camuri.handler = handler_json;
  1436. camuri.user_ctx = (void *)"JSON";
  1437. httpd_register_uri_handler(server, &camuri);
  1438. camuri.uri = "/heap";
  1439. camuri.handler = handler_get_heap;
  1440. camuri.user_ctx = (void *)"Heap";
  1441. httpd_register_uri_handler(server, &camuri);
  1442. camuri.uri = "/stream";
  1443. camuri.handler = handler_stream;
  1444. camuri.user_ctx = (void *)"stream";
  1445. httpd_register_uri_handler(server, &camuri);
  1446. /** will handle metrics requests */
  1447. camuri.uri = "/metrics";
  1448. camuri.handler = handler_openmetrics;
  1449. camuri.user_ctx = (void *)"metrics";
  1450. httpd_register_uri_handler(server, &camuri);
  1451. /** when adding a new handler, make sure to increment the value for config.max_uri_handlers in `main/server_main.cpp` */
  1452. }