MainFlowControl.cpp 39 KB

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