MainFlowControl.cpp 38 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222
  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. TaskHandle_t xHandletask_autodoFlow = NULL;
  28. bool bTaskAutoFlowCreated = false;
  29. bool flowisrunning = false;
  30. long auto_interval = 0;
  31. bool autostartIsEnabled = false;
  32. int countRounds = 0;
  33. bool isPlannedReboot = false;
  34. static const char *TAG = "MAINCTRL";
  35. //#define DEBUG_DETAIL_ON
  36. void CheckIsPlannedReboot()
  37. {
  38. FILE *pfile;
  39. if ((pfile = fopen("/sdcard/reboot.txt", "r")) == NULL) {
  40. //LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "Initial boot or not a planned reboot");
  41. isPlannedReboot = false;
  42. }
  43. else {
  44. LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "Planned reboot");
  45. DeleteFile("/sdcard/reboot.txt"); // Prevent Boot Loop!!!
  46. isPlannedReboot = true;
  47. }
  48. }
  49. bool getIsPlannedReboot()
  50. {
  51. return isPlannedReboot;
  52. }
  53. int getCountFlowRounds()
  54. {
  55. return countRounds;
  56. }
  57. esp_err_t GetJPG(std::string _filename, httpd_req_t *req)
  58. {
  59. return flowctrl.GetJPGStream(_filename, req);
  60. }
  61. esp_err_t GetRawJPG(httpd_req_t *req)
  62. {
  63. return flowctrl.SendRawJPG(req);
  64. }
  65. bool isSetupModusActive()
  66. {
  67. return flowctrl.getStatusSetupModus();
  68. }
  69. void DeleteMainFlowTask()
  70. {
  71. #ifdef DEBUG_DETAIL_ON
  72. ESP_LOGD(TAG, "DeleteMainFlowTask: xHandletask_autodoFlow: %ld", (long) xHandletask_autodoFlow);
  73. #endif
  74. if( xHandletask_autodoFlow != NULL )
  75. {
  76. vTaskDelete(xHandletask_autodoFlow);
  77. xHandletask_autodoFlow = NULL;
  78. }
  79. #ifdef DEBUG_DETAIL_ON
  80. ESP_LOGD(TAG, "Killed: xHandletask_autodoFlow");
  81. #endif
  82. }
  83. void doInit(void)
  84. {
  85. #ifdef DEBUG_DETAIL_ON
  86. ESP_LOGD(TAG, "Start flowctrl.InitFlow(config);");
  87. #endif
  88. flowctrl.InitFlow(CONFIG_FILE);
  89. #ifdef DEBUG_DETAIL_ON
  90. ESP_LOGD(TAG, "Finished flowctrl.InitFlow(config);");
  91. #endif
  92. /* GPIO handler has to be initialized before MQTT init to ensure proper topic subscription */
  93. gpio_handler_init();
  94. #ifdef ENABLE_MQTT
  95. flowctrl.StartMQTTService();
  96. #endif //ENABLE_MQTT
  97. }
  98. bool doflow(void)
  99. {
  100. std::string zw_time = getCurrentTimeString(LOGFILE_TIME_FORMAT);
  101. ESP_LOGD(TAG, "doflow - start %s", zw_time.c_str());
  102. flowisrunning = true;
  103. flowctrl.doFlow(zw_time);
  104. flowisrunning = false;
  105. #ifdef DEBUG_DETAIL_ON
  106. ESP_LOGD(TAG, "doflow - end %s", zw_time.c_str());
  107. #endif
  108. return true;
  109. }
  110. esp_err_t handler_get_heap(httpd_req_t *req)
  111. {
  112. #ifdef DEBUG_DETAIL_ON
  113. LogFile.WriteHeapInfo("handler_get_heap - Start");
  114. ESP_LOGD(TAG, "handler_get_heap uri: %s", req->uri);
  115. #endif
  116. std::string zw = "Heap info:<br>" + getESPHeapInfo();
  117. #ifdef TASK_ANALYSIS_ON
  118. char* pcTaskList = (char*) calloc_psram_heap(std::string(TAG) + "->pcTaskList", 1, sizeof(char) * 768, MALLOC_CAP_8BIT | MALLOC_CAP_SPIRAM);
  119. if (pcTaskList) {
  120. vTaskList(pcTaskList);
  121. zw = zw + "<br><br>Task info:<br><pre>Name | State | Prio | Lowest stacksize | Creation order | CPU (-1=NoAffinity)<br>"
  122. + std::string(pcTaskList) + "</pre>";
  123. free_psram_heap(std::string(TAG) + "->pcTaskList", pcTaskList);
  124. }
  125. else {
  126. zw = zw + "<br><br>Task info:<br>ERROR - Allocation of TaskList buffer in PSRAM failed";
  127. }
  128. #endif
  129. httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*");
  130. if (zw.length() > 0)
  131. {
  132. httpd_resp_send(req, zw.c_str(), zw.length());
  133. }
  134. else
  135. {
  136. httpd_resp_send(req, NULL, 0);
  137. }
  138. #ifdef DEBUG_DETAIL_ON
  139. LogFile.WriteHeapInfo("handler_get_heap - Done");
  140. #endif
  141. return ESP_OK;
  142. }
  143. esp_err_t handler_init(httpd_req_t *req)
  144. {
  145. #ifdef DEBUG_DETAIL_ON
  146. LogFile.WriteHeapInfo("handler_init - Start");
  147. ESP_LOGD(TAG, "handler_doinit uri: %s", req->uri);
  148. #endif
  149. httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*");
  150. const char* resp_str = "Init started<br>";
  151. httpd_resp_send(req, resp_str, HTTPD_RESP_USE_STRLEN);
  152. doInit();
  153. resp_str = "Init done<br>";
  154. httpd_resp_send(req, resp_str, HTTPD_RESP_USE_STRLEN);
  155. #ifdef DEBUG_DETAIL_ON
  156. LogFile.WriteHeapInfo("handler_init - Done");
  157. #endif
  158. return ESP_OK;
  159. }
  160. esp_err_t handler_stream(httpd_req_t *req)
  161. {
  162. #ifdef DEBUG_DETAIL_ON
  163. LogFile.WriteHeapInfo("handler_stream - Start");
  164. ESP_LOGD(TAG, "handler_stream uri: %s", req->uri);
  165. #endif
  166. char _query[50];
  167. char _value[10];
  168. bool flashlightOn = false;
  169. if (httpd_req_get_url_query_str(req, _query, 50) == ESP_OK)
  170. {
  171. // ESP_LOGD(TAG, "Query: %s", _query);
  172. if (httpd_query_key_value(_query, "flashlight", _value, 10) == ESP_OK)
  173. {
  174. #ifdef DEBUG_DETAIL_ON
  175. ESP_LOGD(TAG, "flashlight is found%s", _value);
  176. #endif
  177. if (strlen(_value) > 0)
  178. flashlightOn = true;
  179. }
  180. }
  181. Camera.CaptureToStream(req, flashlightOn);
  182. #ifdef DEBUG_DETAIL_ON
  183. LogFile.WriteHeapInfo("handler_stream - Done");
  184. #endif
  185. return ESP_OK;
  186. }
  187. esp_err_t handler_flow_start(httpd_req_t *req) {
  188. #ifdef DEBUG_DETAIL_ON
  189. LogFile.WriteHeapInfo("handler_flow_start - Start");
  190. #endif
  191. ESP_LOGD(TAG, "handler_flow_start uri: %s", req->uri);
  192. httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*");
  193. if (autostartIsEnabled) {
  194. xTaskAbortDelay(xHandletask_autodoFlow); // Delay will be aborted if task is in blocked (waiting) state. If task is already running, no action
  195. LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "Flow start triggered by REST API /flow_start");
  196. const char* resp_str = "The flow is going to be started immediately or is already running";
  197. httpd_resp_send(req, resp_str, HTTPD_RESP_USE_STRLEN);
  198. }
  199. else {
  200. LogFile.WriteToFile(ESP_LOG_WARN, TAG, "Flow start triggered by REST API, but flow is not active!");
  201. const char* resp_str = "WARNING: Flow start triggered by REST API, but flow is not active";
  202. httpd_resp_send(req, resp_str, HTTPD_RESP_USE_STRLEN);
  203. }
  204. #ifdef DEBUG_DETAIL_ON
  205. LogFile.WriteHeapInfo("handler_flow_start - Done");
  206. #endif
  207. return ESP_OK;
  208. }
  209. #ifdef ENABLE_MQTT
  210. esp_err_t MQTTCtrlFlowStart(std::string _topic) {
  211. #ifdef DEBUG_DETAIL_ON
  212. LogFile.WriteHeapInfo("MQTTCtrlFlowStart - Start");
  213. #endif
  214. ESP_LOGD(TAG, "MQTTCtrlFlowStart: topic %s", _topic.c_str());
  215. if (autostartIsEnabled)
  216. {
  217. xTaskAbortDelay(xHandletask_autodoFlow); // Delay will be aborted if task is in blocked (waiting) state. If task is already running, no action
  218. LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "Flow start triggered by MQTT topic " + _topic);
  219. }
  220. else
  221. {
  222. LogFile.WriteToFile(ESP_LOG_WARN, TAG, "Flow start triggered by MQTT topic " + _topic + ", but flow is not active!");
  223. }
  224. #ifdef DEBUG_DETAIL_ON
  225. LogFile.WriteHeapInfo("MQTTCtrlFlowStart - Done");
  226. #endif
  227. return ESP_OK;
  228. }
  229. #endif //ENABLE_MQTT
  230. esp_err_t handler_json(httpd_req_t *req)
  231. {
  232. #ifdef DEBUG_DETAIL_ON
  233. LogFile.WriteHeapInfo("handler_json - Start");
  234. #endif
  235. ESP_LOGD(TAG, "handler_JSON uri: %s", req->uri);
  236. if (bTaskAutoFlowCreated)
  237. {
  238. httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*");
  239. httpd_resp_set_type(req, "application/json");
  240. std::string zw = flowctrl.getJSON();
  241. if (zw.length() > 0)
  242. {
  243. httpd_resp_send(req, zw.c_str(), zw.length());
  244. }
  245. else
  246. {
  247. httpd_resp_send(req, NULL, 0);
  248. }
  249. }
  250. else
  251. {
  252. httpd_resp_send_err(req, HTTPD_403_FORBIDDEN, "Flow not (yet) started: REST API /json not yet available!");
  253. return ESP_ERR_NOT_FOUND;
  254. }
  255. #ifdef DEBUG_DETAIL_ON
  256. LogFile.WriteHeapInfo("handler_JSON - Done");
  257. #endif
  258. return ESP_OK;
  259. }
  260. esp_err_t handler_wasserzaehler(httpd_req_t *req)
  261. {
  262. #ifdef DEBUG_DETAIL_ON
  263. LogFile.WriteHeapInfo("handler water counter - Start");
  264. #endif
  265. if (bTaskAutoFlowCreated)
  266. {
  267. bool _rawValue = false;
  268. bool _noerror = false;
  269. bool _all = false;
  270. std::string _type = "value";
  271. string zw;
  272. ESP_LOGD(TAG, "handler water counter uri: %s", req->uri);
  273. char _query[100];
  274. char _size[10];
  275. if (httpd_req_get_url_query_str(req, _query, 100) == ESP_OK)
  276. {
  277. // ESP_LOGD(TAG, "Query: %s", _query);
  278. if (httpd_query_key_value(_query, "all", _size, 10) == ESP_OK)
  279. {
  280. #ifdef DEBUG_DETAIL_ON
  281. ESP_LOGD(TAG, "all is found%s", _size);
  282. #endif
  283. _all = true;
  284. }
  285. if (httpd_query_key_value(_query, "type", _size, 10) == ESP_OK)
  286. {
  287. #ifdef DEBUG_DETAIL_ON
  288. ESP_LOGD(TAG, "all is found: %s", _size);
  289. #endif
  290. _type = std::string(_size);
  291. }
  292. if (httpd_query_key_value(_query, "rawvalue", _size, 10) == ESP_OK)
  293. {
  294. #ifdef DEBUG_DETAIL_ON
  295. ESP_LOGD(TAG, "rawvalue is found: %s", _size);
  296. #endif
  297. _rawValue = true;
  298. }
  299. if (httpd_query_key_value(_query, "noerror", _size, 10) == ESP_OK)
  300. {
  301. #ifdef DEBUG_DETAIL_ON
  302. ESP_LOGD(TAG, "noerror is found: %s", _size);
  303. #endif
  304. _noerror = true;
  305. }
  306. }
  307. httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*");
  308. if (_all)
  309. {
  310. httpd_resp_set_type(req, "text/plain");
  311. ESP_LOGD(TAG, "TYPE: %s", _type.c_str());
  312. int _intype = READOUT_TYPE_VALUE;
  313. if (_type == "prevalue")
  314. _intype = READOUT_TYPE_PREVALUE;
  315. if (_type == "raw")
  316. _intype = READOUT_TYPE_RAWVALUE;
  317. if (_type == "error")
  318. _intype = READOUT_TYPE_ERROR;
  319. zw = flowctrl.getReadoutAll(_intype);
  320. ESP_LOGD(TAG, "ZW: %s", zw.c_str());
  321. if (zw.length() > 0)
  322. httpd_resp_send(req, zw.c_str(), zw.length());
  323. return ESP_OK;
  324. }
  325. std::string *status = flowctrl.getActStatus();
  326. string query = std::string(_query);
  327. // ESP_LOGD(TAG, "Query: %s, query.c_str());
  328. if (query.find("full") != std::string::npos)
  329. {
  330. string txt;
  331. txt = "<body style=\"font-family: arial\">";
  332. if ((countRounds <= 1) && (*status != std::string("Flow finished"))) { // First round not completed yet
  333. txt += "<h3>Please wait for the first round to complete!</h3><h3>Current state: " + *status + "</h3>\n";
  334. }
  335. else {
  336. txt += "<h3>Value</h3>";
  337. }
  338. httpd_resp_sendstr_chunk(req, txt.c_str());
  339. }
  340. zw = flowctrl.getReadout(_rawValue, _noerror, 0);
  341. if (zw.length() > 0)
  342. httpd_resp_sendstr_chunk(req, zw.c_str());
  343. if (query.find("full") != std::string::npos)
  344. {
  345. string txt, zw;
  346. if ((countRounds <= 1) && (*status != std::string("Flow finished"))) { // First round not completed yet
  347. // Nothing to do
  348. }
  349. else {
  350. /* Digital ROIs */
  351. txt = "<body style=\"font-family: arial\">";
  352. txt += "<hr><h3>Recognized Digit ROIs (previous round)</h3>\n";
  353. txt += "<table style=\"border-spacing: 5px\"><tr style=\"text-align: center; vertical-align: top;\">\n";
  354. std::vector<HTMLInfo*> htmlinfodig;
  355. htmlinfodig = flowctrl.GetAllDigital();
  356. for (int i = 0; i < htmlinfodig.size(); ++i)
  357. {
  358. if (flowctrl.GetTypeDigital() == Digital)
  359. {
  360. if (htmlinfodig[i]->val == 10)
  361. zw = "NaN";
  362. else
  363. zw = to_string((int) htmlinfodig[i]->val);
  364. txt += "<td style=\"width: 100px\"><h4>" + zw + "</h4><p><img src=\"/img_tmp/" + htmlinfodig[i]->filename + "\"></p></td>\n";
  365. }
  366. else
  367. {
  368. std::stringstream stream;
  369. stream << std::fixed << std::setprecision(1) << htmlinfodig[i]->val;
  370. zw = stream.str();
  371. txt += "<td style=\"width: 100px\"><h4>" + zw + "</h4><p><img src=\"/img_tmp/" + htmlinfodig[i]->filename + "\"></p></td>\n";
  372. }
  373. delete htmlinfodig[i];
  374. }
  375. htmlinfodig.clear();
  376. txt += "</tr></table>\n";
  377. httpd_resp_sendstr_chunk(req, txt.c_str());
  378. /* Analog ROIs */
  379. txt = "<hr><h3>Recognized Analog ROIs (previous round)</h3>\n";
  380. txt += "<table style=\"border-spacing: 5px\"><tr style=\"text-align: center; vertical-align: top;\">\n";
  381. std::vector<HTMLInfo*> htmlinfoana;
  382. htmlinfoana = flowctrl.GetAllAnalog();
  383. for (int i = 0; i < htmlinfoana.size(); ++i)
  384. {
  385. std::stringstream stream;
  386. stream << std::fixed << std::setprecision(1) << htmlinfoana[i]->val;
  387. zw = stream.str();
  388. txt += "<td style=\"width: 150px;\"><h4>" + zw + "</h4><p><img src=\"/img_tmp/" + htmlinfoana[i]->filename + "\"></p></td>\n";
  389. delete htmlinfoana[i];
  390. }
  391. htmlinfoana.clear();
  392. txt += "</tr>\n</table>\n";
  393. httpd_resp_sendstr_chunk(req, txt.c_str());
  394. /* Full Image
  395. * Only show it after the image got taken and aligned */
  396. txt = "<hr><h3>Aligned Image (current round)</h3>\n";
  397. if ((*status == std::string("Initialization")) ||
  398. (*status == std::string("Initialization (delayed)")) ||
  399. (*status == std::string("Take Image"))) {
  400. txt += "<p>Current state: " + *status + "</p>\n";
  401. }
  402. else {
  403. txt += "<img src=\"/img_tmp/alg_roi.jpg\">\n";
  404. }
  405. httpd_resp_sendstr_chunk(req, txt.c_str());
  406. }
  407. }
  408. /* Respond with an empty chunk to signal HTTP response completion */
  409. httpd_resp_sendstr_chunk(req, NULL);
  410. }
  411. else
  412. {
  413. httpd_resp_send_err(req, HTTPD_403_FORBIDDEN, "Flow not (yet) started: REST API /value not available!");
  414. return ESP_ERR_NOT_FOUND;
  415. }
  416. #ifdef DEBUG_DETAIL_ON
  417. LogFile.WriteHeapInfo("handler_wasserzaehler - Done");
  418. #endif
  419. return ESP_OK;
  420. }
  421. esp_err_t handler_editflow(httpd_req_t *req)
  422. {
  423. #ifdef DEBUG_DETAIL_ON
  424. LogFile.WriteHeapInfo("handler_editflow - Start");
  425. #endif
  426. ESP_LOGD(TAG, "handler_editflow uri: %s", req->uri);
  427. char _query[200];
  428. char _valuechar[30];
  429. string _task;
  430. if (httpd_req_get_url_query_str(req, _query, 200) == ESP_OK)
  431. {
  432. if (httpd_query_key_value(_query, "task", _valuechar, 30) == ESP_OK)
  433. {
  434. #ifdef DEBUG_DETAIL_ON
  435. ESP_LOGD(TAG, "task is found: %s", _valuechar);
  436. #endif
  437. _task = string(_valuechar);
  438. }
  439. }
  440. if (_task.compare("namenumbers") == 0)
  441. {
  442. ESP_LOGD(TAG, "Get NUMBER list");
  443. return get_numbers_file_handler(req);
  444. }
  445. if (_task.compare("data") == 0)
  446. {
  447. ESP_LOGD(TAG, "Get data list");
  448. return get_data_file_handler(req);
  449. }
  450. if (_task.compare("tflite") == 0)
  451. {
  452. ESP_LOGD(TAG, "Get tflite list");
  453. return get_tflite_file_handler(req);
  454. }
  455. if (_task.compare("copy") == 0)
  456. {
  457. string in, out, zw;
  458. httpd_query_key_value(_query, "in", _valuechar, 30);
  459. in = string(_valuechar);
  460. httpd_query_key_value(_query, "out", _valuechar, 30);
  461. out = string(_valuechar);
  462. #ifdef DEBUG_DETAIL_ON
  463. ESP_LOGD(TAG, "in: %s", in.c_str());
  464. ESP_LOGD(TAG, "out: %s", out.c_str());
  465. #endif
  466. in = "/sdcard" + in;
  467. out = "/sdcard" + out;
  468. CopyFile(in, out);
  469. zw = "Copy Done";
  470. httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*");
  471. httpd_resp_send(req, zw.c_str(), zw.length());
  472. }
  473. if (_task.compare("cutref") == 0)
  474. {
  475. string in, out, zw;
  476. int x, y, dx, dy;
  477. bool enhance = false;
  478. httpd_query_key_value(_query, "in", _valuechar, 30);
  479. in = string(_valuechar);
  480. httpd_query_key_value(_query, "out", _valuechar, 30);
  481. out = string(_valuechar);
  482. httpd_query_key_value(_query, "x", _valuechar, 30);
  483. zw = string(_valuechar);
  484. x = stoi(zw);
  485. httpd_query_key_value(_query, "y", _valuechar, 30);
  486. zw = string(_valuechar);
  487. y = stoi(zw);
  488. httpd_query_key_value(_query, "dx", _valuechar, 30);
  489. zw = string(_valuechar);
  490. dx = stoi(zw);
  491. httpd_query_key_value(_query, "dy", _valuechar, 30);
  492. zw = string(_valuechar);
  493. dy = stoi(zw);
  494. #ifdef DEBUG_DETAIL_ON
  495. ESP_LOGD(TAG, "in: %s", in.c_str());
  496. ESP_LOGD(TAG, "out: %s", out.c_str());
  497. ESP_LOGD(TAG, "x: %s", zw.c_str());
  498. ESP_LOGD(TAG, "y: %s", zw.c_str());
  499. ESP_LOGD(TAG, "dx: %s", zw.c_str());
  500. ESP_LOGD(TAG, "dy: %s", zw.c_str());
  501. #endif
  502. if (httpd_query_key_value(_query, "enhance", _valuechar, 10) == ESP_OK)
  503. {
  504. zw = string(_valuechar);
  505. if (zw.compare("true") == 0)
  506. {
  507. enhance = true;
  508. }
  509. }
  510. in = "/sdcard" + in;
  511. out = "/sdcard" + out;
  512. string out2 = out.substr(0, out.length() - 4) + "_org.jpg";
  513. if ((flowctrl.SetupModeActive || (*flowctrl.getActStatus() == "Flow finished")) && psram_init_shared_memory_for_take_image_step()) {
  514. LogFile.WriteToFile(ESP_LOG_INFO, TAG, "Taking image for Alignment Mark Update...");
  515. CAlignAndCutImage *caic = new CAlignAndCutImage("cutref", in);
  516. caic->CutAndSave(out2, x, y, dx, dy);
  517. delete caic;
  518. CImageBasis *cim = new CImageBasis("cutref", out2);
  519. if (enhance)
  520. {
  521. cim->Contrast(90);
  522. }
  523. cim->SaveToFile(out);
  524. delete cim;
  525. psram_deinit_shared_memory_for_take_image_step();
  526. zw = "CutImage Done";
  527. }
  528. else {
  529. LogFile.WriteToFile(ESP_LOG_WARN, TAG, std::string("Taking image for Alignment Mark not possible while device") +
  530. " is busy with a round (Current State: '" + *flowctrl.getActStatus() + "')!");
  531. zw = "Device Busy";
  532. }
  533. httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*");
  534. httpd_resp_send(req, zw.c_str(), zw.length());
  535. }
  536. if (_task.compare("test_take") == 0)
  537. {
  538. std::string _host = "";
  539. int bri = -100;
  540. int sat = -100;
  541. int con = -100;
  542. int intens = -100;
  543. int aelevel = 0;
  544. int zoommode = 0;
  545. int zoomoffsetx = 0;
  546. int zoomoffsety = 0;
  547. bool zoom = false;
  548. bool negative = false;
  549. bool aec2 = false;
  550. #ifdef GRAYSCALE_AS_DEFAULT
  551. bool grayscale = true;
  552. #else
  553. bool grayscale = false;
  554. #endif
  555. if (httpd_query_key_value(_query, "host", _valuechar, 30) == ESP_OK) {
  556. _host = std::string(_valuechar);
  557. }
  558. if (httpd_query_key_value(_query, "int", _valuechar, 30) == ESP_OK) {
  559. std::string _int = std::string(_valuechar);
  560. intens = stoi(_int);
  561. }
  562. if (httpd_query_key_value(_query, "bri", _valuechar, 30) == ESP_OK) {
  563. std::string _bri = std::string(_valuechar);
  564. bri = stoi(_bri);
  565. }
  566. if (httpd_query_key_value(_query, "con", _valuechar, 30) == ESP_OK) {
  567. std::string _con = std::string(_valuechar);
  568. con = stoi(_con);
  569. }
  570. if (httpd_query_key_value(_query, "sat", _valuechar, 30) == ESP_OK) {
  571. std::string _sat = std::string(_valuechar);
  572. sat = stoi(_sat);
  573. }
  574. if (httpd_query_key_value(_query, "ae", _valuechar, 30) == ESP_OK) {
  575. std::string _ae = std::string(_valuechar);
  576. aelevel = stoi(_ae);
  577. }
  578. if (httpd_query_key_value(_query, "gs", _valuechar, 30) == ESP_OK) {
  579. std::string _gr = std::string(_valuechar);
  580. if (stoi(_gr) != 0)
  581. grayscale = true;
  582. else
  583. grayscale = false;
  584. }
  585. if (httpd_query_key_value(_query, "ne", _valuechar, 30) == ESP_OK) {
  586. std::string _ne = std::string(_valuechar);
  587. if (stoi(_ne) != 0)
  588. negative = true;
  589. else
  590. negative = false;
  591. }
  592. if (httpd_query_key_value(_query, "a2", _valuechar, 30) == ESP_OK) {
  593. std::string _a2 = std::string(_valuechar);
  594. if (stoi(_a2) != 0)
  595. aec2 = true;
  596. else
  597. aec2 = false;
  598. }
  599. if (httpd_query_key_value(_query, "z", _valuechar, 30) == ESP_OK) {
  600. std::string _zoom = std::string(_valuechar);
  601. if (stoi(_zoom) != 0)
  602. zoom = true;
  603. else
  604. zoom = false;
  605. }
  606. if (httpd_query_key_value(_query, "zm", _valuechar, 30) == ESP_OK) {
  607. std::string _zm = std::string(_valuechar);
  608. zoommode = stoi(_zm);
  609. }
  610. if (httpd_query_key_value(_query, "x", _valuechar, 30) == ESP_OK) {
  611. std::string _x = std::string(_valuechar);
  612. zoomoffsetx = stoi(_x);
  613. }
  614. if (httpd_query_key_value(_query, "y", _valuechar, 30) == ESP_OK) {
  615. std::string _y = std::string(_valuechar);
  616. zoomoffsety = stoi(_y);
  617. }
  618. // ESP_LOGD(TAG, "Parameter host: %s", _host.c_str());
  619. // string zwzw = "Do " + _task + " start\n"; ESP_LOGD(TAG, zwzw.c_str());
  620. Camera.SetZoom(zoom, zoommode, zoomoffsetx, zoomoffsety);
  621. Camera.SetBrightnessContrastSaturation(bri, con, sat, aelevel, grayscale, negative, aec2);
  622. Camera.SetLEDIntensity(intens);
  623. ESP_LOGD(TAG, "test_take - vor TakeImage");
  624. std::string zw = flowctrl.doSingleStep("[TakeImage]", _host);
  625. httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*");
  626. httpd_resp_send(req, zw.c_str(), zw.length());
  627. }
  628. if (_task.compare("test_align") == 0)
  629. {
  630. std::string _host = "";
  631. if (httpd_query_key_value(_query, "host", _valuechar, 30) == ESP_OK) {
  632. _host = std::string(_valuechar);
  633. }
  634. // ESP_LOGD(TAG, "Parameter host: %s", _host.c_str());
  635. // string zwzw = "Do " + _task + " start\n"; ESP_LOGD(TAG, zwzw.c_str());
  636. std::string zw = flowctrl.doSingleStep("[Alignment]", _host);
  637. httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*");
  638. httpd_resp_send(req, zw.c_str(), zw.length());
  639. }
  640. #ifdef DEBUG_DETAIL_ON
  641. LogFile.WriteHeapInfo("handler_editflow - Done");
  642. #endif
  643. return ESP_OK;
  644. }
  645. esp_err_t handler_statusflow(httpd_req_t *req)
  646. {
  647. #ifdef DEBUG_DETAIL_ON
  648. LogFile.WriteHeapInfo("handler_statusflow - Start");
  649. #endif
  650. const char* resp_str;
  651. httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*");
  652. if (bTaskAutoFlowCreated)
  653. {
  654. #ifdef DEBUG_DETAIL_ON
  655. ESP_LOGD(TAG, "handler_statusflow: %s", req->uri);
  656. #endif
  657. string* zw = flowctrl.getActStatusWithTime();
  658. resp_str = zw->c_str();
  659. httpd_resp_send(req, resp_str, HTTPD_RESP_USE_STRLEN);
  660. }
  661. else
  662. {
  663. resp_str = "Flow task not yet created";
  664. httpd_resp_send(req, resp_str, HTTPD_RESP_USE_STRLEN);
  665. }
  666. #ifdef DEBUG_DETAIL_ON
  667. LogFile.WriteHeapInfo("handler_statusflow - Done");
  668. #endif
  669. return ESP_OK;
  670. }
  671. esp_err_t handler_cputemp(httpd_req_t *req)
  672. {
  673. #ifdef DEBUG_DETAIL_ON
  674. LogFile.WriteHeapInfo("handler_cputemp - Start");
  675. #endif
  676. httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*");
  677. httpd_resp_send(req, std::to_string((int)temperatureRead()).c_str(), HTTPD_RESP_USE_STRLEN);
  678. #ifdef DEBUG_DETAIL_ON
  679. LogFile.WriteHeapInfo("handler_cputemp - End");
  680. #endif
  681. return ESP_OK;
  682. }
  683. esp_err_t handler_rssi(httpd_req_t *req)
  684. {
  685. #ifdef DEBUG_DETAIL_ON
  686. LogFile.WriteHeapInfo("handler_rssi - Start");
  687. #endif
  688. if (getWIFIisConnected())
  689. {
  690. httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*");
  691. httpd_resp_send(req, std::to_string(get_WIFI_RSSI()).c_str(), HTTPD_RESP_USE_STRLEN);
  692. }
  693. else
  694. {
  695. httpd_resp_send_err(req, HTTPD_403_FORBIDDEN, "WIFI not (yet) connected: REST API /rssi not available!");
  696. return ESP_ERR_NOT_FOUND;
  697. }
  698. #ifdef DEBUG_DETAIL_ON
  699. LogFile.WriteHeapInfo("handler_rssi - End");
  700. #endif
  701. return ESP_OK;
  702. }
  703. esp_err_t handler_uptime(httpd_req_t *req)
  704. {
  705. #ifdef DEBUG_DETAIL_ON
  706. LogFile.WriteHeapInfo("handler_uptime - Start");
  707. #endif
  708. std::string formatedUptime = getFormatedUptime(false);
  709. httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*");
  710. httpd_resp_send(req, formatedUptime.c_str(), formatedUptime.length());
  711. #ifdef DEBUG_DETAIL_ON
  712. LogFile.WriteHeapInfo("handler_uptime - End");
  713. #endif
  714. return ESP_OK;
  715. }
  716. esp_err_t handler_prevalue(httpd_req_t *req)
  717. {
  718. #ifdef DEBUG_DETAIL_ON
  719. LogFile.WriteHeapInfo("handler_prevalue - Start");
  720. ESP_LOGD(TAG, "handler_prevalue: %s", req->uri);
  721. #endif
  722. // Default usage message when handler gets called without any parameter
  723. const std::string RESTUsageInfo =
  724. "00: Handler usage:<br>"
  725. "- To retrieve actual PreValue, please provide only a numbersname, e.g. /setPreValue?numbers=main<br>"
  726. "- To set PreValue to a new value, please provide a numbersname and a value, e.g. /setPreValue?numbers=main&value=1234.5678<br>"
  727. "NOTE:<br>"
  728. "value >= 0.0: Set PreValue to provided value<br>"
  729. "value < 0.0: Set PreValue to actual RAW value (as long RAW value is a valid number, without N)";
  730. // Default return error message when no return is programmed
  731. std::string sReturnMessage = "E90: Uninitialized";
  732. char _query[100];
  733. char _numbersname[50] = "default";
  734. char _value[20] = "";
  735. httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*");
  736. if (httpd_req_get_url_query_str(req, _query, 100) == ESP_OK) {
  737. #ifdef DEBUG_DETAIL_ON
  738. ESP_LOGD(TAG, "Query: %s", _query);
  739. #endif
  740. if (httpd_query_key_value(_query, "numbers", _numbersname, 50) != ESP_OK) { // If request is incomplete
  741. sReturnMessage = "E91: Query parameter incomplete or not valid!<br> "
  742. "Call /setPreValue to show REST API usage info and/or check documentation";
  743. httpd_resp_send(req, sReturnMessage.c_str(), sReturnMessage.length());
  744. return ESP_FAIL;
  745. }
  746. if (httpd_query_key_value(_query, "value", _value, 20) == ESP_OK) {
  747. #ifdef DEBUG_DETAIL_ON
  748. ESP_LOGD(TAG, "Value: %s", _value);
  749. #endif
  750. }
  751. }
  752. else { // if no parameter is provided, print handler usage
  753. httpd_resp_send(req, RESTUsageInfo.c_str(), RESTUsageInfo.length());
  754. return ESP_OK;
  755. }
  756. if (strlen(_value) == 0) { // If no value is povided --> return actual PreValue
  757. sReturnMessage = flowctrl.GetPrevalue(std::string(_numbersname));
  758. if (sReturnMessage.empty()) {
  759. sReturnMessage = "E92: Numbers name not found";
  760. httpd_resp_send(req, sReturnMessage.c_str(), sReturnMessage.length());
  761. return ESP_FAIL;
  762. }
  763. }
  764. else {
  765. // New value is positive: Set PreValue to provided value and return value
  766. // New value is negative and actual RAW value is a valid number: Set PreValue to RAW value and return value
  767. LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "REST API handler_prevalue called: numbersname: " + std::string(_numbersname) +
  768. ", value: " + std::string(_value));
  769. if (!flowctrl.UpdatePrevalue(_value, _numbersname, true)) {
  770. sReturnMessage = "E93: Update request rejected. Please check device logs for more details";
  771. httpd_resp_send(req, sReturnMessage.c_str(), sReturnMessage.length());
  772. return ESP_FAIL;
  773. }
  774. sReturnMessage = flowctrl.GetPrevalue(std::string(_numbersname));
  775. if (sReturnMessage.empty()) {
  776. sReturnMessage = "E94: Numbers name not found";
  777. httpd_resp_send(req, sReturnMessage.c_str(), sReturnMessage.length());
  778. return ESP_FAIL;
  779. }
  780. }
  781. httpd_resp_send(req, sReturnMessage.c_str(), sReturnMessage.length());
  782. #ifdef DEBUG_DETAIL_ON
  783. LogFile.WriteHeapInfo("handler_prevalue - End");
  784. #endif
  785. return ESP_OK;
  786. }
  787. void task_autodoFlow(void *pvParameter)
  788. {
  789. int64_t fr_start, fr_delta_ms;
  790. bTaskAutoFlowCreated = true;
  791. if (!isPlannedReboot && (esp_reset_reason() == ESP_RST_PANIC))
  792. {
  793. flowctrl.setActStatus("Initialization (delayed)");
  794. //#ifdef ENABLE_MQTT
  795. //MQTTPublish(mqttServer_getMainTopic() + "/" + "status", "Initialization (delayed)", false); // Right now, not possible -> MQTT Service is going to be started later
  796. //#endif //ENABLE_MQTT
  797. vTaskDelay(60*5000 / portTICK_PERIOD_MS); // Wait 5 minutes to give time to do an OTA update or fetch the log
  798. }
  799. ESP_LOGD(TAG, "task_autodoFlow: start");
  800. doInit();
  801. flowctrl.setAutoStartInterval(auto_interval);
  802. autostartIsEnabled = flowctrl.getIsAutoStart();
  803. if (isSetupModusActive())
  804. {
  805. LogFile.WriteToFile(ESP_LOG_INFO, TAG, "We are in Setup Mode -> Not starting Auto Flow!");
  806. autostartIsEnabled = false;
  807. std::string zw_time = getCurrentTimeString(LOGFILE_TIME_FORMAT);
  808. flowctrl.doFlowTakeImageOnly(zw_time);
  809. }
  810. if (autostartIsEnabled) {
  811. LogFile.WriteToFile(ESP_LOG_INFO, TAG, "Starting Flow...");
  812. }
  813. else {
  814. LogFile.WriteToFile(ESP_LOG_INFO, TAG, "Autostart is not enabled -> Not starting Flow");
  815. }
  816. while (autostartIsEnabled)
  817. {
  818. LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "----------------------------------------------------------------"); // Clear separation between runs
  819. std::string _zw = "Round #" + std::to_string(++countRounds) + " started";
  820. time_t roundStartTime = getUpTime();
  821. LogFile.WriteToFile(ESP_LOG_INFO, TAG, _zw);
  822. fr_start = esp_timer_get_time();
  823. if (flowisrunning)
  824. {
  825. #ifdef DEBUG_DETAIL_ON
  826. ESP_LOGD(TAG, "Autoflow: doFlow is already running!");
  827. #endif
  828. }
  829. else
  830. {
  831. #ifdef DEBUG_DETAIL_ON
  832. ESP_LOGD(TAG, "Autoflow: doFlow is started");
  833. #endif
  834. flowisrunning = true;
  835. doflow();
  836. #ifdef DEBUG_DETAIL_ON
  837. ESP_LOGD(TAG, "Remove older log files");
  838. #endif
  839. LogFile.RemoveOldLogFile();
  840. LogFile.RemoveOldDataLog();
  841. }
  842. // Round finished -> Logfile
  843. LogFile.WriteToFile(ESP_LOG_INFO, TAG, "Round #" + std::to_string(countRounds) +
  844. " completed (" + std::to_string(getUpTime() - roundStartTime) + " seconds)");
  845. // CPU Temp -> Logfile
  846. LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "CPU Temperature: " + std::to_string((int)temperatureRead()) + "°C");
  847. // WIFI Signal Strength (RSSI) -> Logfile
  848. LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "WIFI Signal (RSSI): " + std::to_string(get_WIFI_RSSI()) + "dBm");
  849. // Check if time is synchronized (if NTP is configured)
  850. if (getUseNtp() && !getTimeIsSet()) {
  851. LogFile.WriteToFile(ESP_LOG_WARN, TAG, "Time server is configured, but time is not yet set!");
  852. StatusLED(TIME_CHECK, 1, false);
  853. }
  854. #if (defined WLAN_USE_MESH_ROAMING && defined WLAN_USE_MESH_ROAMING_ACTIVATE_CLIENT_TRIGGERED_QUERIES)
  855. wifiRoamingQuery();
  856. #endif
  857. // Scan channels and check if an AP with better RSSI is available, then disconnect and try to reconnect to AP with better RSSI
  858. // NOTE: Keep this direct before the following task delay, because scan is done in blocking mode and this takes ca. 1,5 - 2s.
  859. #ifdef WLAN_USE_ROAMING_BY_SCANNING
  860. wifiRoamByScanning();
  861. #endif
  862. fr_delta_ms = (esp_timer_get_time() - fr_start) / 1000;
  863. if (auto_interval > fr_delta_ms)
  864. {
  865. const TickType_t xDelay = (auto_interval - fr_delta_ms) / portTICK_PERIOD_MS;
  866. ESP_LOGD(TAG, "Autoflow: sleep for: %ldms", (long) xDelay);
  867. vTaskDelay( xDelay );
  868. }
  869. }
  870. while(1) // Keep flow task running to handle necessary sub tasks like reboot handler, etc..
  871. {
  872. vTaskDelay(2000 / portTICK_PERIOD_MS);
  873. }
  874. vTaskDelete(NULL); //Delete this task if it exits from the loop above
  875. xHandletask_autodoFlow = NULL;
  876. ESP_LOGD(TAG, "task_autodoFlow: end");
  877. }
  878. void InitializeFlowTask()
  879. {
  880. BaseType_t xReturned;
  881. ESP_LOGD(TAG, "getESPHeapInfo: %s", getESPHeapInfo().c_str());
  882. uint32_t stackSize = 16 * 1024;
  883. xReturned = xTaskCreatePinnedToCore(&task_autodoFlow, "task_autodoFlow", stackSize, NULL, tskIDLE_PRIORITY+2, &xHandletask_autodoFlow, 0);
  884. if( xReturned != pdPASS )
  885. {
  886. LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "Creation task_autodoFlow failed. Requested stack size:" + std::to_string(stackSize));
  887. LogFile.WriteHeapInfo("Creation task_autodoFlow failed");
  888. }
  889. ESP_LOGD(TAG, "getESPHeapInfo: %s", getESPHeapInfo().c_str());
  890. }
  891. void register_server_main_flow_task_uri(httpd_handle_t server)
  892. {
  893. ESP_LOGI(TAG, "server_main_flow_task - Registering URI handlers");
  894. httpd_uri_t camuri = { };
  895. camuri.method = HTTP_GET;
  896. camuri.uri = "/doinit";
  897. camuri.handler = handler_init;
  898. camuri.user_ctx = (void*) "Light On";
  899. httpd_register_uri_handler(server, &camuri);
  900. // Legacy API => New: "/setPreValue"
  901. camuri.uri = "/setPreValue.html";
  902. camuri.handler = handler_prevalue;
  903. camuri.user_ctx = (void*) "Prevalue";
  904. httpd_register_uri_handler(server, &camuri);
  905. camuri.uri = "/setPreValue";
  906. camuri.handler = handler_prevalue;
  907. camuri.user_ctx = (void*) "Prevalue";
  908. httpd_register_uri_handler(server, &camuri);
  909. camuri.uri = "/flow_start";
  910. camuri.handler = handler_flow_start;
  911. camuri.user_ctx = (void*) "Flow Start";
  912. httpd_register_uri_handler(server, &camuri);
  913. camuri.uri = "/statusflow.html";
  914. camuri.handler = handler_statusflow;
  915. camuri.user_ctx = (void*) "Light Off";
  916. httpd_register_uri_handler(server, &camuri);
  917. camuri.uri = "/statusflow";
  918. camuri.handler = handler_statusflow;
  919. camuri.user_ctx = (void*) "Light Off";
  920. httpd_register_uri_handler(server, &camuri);
  921. // Legacy API => New: "/cpu_temperature"
  922. camuri.uri = "/cputemp.html";
  923. camuri.handler = handler_cputemp;
  924. camuri.user_ctx = (void*) "Light Off";
  925. httpd_register_uri_handler(server, &camuri);
  926. camuri.uri = "/cpu_temperature";
  927. camuri.handler = handler_cputemp;
  928. camuri.user_ctx = (void*) "Light Off";
  929. httpd_register_uri_handler(server, &camuri);
  930. // Legacy API => New: "/rssi"
  931. camuri.uri = "/rssi.html";
  932. camuri.handler = handler_rssi;
  933. camuri.user_ctx = (void*) "Light Off";
  934. httpd_register_uri_handler(server, &camuri);
  935. camuri.uri = "/rssi";
  936. camuri.handler = handler_rssi;
  937. camuri.user_ctx = (void*) "Light Off";
  938. httpd_register_uri_handler(server, &camuri);
  939. camuri.uri = "/uptime";
  940. camuri.handler = handler_uptime;
  941. camuri.user_ctx = (void*) "Light Off";
  942. httpd_register_uri_handler(server, &camuri);
  943. camuri.uri = "/editflow";
  944. camuri.handler = handler_editflow;
  945. camuri.user_ctx = (void*) "EditFlow";
  946. httpd_register_uri_handler(server, &camuri);
  947. // Legacy API => New: "/value"
  948. camuri.uri = "/value.html";
  949. camuri.handler = handler_wasserzaehler;
  950. camuri.user_ctx = (void*) "Value";
  951. httpd_register_uri_handler(server, &camuri);
  952. camuri.uri = "/value";
  953. camuri.handler = handler_wasserzaehler;
  954. camuri.user_ctx = (void*) "Value";
  955. httpd_register_uri_handler(server, &camuri);
  956. // Legacy API => New: "/value"
  957. camuri.uri = "/wasserzaehler.html";
  958. camuri.handler = handler_wasserzaehler;
  959. camuri.user_ctx = (void*) "Wasserzaehler";
  960. httpd_register_uri_handler(server, &camuri);
  961. camuri.uri = "/json";
  962. camuri.handler = handler_json;
  963. camuri.user_ctx = (void*) "JSON";
  964. httpd_register_uri_handler(server, &camuri);
  965. camuri.uri = "/heap";
  966. camuri.handler = handler_get_heap;
  967. camuri.user_ctx = (void*) "Heap";
  968. httpd_register_uri_handler(server, &camuri);
  969. camuri.uri = "/stream";
  970. camuri.handler = handler_stream;
  971. camuri.user_ctx = (void*) "stream";
  972. httpd_register_uri_handler(server, &camuri);
  973. }