server_tflite.cpp 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844
  1. #include "server_tflite.h"
  2. #include <string>
  3. #include <vector>
  4. #include "string.h"
  5. #include "esp_log.h"
  6. #include <iomanip>
  7. #include <sstream>
  8. #include "defines.h"
  9. #include "Helper.h"
  10. #include "esp_camera.h"
  11. #include "time_sntp.h"
  12. #include "ClassControllCamera.h"
  13. #include "ClassFlowControll.h"
  14. #include "ClassLogFile.h"
  15. #include "server_GPIO.h"
  16. #include "server_file.h"
  17. #include "connect_wlan.h"
  18. #define DEBUG_DETAIL_ON
  19. ClassFlowControll tfliteflow;
  20. TaskHandle_t xHandleblink_task_doFlow = NULL;
  21. TaskHandle_t xHandletask_autodoFlow = NULL;
  22. bool flowisrunning = false;
  23. long auto_intervall = 0;
  24. bool auto_isrunning = false;
  25. int countRounds = 0;
  26. static const char *TAGTFLITE = "server_tflite";
  27. int getCountFlowRounds() {
  28. return countRounds;
  29. }
  30. esp_err_t GetJPG(std::string _filename, httpd_req_t *req)
  31. {
  32. return tfliteflow.GetJPGStream(_filename, req);
  33. }
  34. esp_err_t GetRawJPG(httpd_req_t *req)
  35. {
  36. return tfliteflow.SendRawJPG(req);
  37. }
  38. bool isSetupModusActive() {
  39. return tfliteflow.getStatusSetupModus();
  40. return false;
  41. }
  42. void KillTFliteTasks()
  43. {
  44. #ifdef DEBUG_DETAIL_ON
  45. printf("Handle: xHandleblink_task_doFlow: %ld\n", (long) xHandleblink_task_doFlow);
  46. #endif
  47. if (xHandleblink_task_doFlow != NULL)
  48. {
  49. TaskHandle_t xHandleblink_task_doFlowTmp = xHandleblink_task_doFlow;
  50. xHandleblink_task_doFlow = NULL;
  51. vTaskDelete(xHandleblink_task_doFlowTmp);
  52. #ifdef DEBUG_DETAIL_ON
  53. printf("Killed: xHandleblink_task_doFlow\n");
  54. #endif
  55. }
  56. #ifdef DEBUG_DETAIL_ON
  57. printf("Handle: xHandletask_autodoFlow: %ld\n", (long) xHandletask_autodoFlow);
  58. #endif
  59. if (xHandletask_autodoFlow != NULL)
  60. {
  61. TaskHandle_t xHandletask_autodoFlowTmp = xHandletask_autodoFlow;
  62. xHandletask_autodoFlow = NULL;
  63. vTaskDelete(xHandletask_autodoFlowTmp);
  64. #ifdef DEBUG_DETAIL_ON
  65. printf("Killed: xHandletask_autodoFlow\n");
  66. #endif
  67. }
  68. }
  69. void doInit(void)
  70. {
  71. #ifdef DEBUG_DETAIL_ON
  72. printf("Start tfliteflow.InitFlow(config);\n");
  73. #endif
  74. tfliteflow.InitFlow(CONFIG_FILE);
  75. #ifdef DEBUG_DETAIL_ON
  76. printf("Finished tfliteflow.InitFlow(config);\n");
  77. #endif
  78. }
  79. bool doflow(void)
  80. {
  81. std::string zw_time = gettimestring(LOGFILE_TIME_FORMAT);
  82. printf("doflow - start %s\n", zw_time.c_str());
  83. flowisrunning = true;
  84. tfliteflow.doFlow(zw_time);
  85. flowisrunning = false;
  86. #ifdef DEBUG_DETAIL_ON
  87. printf("doflow - end %s\n", zw_time.c_str());
  88. #endif
  89. return true;
  90. }
  91. void blink_task_doFlow(void *pvParameter)
  92. {
  93. #ifdef DEBUG_DETAIL_ON
  94. printf("blink_task_doFlow\n");
  95. #endif
  96. if (!flowisrunning)
  97. {
  98. flowisrunning = true;
  99. doflow();
  100. flowisrunning = false;
  101. }
  102. vTaskDelete(NULL); //Delete this task if it exits from the loop above
  103. xHandleblink_task_doFlow = NULL;
  104. }
  105. esp_err_t handler_init(httpd_req_t *req)
  106. {
  107. #ifdef DEBUG_DETAIL_ON
  108. LogFile.WriteHeapInfo("handler_init - Start");
  109. printf("handler_doinit uri:\n"); printf(req->uri); printf("\n");
  110. #endif
  111. const char* resp_str = "Init started<br>";
  112. httpd_resp_send(req, resp_str, strlen(resp_str));
  113. doInit();
  114. resp_str = "Init done<br>";
  115. httpd_resp_send(req, resp_str, strlen(resp_str));
  116. /* Respond with an empty chunk to signal HTTP response completion */
  117. httpd_resp_send_chunk(req, NULL, 0);
  118. #ifdef DEBUG_DETAIL_ON
  119. LogFile.WriteHeapInfo("handler_init - Done");
  120. #endif
  121. return ESP_OK;
  122. };
  123. esp_err_t handler_doflow(httpd_req_t *req)
  124. {
  125. #ifdef DEBUG_DETAIL_ON
  126. LogFile.WriteHeapInfo("handler_doflow - Start");
  127. #endif
  128. printf("handler_doFlow uri: "); printf(req->uri); printf("\n");
  129. if (flowisrunning)
  130. {
  131. const char* resp_str = "doFlow läuft bereits und kann nicht nochmal gestartet werden";
  132. httpd_resp_send(req, resp_str, strlen(resp_str));
  133. return 2;
  134. }
  135. else
  136. {
  137. xTaskCreate(&blink_task_doFlow, "blink_doFlow", configMINIMAL_STACK_SIZE * 64, NULL, tskIDLE_PRIORITY+1, &xHandleblink_task_doFlow);
  138. }
  139. const char* resp_str = "doFlow gestartet - dauert ca. 60 Sekunden";
  140. httpd_resp_send(req, resp_str, strlen(resp_str));
  141. /* Respond with an empty chunk to signal HTTP response completion */
  142. httpd_resp_send_chunk(req, NULL, 0);
  143. #ifdef DEBUG_DETAIL_ON
  144. LogFile.WriteHeapInfo("handler_doflow - Done");
  145. #endif
  146. return ESP_OK;
  147. };
  148. esp_err_t handler_json(httpd_req_t *req)
  149. {
  150. #ifdef DEBUG_DETAIL_ON
  151. LogFile.WriteHeapInfo("handler_json - Start");
  152. #endif
  153. printf("handler_JSON uri:\n"); printf(req->uri); printf("\n");
  154. char _query[100];
  155. // char _size[10];
  156. httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*");
  157. httpd_resp_set_type(req, "application/json");
  158. std::string zw = tfliteflow.getJSON();
  159. if (zw.length() > 0)
  160. httpd_resp_sendstr_chunk(req, zw.c_str());
  161. string query = std::string(_query);
  162. /* Respond with an empty chunk to signal HTTP response completion */
  163. httpd_resp_sendstr_chunk(req, NULL);
  164. #ifdef DEBUG_DETAIL_ON
  165. LogFile.WriteHeapInfo("handler_JSON - Done");
  166. #endif
  167. return ESP_OK;
  168. };
  169. esp_err_t handler_wasserzaehler(httpd_req_t *req)
  170. {
  171. #ifdef DEBUG_DETAIL_ON
  172. LogFile.WriteHeapInfo("handler_wasserzaehler - Start");
  173. #endif
  174. bool _rawValue = false;
  175. bool _noerror = false;
  176. bool _all = false;
  177. std::string _type = "value";
  178. string zw;
  179. printf("handler_wasserzaehler uri:\n"); printf(req->uri); printf("\n");
  180. char _query[100];
  181. char _size[10];
  182. if (httpd_req_get_url_query_str(req, _query, 100) == ESP_OK)
  183. {
  184. // printf("Query: "); printf(_query); printf("\n");
  185. if (httpd_query_key_value(_query, "all", _size, 10) == ESP_OK)
  186. {
  187. #ifdef DEBUG_DETAIL_ON
  188. printf("all is found"); printf(_size); printf("\n");
  189. #endif
  190. _all = true;
  191. }
  192. if (httpd_query_key_value(_query, "type", _size, 10) == ESP_OK)
  193. {
  194. #ifdef DEBUG_DETAIL_ON
  195. printf("all is found"); printf(_size); printf("\n");
  196. #endif
  197. _type = std::string(_size);
  198. }
  199. if (httpd_query_key_value(_query, "rawvalue", _size, 10) == ESP_OK)
  200. {
  201. #ifdef DEBUG_DETAIL_ON
  202. printf("rawvalue is found"); printf(_size); printf("\n");
  203. #endif
  204. _rawValue = true;
  205. }
  206. if (httpd_query_key_value(_query, "noerror", _size, 10) == ESP_OK)
  207. {
  208. #ifdef DEBUG_DETAIL_ON
  209. printf("noerror is found"); printf(_size); printf("\n");
  210. #endif
  211. _noerror = true;
  212. }
  213. }
  214. httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*");
  215. if (_all)
  216. {
  217. httpd_resp_set_type(req, "text/plain");
  218. printf("TYPE: %s\n", _type.c_str());
  219. int _intype = READOUT_TYPE_VALUE;
  220. if (_type == "prevalue")
  221. _intype = READOUT_TYPE_PREVALUE;
  222. if (_type == "raw")
  223. _intype = READOUT_TYPE_RAWVALUE;
  224. if (_type == "error")
  225. _intype = READOUT_TYPE_ERROR;
  226. zw = tfliteflow.getReadoutAll(_intype);
  227. printf("ZW: %s\n", zw.c_str());
  228. if (zw.length() > 0)
  229. httpd_resp_sendstr_chunk(req, zw.c_str());
  230. httpd_resp_sendstr_chunk(req, NULL);
  231. return ESP_OK;
  232. }
  233. zw = tfliteflow.getReadout(_rawValue, _noerror);
  234. if (zw.length() > 0)
  235. httpd_resp_sendstr_chunk(req, zw.c_str());
  236. string query = std::string(_query);
  237. // printf("Query: %s\n", query.c_str());
  238. if (query.find("full") != std::string::npos)
  239. {
  240. string txt, zw;
  241. txt = "<p>Aligned Image: <p><img src=\"/img_tmp/alg_roi.jpg\"> <p>\n";
  242. txt = txt + "Digital Counter: <p> ";
  243. httpd_resp_sendstr_chunk(req, txt.c_str());
  244. std::vector<HTMLInfo*> htmlinfodig;
  245. htmlinfodig = tfliteflow.GetAllDigital();
  246. for (int i = 0; i < htmlinfodig.size(); ++i)
  247. {
  248. if (tfliteflow.GetTypeDigital() == Digital)
  249. {
  250. if (htmlinfodig[i]->val == 10)
  251. zw = "NaN";
  252. else
  253. zw = to_string((int) htmlinfodig[i]->val);
  254. txt = "<img src=\"/img_tmp/" + htmlinfodig[i]->filename + "\"> " + zw;
  255. }
  256. else
  257. {
  258. std::stringstream stream;
  259. stream << std::fixed << std::setprecision(1) << htmlinfodig[i]->val;
  260. zw = stream.str();
  261. txt = "<img src=\"/img_tmp/" + htmlinfodig[i]->filename + "\"> " + zw;
  262. }
  263. httpd_resp_sendstr_chunk(req, txt.c_str());
  264. delete htmlinfodig[i];
  265. }
  266. htmlinfodig.clear();
  267. txt = " <p> Analog Meter: <p> ";
  268. httpd_resp_sendstr_chunk(req, txt.c_str());
  269. std::vector<HTMLInfo*> htmlinfoana;
  270. htmlinfoana = tfliteflow.GetAllAnalog();
  271. for (int i = 0; i < htmlinfoana.size(); ++i)
  272. {
  273. std::stringstream stream;
  274. stream << std::fixed << std::setprecision(1) << htmlinfoana[i]->val;
  275. zw = stream.str();
  276. txt = "<img src=\"/img_tmp/" + htmlinfoana[i]->filename + "\"> " + zw;
  277. httpd_resp_sendstr_chunk(req, txt.c_str());
  278. delete htmlinfoana[i];
  279. }
  280. htmlinfoana.clear();
  281. }
  282. /* Respond with an empty chunk to signal HTTP response completion */
  283. httpd_resp_sendstr_chunk(req, NULL);
  284. #ifdef DEBUG_DETAIL_ON
  285. LogFile.WriteHeapInfo("handler_wasserzaehler - Done");
  286. #endif
  287. return ESP_OK;
  288. };
  289. esp_err_t handler_editflow(httpd_req_t *req)
  290. {
  291. #ifdef DEBUG_DETAIL_ON
  292. LogFile.WriteHeapInfo("handler_editflow - Start");
  293. #endif
  294. printf("handler_editflow uri: "); printf(req->uri); printf("\n");
  295. char _query[200];
  296. char _valuechar[30];
  297. string _task;
  298. if (httpd_req_get_url_query_str(req, _query, 200) == ESP_OK)
  299. {
  300. if (httpd_query_key_value(_query, "task", _valuechar, 30) == ESP_OK)
  301. {
  302. #ifdef DEBUG_DETAIL_ON
  303. printf("task is found: %s\n", _valuechar);
  304. #endif
  305. _task = string(_valuechar);
  306. }
  307. }
  308. if (_task.compare("tflite") == 0)
  309. {
  310. printf("Get tflite list\n");
  311. return get_tflite_file_handler(req);
  312. }
  313. if (_task.compare("copy") == 0)
  314. {
  315. string in, out, zw;
  316. httpd_query_key_value(_query, "in", _valuechar, 30);
  317. in = string(_valuechar);
  318. httpd_query_key_value(_query, "out", _valuechar, 30);
  319. out = string(_valuechar);
  320. #ifdef DEBUG_DETAIL_ON
  321. printf("in: "); printf(in.c_str()); printf("\n");
  322. printf("out: "); printf(out.c_str()); printf("\n");
  323. #endif
  324. in = "/sdcard" + in;
  325. out = "/sdcard" + out;
  326. CopyFile(in, out);
  327. zw = "Copy Done";
  328. httpd_resp_sendstr_chunk(req, zw.c_str());
  329. }
  330. if (_task.compare("cutref") == 0)
  331. {
  332. string in, out, zw;
  333. int x, y, dx, dy;
  334. bool enhance = false;
  335. httpd_query_key_value(_query, "in", _valuechar, 30);
  336. in = string(_valuechar);
  337. httpd_query_key_value(_query, "out", _valuechar, 30);
  338. out = string(_valuechar);
  339. httpd_query_key_value(_query, "x", _valuechar, 30);
  340. zw = string(_valuechar);
  341. x = stoi(zw);
  342. httpd_query_key_value(_query, "y", _valuechar, 30);
  343. zw = string(_valuechar);
  344. y = stoi(zw);
  345. httpd_query_key_value(_query, "dx", _valuechar, 30);
  346. zw = string(_valuechar);
  347. dx = stoi(zw);
  348. httpd_query_key_value(_query, "dy", _valuechar, 30);
  349. zw = string(_valuechar);
  350. dy = stoi(zw);
  351. #ifdef DEBUG_DETAIL_ON
  352. printf("in: "); printf(in.c_str()); printf("\n");
  353. printf("out: "); printf(out.c_str()); printf("\n");
  354. printf("x: "); printf(zw.c_str()); printf("\n");
  355. printf("y: "); printf(zw.c_str()); printf("\n");
  356. printf("dx: "); printf(zw.c_str()); printf("\n");
  357. printf("dy: "); printf(zw.c_str()); printf("\n");
  358. #endif
  359. if (httpd_query_key_value(_query, "enhance", _valuechar, 10) == ESP_OK)
  360. {
  361. zw = string(_valuechar);
  362. if (zw.compare("true") == 0)
  363. {
  364. enhance = true;
  365. }
  366. }
  367. in = "/sdcard" + in;
  368. out = "/sdcard" + out;
  369. string out2 = out.substr(0, out.length() - 4) + "_org.jpg";
  370. CAlignAndCutImage *caic = new CAlignAndCutImage(in);
  371. caic->CutAndSave(out2, x, y, dx, dy);
  372. delete caic;
  373. CImageBasis *cim = new CImageBasis(out2);
  374. if (enhance)
  375. {
  376. cim->Contrast(90);
  377. }
  378. cim->SaveToFile(out);
  379. delete cim;
  380. zw = "CutImage Done";
  381. httpd_resp_sendstr_chunk(req, zw.c_str());
  382. }
  383. if (_task.compare("test_take") == 0)
  384. {
  385. std::string _host = "";
  386. std::string _bri = "";
  387. std::string _con = "";
  388. std::string _sat = "";
  389. std::string _int = "";
  390. int bri = -100;
  391. int sat = -100;
  392. int con = -100;
  393. int intens = -100;
  394. if (httpd_query_key_value(_query, "host", _valuechar, 30) == ESP_OK) {
  395. _host = std::string(_valuechar);
  396. }
  397. if (httpd_query_key_value(_query, "int", _valuechar, 30) == ESP_OK) {
  398. _int = std::string(_valuechar);
  399. intens = stoi(_int);
  400. }
  401. if (httpd_query_key_value(_query, "bri", _valuechar, 30) == ESP_OK) {
  402. _bri = std::string(_valuechar);
  403. bri = stoi(_bri);
  404. }
  405. if (httpd_query_key_value(_query, "con", _valuechar, 30) == ESP_OK) {
  406. _con = std::string(_valuechar);
  407. con = stoi(_con);
  408. }
  409. if (httpd_query_key_value(_query, "sat", _valuechar, 30) == ESP_OK) {
  410. _sat = std::string(_valuechar);
  411. sat = stoi(_sat);
  412. }
  413. // printf("Parameter host: "); printf(_host.c_str()); printf("\n");
  414. // string zwzw = "Do " + _task + " start\n"; printf(zwzw.c_str());
  415. Camera.SetBrightnessContrastSaturation(bri, con, sat);
  416. Camera.SetLEDIntensity(intens);
  417. printf("test_take - vor MakeImage");
  418. std::string zw = tfliteflow.doSingleStep("[MakeImage]", _host);
  419. httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*");
  420. httpd_resp_sendstr_chunk(req, zw.c_str());
  421. }
  422. if (_task.compare("test_align") == 0)
  423. {
  424. std::string _host = "";
  425. if (httpd_query_key_value(_query, "host", _valuechar, 30) == ESP_OK) {
  426. _host = std::string(_valuechar);
  427. }
  428. // printf("Parameter host: "); printf(_host.c_str()); printf("\n");
  429. // string zwzw = "Do " + _task + " start\n"; printf(zwzw.c_str());
  430. std::string zw = tfliteflow.doSingleStep("[Alignment]", _host);
  431. httpd_resp_sendstr_chunk(req, zw.c_str());
  432. }
  433. /* Respond with an empty chunk to signal HTTP response completion */
  434. httpd_resp_sendstr_chunk(req, NULL);
  435. #ifdef DEBUG_DETAIL_ON
  436. LogFile.WriteHeapInfo("handler_editflow - Done");
  437. #endif
  438. return ESP_OK;
  439. };
  440. esp_err_t handler_statusflow(httpd_req_t *req)
  441. {
  442. #ifdef DEBUG_DETAIL_ON
  443. LogFile.WriteHeapInfo("handler_prevalue - Start");
  444. #endif
  445. const char* resp_str;
  446. #ifdef DEBUG_DETAIL_ON
  447. printf("handler_prevalue:\n"); printf(req->uri); printf("\n");
  448. #endif
  449. string* zw = tfliteflow.getActStatus();
  450. resp_str = zw->c_str();
  451. httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*");
  452. httpd_resp_send(req, resp_str, strlen(resp_str));
  453. /* Respond with an empty chunk to signal HTTP response completion */
  454. httpd_resp_send_chunk(req, NULL, 0);
  455. #ifdef DEBUG_DETAIL_ON
  456. LogFile.WriteHeapInfo("handler_prevalue - Start");
  457. #endif
  458. return ESP_OK;
  459. };
  460. esp_err_t handler_cputemp(httpd_req_t *req)
  461. {
  462. #ifdef DEBUG_DETAIL_ON
  463. LogFile.WriteHeapInfo("handler_cputemp - Start");
  464. #endif
  465. const char* resp_str;
  466. char cputemp[20];
  467. sprintf(cputemp, "CPU Temp: %4.1f°C", temperatureRead());
  468. resp_str = cputemp;
  469. httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*");
  470. httpd_resp_send(req, resp_str, strlen(resp_str));
  471. /* Respond with an empty chunk to signal HTTP response completion */
  472. httpd_resp_send_chunk(req, NULL, 0);
  473. #ifdef DEBUG_DETAIL_ON
  474. LogFile.WriteHeapInfo("handler_cputemp - End");
  475. #endif
  476. return ESP_OK;
  477. };
  478. esp_err_t handler_rssi(httpd_req_t *req)
  479. {
  480. #ifdef DEBUG_DETAIL_ON
  481. LogFile.WriteHeapInfo("handler_rssi - Start");
  482. #endif
  483. const char* resp_str;
  484. char rssi[20];
  485. sprintf(rssi, "RSSI: %idBm", get_WIFI_RSSI());
  486. resp_str = rssi;
  487. httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*");
  488. httpd_resp_send(req, resp_str, strlen(resp_str));
  489. /* Respond with an empty chunk to signal HTTP response completion */
  490. httpd_resp_send_chunk(req, NULL, 0);
  491. #ifdef DEBUG_DETAIL_ON
  492. LogFile.WriteHeapInfo("handler_rssi - End");
  493. #endif
  494. return ESP_OK;
  495. };
  496. esp_err_t handler_prevalue(httpd_req_t *req)
  497. {
  498. #ifdef DEBUG_DETAIL_ON
  499. LogFile.WriteHeapInfo("handler_prevalue - Start");
  500. #endif
  501. const char* resp_str;
  502. string zw;
  503. #ifdef DEBUG_DETAIL_ON
  504. printf("handler_prevalue:\n"); printf(req->uri); printf("\n");
  505. #endif
  506. char _query[100];
  507. char _size[10] = "";
  508. char _numbers[50] = "default";
  509. if (httpd_req_get_url_query_str(req, _query, 100) == ESP_OK)
  510. {
  511. #ifdef DEBUG_DETAIL_ON
  512. printf("Query: "); printf(_query); printf("\n");
  513. #endif
  514. if (httpd_query_key_value(_query, "value", _size, 10) == ESP_OK)
  515. {
  516. #ifdef DEBUG_DETAIL_ON
  517. printf("Value: "); printf(_size); printf("\n");
  518. #endif
  519. }
  520. httpd_query_key_value(_query, "numbers", _numbers, 50);
  521. }
  522. if (strlen(_size) == 0)
  523. {
  524. zw = tfliteflow.GetPrevalue(std::string(_numbers));
  525. }
  526. else
  527. {
  528. zw = "SetPrevalue to " + tfliteflow.UpdatePrevalue(_size, _numbers, true);
  529. }
  530. resp_str = zw.c_str();
  531. httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*");
  532. httpd_resp_send(req, resp_str, strlen(resp_str));
  533. /* Respond with an empty chunk to signal HTTP response completion */
  534. httpd_resp_send_chunk(req, NULL, 0);
  535. #ifdef DEBUG_DETAIL_ON
  536. LogFile.WriteHeapInfo("handler_prevalue - End");
  537. #endif
  538. return ESP_OK;
  539. };
  540. void task_autodoFlow(void *pvParameter)
  541. {
  542. int64_t fr_start, fr_delta_ms;
  543. printf("task_autodoFlow: start\r\n");
  544. doInit();
  545. gpio_handler_init();
  546. auto_isrunning = tfliteflow.isAutoStart(auto_intervall);
  547. if (isSetupModusActive()) {
  548. auto_isrunning = false;
  549. std::string zw_time = gettimestring(LOGFILE_TIME_FORMAT);
  550. tfliteflow.doFlowMakeImageOnly(zw_time);
  551. }
  552. while (auto_isrunning)
  553. {
  554. std::string _zw = "task_autodoFlow - next round - Round #" + std::to_string(++countRounds);
  555. LogFile.WriteToFile(_zw);
  556. printf("Autoflow: start\n");
  557. fr_start = esp_timer_get_time();
  558. if (flowisrunning)
  559. {
  560. #ifdef DEBUG_DETAIL_ON
  561. printf("Autoflow: doFLow laeuft bereits!\n");
  562. #endif
  563. }
  564. else
  565. {
  566. #ifdef DEBUG_DETAIL_ON
  567. printf("Autoflow: doFLow wird gestartet\n");
  568. #endif
  569. flowisrunning = true;
  570. doflow();
  571. #ifdef DEBUG_DETAIL_ON
  572. printf("Remove older log files\n");
  573. #endif
  574. LogFile.RemoveOld();
  575. }
  576. LogFile.WriteToFile("task_autodoFlow - round done");
  577. //CPU Temp
  578. float cputmp = temperatureRead();
  579. std::stringstream stream;
  580. stream << std::fixed << std::setprecision(1) << cputmp;
  581. string zwtemp = "CPU Temperature: " + stream.str();
  582. LogFile.WriteToFile(zwtemp);
  583. printf("CPU Temperature: %.2f\n", cputmp);
  584. fr_delta_ms = (esp_timer_get_time() - fr_start) / 1000;
  585. if (auto_intervall > fr_delta_ms)
  586. {
  587. const TickType_t xDelay = (auto_intervall - fr_delta_ms) / portTICK_PERIOD_MS;
  588. printf("Autoflow: sleep for : %ldms\n", (long) xDelay);
  589. vTaskDelay( xDelay );
  590. }
  591. }
  592. vTaskDelete(NULL); //Delete this task if it exits from the loop above
  593. xHandletask_autodoFlow = NULL;
  594. printf("task_autodoFlow: end\r\n");
  595. }
  596. void TFliteDoAutoStart()
  597. {
  598. BaseType_t xReturned;
  599. int _i = configMINIMAL_STACK_SIZE;
  600. printf("task_autodoFlow configMINIMAL_STACK_SIZE: %d\n", _i);
  601. printf("getESPHeapInfo: %s\n", getESPHeapInfo().c_str());
  602. xReturned = xTaskCreate(&task_autodoFlow, "task_autodoFlow", configMINIMAL_STACK_SIZE * 35, NULL, tskIDLE_PRIORITY+1, &xHandletask_autodoFlow);
  603. if( xReturned != pdPASS )
  604. {
  605. //Memory: 64 --> 48 --> 35 --> 25
  606. printf("ERROR task_autodoFlow konnte nicht erzeugt werden !!\r\n");
  607. }
  608. printf("getESPHeapInfo: %s\n", getESPHeapInfo().c_str());
  609. }
  610. std::string GetMQTTMainTopic()
  611. {
  612. return tfliteflow.GetMQTTMainTopic();
  613. }
  614. void register_server_tflite_uri(httpd_handle_t server)
  615. {
  616. ESP_LOGI(TAGTFLITE, "server_part_camera - Registering URI handlers");
  617. httpd_uri_t camuri = { };
  618. camuri.method = HTTP_GET;
  619. camuri.uri = "/doinit";
  620. camuri.handler = handler_init;
  621. camuri.user_ctx = (void*) "Light On";
  622. httpd_register_uri_handler(server, &camuri);
  623. camuri.uri = "/setPreValue.html";
  624. camuri.handler = handler_prevalue;
  625. camuri.user_ctx = (void*) "Prevalue";
  626. httpd_register_uri_handler(server, &camuri);
  627. camuri.uri = "/doflow";
  628. camuri.handler = handler_doflow;
  629. camuri.user_ctx = (void*) "Light Off";
  630. httpd_register_uri_handler(server, &camuri);
  631. camuri.uri = "/statusflow.html";
  632. camuri.handler = handler_statusflow;
  633. camuri.user_ctx = (void*) "Light Off";
  634. httpd_register_uri_handler(server, &camuri);
  635. camuri.uri = "/cputemp.html";
  636. camuri.handler = handler_cputemp;
  637. camuri.user_ctx = (void*) "Light Off";
  638. httpd_register_uri_handler(server, &camuri);
  639. camuri.uri = "/rssi.html";
  640. camuri.handler = handler_rssi;
  641. camuri.user_ctx = (void*) "Light Off";
  642. httpd_register_uri_handler(server, &camuri);
  643. camuri.uri = "/editflow.html";
  644. camuri.handler = handler_editflow;
  645. camuri.user_ctx = (void*) "EditFlow";
  646. httpd_register_uri_handler(server, &camuri);
  647. camuri.uri = "/wasserzaehler.html";
  648. camuri.handler = handler_wasserzaehler;
  649. camuri.user_ctx = (void*) "Wasserzaehler";
  650. httpd_register_uri_handler(server, &camuri);
  651. camuri.uri = "/json";
  652. camuri.handler = handler_json;
  653. camuri.user_ctx = (void*) "JSON";
  654. httpd_register_uri_handler(server, &camuri);
  655. }