server_tflite.cpp 21 KB

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