server_tflite.cpp 21 KB

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