| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969 |
- #include "MainFlowControl.h"
- #include <new>
- #include <string>
- #include <vector>
- #include "string.h"
- #include "esp_log.h"
- #include <esp_timer.h>
- #include "freertos/FreeRTOS.h"
- #include "freertos/task.h"
- #include <iomanip>
- #include <sstream>
- #include "../../include/defines.h"
- #include "Helper.h"
- #include "statusled.h"
- #include "esp_camera.h"
- #include "time_sntp.h"
- #include "ClassControllCamera.h"
- #include "ClassFlowControll.h"
- #include "ClassLogFile.h"
- #include "server_GPIO.h"
- #include "server_file.h"
- #include "server_ota.h"
- #include "read_wlanini.h"
- #include "connect_wlan.h"
- #include "psram.h"
- #include "basic_auth.h"
- // support IDF 5.x
- #ifndef portTICK_RATE_MS
- #define portTICK_RATE_MS portTICK_PERIOD_MS
- #endif
- ClassFlowControll flowctrl;
- camera_flow_config_temp_t CFstatus;
- TaskHandle_t xHandletask_autodoFlow = NULL;
- bool bTaskAutoFlowCreated = false;
- // True only while the flow objects are fully built. bTaskAutoFlowCreated is already true during the
- // post-panic init delay and while doInit() rebuilds the flow, when flowctrl's post-processing is NULL
- // or half-built, so REST handlers that read the results must check this flag instead.
- bool bFlowInitialized = false;
- bool flowisrunning = false;
- // Flow control state is shared by the HTTP server task and the flow task (different cores).
- static portMUX_TYPE flowControlMux = portMUX_INITIALIZER_UNLOCKED;
- static bool flowPauseRequested = false;
- static bool flowPaused = false;
- static bool flowManualRunRequested = false;
- static bool IsFlowRunning()
- {
- bool running;
- portENTER_CRITICAL(&flowControlMux);
- running = flowisrunning;
- portEXIT_CRITICAL(&flowControlMux);
- return running;
- }
- static void SetFlowRunning(bool running)
- {
- portENTER_CRITICAL(&flowControlMux);
- flowisrunning = running;
- portEXIT_CRITICAL(&flowControlMux);
- }
- static bool IsFlowPauseRequested()
- {
- bool requested;
- portENTER_CRITICAL(&flowControlMux);
- requested = flowPauseRequested;
- portEXIT_CRITICAL(&flowControlMux);
- return requested;
- }
- static bool IsFlowPaused()
- {
- bool paused;
- portENTER_CRITICAL(&flowControlMux);
- paused = flowPaused;
- portEXIT_CRITICAL(&flowControlMux);
- return paused;
- }
- static void RequestFlowPause()
- {
- portENTER_CRITICAL(&flowControlMux);
- flowPauseRequested = true;
- portEXIT_CRITICAL(&flowControlMux);
- }
- static void RequestFlowResume()
- {
- portENTER_CRITICAL(&flowControlMux);
- flowPauseRequested = false;
- flowPaused = false;
- flowManualRunRequested = false;
- portEXIT_CRITICAL(&flowControlMux);
- }
- static bool QueueManualRunWhilePaused()
- {
- bool queued = false;
- portENTER_CRITICAL(&flowControlMux);
- if (flowPauseRequested && !flowisrunning)
- {
- flowManualRunRequested = true;
- queued = true;
- }
- portEXIT_CRITICAL(&flowControlMux);
- return queued;
- }
- // Called only by task_autodoFlow at the start of each scheduling iteration.
- // A queued manual run is allowed through once, but the automatic pause remains set.
- static bool UpdateFlowPauseStateForTask()
- {
- bool shouldPause = false;
- portENTER_CRITICAL(&flowControlMux);
- if (flowPauseRequested && flowManualRunRequested && !flowisrunning)
- {
- flowManualRunRequested = false;
- flowPaused = false;
- }
- else if (flowPauseRequested)
- {
- flowPaused = true;
- shouldPause = true;
- }
- else
- {
- flowPaused = false;
- flowManualRunRequested = false;
- }
- portEXIT_CRITICAL(&flowControlMux);
- return shouldPause;
- }
- static void ResetFlowControlState()
- {
- portENTER_CRITICAL(&flowControlMux);
- flowPauseRequested = false;
- flowPaused = false;
- flowManualRunRequested = false;
- flowisrunning = false;
- portEXIT_CRITICAL(&flowControlMux);
- }
- long auto_interval = 0;
- bool autostartIsEnabled = false;
- int countRounds = 0;
- bool isPlannedReboot = false;
- static const char *TAG = "MAINCTRL";
- // #define DEBUG_DETAIL_ON
- void CheckIsPlannedReboot(void)
- {
- FILE *pfile;
- if ((pfile = fopen("/sdcard/reboot.txt", "r")) == NULL)
- {
- // LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "Initial boot or not a planned reboot");
- isPlannedReboot = false;
- }
- else
- {
- LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "Planned reboot");
- DeleteFile("/sdcard/reboot.txt"); // Prevent Boot Loop!!!
- isPlannedReboot = true;
- }
- }
- bool getIsPlannedReboot(void)
- {
- return isPlannedReboot;
- }
- int getCountFlowRounds(void)
- {
- return countRounds;
- }
- esp_err_t GetJPG(std::string _filename, httpd_req_t *req)
- {
- return flowctrl.GetJPGStream(_filename, req);
- }
- esp_err_t GetRawJPG(httpd_req_t *req, bool previewCapture)
- {
- return flowctrl.SendRawJPG(req, previewCapture);
- }
- bool isSetupModusActive(void)
- {
- return flowctrl.getStatusSetupModus();
- }
- void DeleteMainFlowTask(void)
- {
- #ifdef DEBUG_DETAIL_ON
- ESP_LOGD(TAG, "DeleteMainFlowTask: xHandletask_autodoFlow: %ld", (long)xHandletask_autodoFlow);
- #endif
- if (xHandletask_autodoFlow != NULL)
- {
- vTaskDelete(xHandletask_autodoFlow);
- xHandletask_autodoFlow = NULL;
- }
- #ifdef DEBUG_DETAIL_ON
- ESP_LOGD(TAG, "Killed: xHandletask_autodoFlow");
- #endif
- }
- void doInit(void)
- {
- bFlowInitialized = false;
- #ifdef DEBUG_DETAIL_ON
- ESP_LOGD(TAG, "Start flowctrl.InitFlow(config);");
- #endif
- flowctrl.InitFlow(CONFIG_FILE);
- bFlowInitialized = true;
- #ifdef DEBUG_DETAIL_ON
- ESP_LOGD(TAG, "Finished flowctrl.InitFlow(config);");
- #endif
- /* GPIO handler has to be initialized before MQTT init to ensure proper topic subscription */
- gpio_handler_init();
- #ifdef ENABLE_MQTT
- flowctrl.StartMQTTService();
- #endif // ENABLE_MQTT
- }
- bool doflow(void)
- {
- std::string zw_time = getCurrentTimeString(LOGFILE_TIME_FORMAT);
- ESP_LOGD(TAG, "doflow - start %s", zw_time.c_str());
- SetFlowRunning(true);
- flowctrl.doFlow(zw_time);
- SetFlowRunning(false);
- #ifdef DEBUG_DETAIL_ON
- ESP_LOGD(TAG, "doflow - end %s", zw_time.c_str());
- #endif
- return true;
- }
- esp_err_t handler_get_heap(httpd_req_t *req)
- {
- #ifdef DEBUG_DETAIL_ON
- LogFile.WriteHeapInfo("handler_get_heap - Start");
- ESP_LOGD(TAG, "handler_get_heap uri: %s", req->uri);
- #endif
- std::string zw = "Heap info:<br>" + getESPHeapInfo();
- #ifdef TASK_ANALYSIS_ON
- char *pcTaskList = (char *)calloc_psram_heap(std::string(TAG) + "->pcTaskList", 1, sizeof(char) * 768, MALLOC_CAP_8BIT | MALLOC_CAP_SPIRAM);
- if (pcTaskList)
- {
- vTaskList(pcTaskList);
- zw = zw + "<br><br>Task info:<br><pre>Name | State | Prio | Lowest stacksize | Creation order | CPU (-1=NoAffinity)<br>" + std::string(pcTaskList) + "</pre>";
- free_psram_heap(std::string(TAG) + "->pcTaskList", pcTaskList);
- }
- else
- {
- zw = zw + "<br><br>Task info:<br>ERROR - Allocation of TaskList buffer in PSRAM failed";
- }
- #endif
- httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*");
- if (zw.length() > 0)
- {
- httpd_resp_send(req, zw.c_str(), zw.length());
- }
- else
- {
- httpd_resp_send(req, NULL, 0);
- }
- #ifdef DEBUG_DETAIL_ON
- LogFile.WriteHeapInfo("handler_get_heap - Done");
- #endif
- return ESP_OK;
- }
- esp_err_t handler_init(httpd_req_t *req)
- {
- #ifdef DEBUG_DETAIL_ON
- LogFile.WriteHeapInfo("handler_init - Start");
- ESP_LOGD(TAG, "handler_doinit uri: %s", req->uri);
- #endif
- httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*");
- // Rebuilding the flow at runtime is not safe: InitFlow() keeps the old ClassFlow objects (a second full
- // pipeline, ~1.2 MB PSRAM, until allocations fail and the device panics) and races with a running round.
- // Apply the configuration with a reboot instead.
- LogFile.WriteToFile(ESP_LOG_INFO, TAG, "/doinit requested -> rebooting to apply the configuration");
- const char *resp_str = "Reboot to apply the configuration<br>";
- httpd_resp_send(req, resp_str, HTTPD_RESP_USE_STRLEN);
- doReboot();
- #ifdef DEBUG_DETAIL_ON
- LogFile.WriteHeapInfo("handler_init - Done");
- #endif
- return ESP_OK;
- }
- esp_err_t handler_stream(httpd_req_t *req)
- {
- #ifdef DEBUG_DETAIL_ON
- LogFile.WriteHeapInfo("handler_stream - Start");
- ESP_LOGD(TAG, "handler_stream uri: %s", req->uri);
- #endif
- char _query[50] = ""; // stays empty when the request has no query string
- char _value[10];
- bool flashlightOn = false;
- if (httpd_req_get_url_query_str(req, _query, 50) == ESP_OK)
- {
- // ESP_LOGD(TAG, "Query: %s", _query);
- if (httpd_query_key_value(_query, "flashlight", _value, 10) == ESP_OK)
- {
- #ifdef DEBUG_DETAIL_ON
- ESP_LOGD(TAG, "flashlight is found%s", _value);
- #endif
- if (strlen(_value) > 0)
- {
- flashlightOn = true;
- }
- }
- }
- Camera.CaptureToStream(req, flashlightOn);
- #ifdef DEBUG_DETAIL_ON
- LogFile.WriteHeapInfo("handler_stream - Done");
- #endif
- return ESP_OK;
- }
- esp_err_t handler_flow_start(httpd_req_t *req)
- {
- #ifdef DEBUG_DETAIL_ON
- LogFile.WriteHeapInfo("handler_flow_start - Start");
- #endif
- ESP_LOGD(TAG, "handler_flow_start uri: %s", req->uri);
- httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*");
- if (autostartIsEnabled && bTaskAutoFlowCreated && bFlowInitialized)
- {
- if (IsFlowRunning())
- {
- const char *resp_str = "A flow round is already running";
- httpd_resp_send(req, resp_str, HTTPD_RESP_USE_STRLEN);
- }
- else if (IsFlowPauseRequested())
- {
- QueueManualRunWhilePaused();
- if (xHandletask_autodoFlow != NULL) xTaskAbortDelay(xHandletask_autodoFlow);
- const char *resp_str = "One manual round is triggered; the automatic flow will remain paused afterwards";
- httpd_resp_send(req, resp_str, HTTPD_RESP_USE_STRLEN);
- }
- else
- {
- if (xHandletask_autodoFlow != NULL) xTaskAbortDelay(xHandletask_autodoFlow);
- LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "Flow start triggered by REST API /flow_start");
- const char *resp_str = "The flow is going to be started immediately";
- httpd_resp_send(req, resp_str, HTTPD_RESP_USE_STRLEN);
- }
- }
- else
- {
- LogFile.WriteToFile(ESP_LOG_WARN, TAG, "Flow start triggered by REST API, but flow is not active!");
- httpd_resp_send_err(req, HTTPD_403_FORBIDDEN, "Flow start triggered by REST API, but flow is not active");
- }
- #ifdef DEBUG_DETAIL_ON
- LogFile.WriteHeapInfo("handler_flow_start - Done");
- #endif
- return ESP_OK;
- }
- esp_err_t handler_flow_pause(httpd_req_t *req)
- {
- httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*");
- if (!autostartIsEnabled || !bTaskAutoFlowCreated || !bFlowInitialized)
- {
- httpd_resp_send_err(req, HTTPD_403_FORBIDDEN, "Flow is not active and cannot be paused");
- return ESP_FAIL;
- }
- if (IsFlowPaused())
- {
- const char *resp_str = "Flow is already paused";
- httpd_resp_send(req, resp_str, HTTPD_RESP_USE_STRLEN);
- return ESP_OK;
- }
- RequestFlowPause();
- if (xHandletask_autodoFlow != NULL) xTaskAbortDelay(xHandletask_autodoFlow);
- const char *resp_str = IsFlowRunning()
- ? "Pause requested. The current round will finish before the flow pauses"
- : "Pause requested. No further automatic round will start";
- httpd_resp_send(req, resp_str, HTTPD_RESP_USE_STRLEN);
- LogFile.WriteToFile(ESP_LOG_INFO, TAG, "Flow pause requested through Web-UI");
- return ESP_OK;
- }
- esp_err_t handler_flow_resume(httpd_req_t *req)
- {
- httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*");
- if (!autostartIsEnabled || !bTaskAutoFlowCreated || !bFlowInitialized)
- {
- httpd_resp_send_err(req, HTTPD_403_FORBIDDEN, "Flow is not active and cannot be resumed");
- return ESP_FAIL;
- }
- RequestFlowResume();
- if (xHandletask_autodoFlow != NULL) xTaskAbortDelay(xHandletask_autodoFlow);
- const char *resp_str = "Automatic flow resumed. The next round starts immediately";
- httpd_resp_send(req, resp_str, HTTPD_RESP_USE_STRLEN);
- LogFile.WriteToFile(ESP_LOG_INFO, TAG, "Automatic flow resumed through Web-UI");
- return ESP_OK;
- }
- #ifdef ENABLE_MQTT
- esp_err_t MQTTCtrlFlowStart(std::string _topic)
- {
- #ifdef DEBUG_DETAIL_ON
- LogFile.WriteHeapInfo("MQTTCtrlFlowStart - Start");
- #endif
- ESP_LOGD(TAG, "MQTTCtrlFlowStart: topic %s", _topic.c_str());
- if (autostartIsEnabled)
- {
- if (IsFlowPauseRequested())
- {
- if (!IsFlowRunning() && QueueManualRunWhilePaused() && xHandletask_autodoFlow != NULL)
- xTaskAbortDelay(xHandletask_autodoFlow);
- }
- else if (xHandletask_autodoFlow != NULL)
- {
- xTaskAbortDelay(xHandletask_autodoFlow); // Start immediately if the flow task is in its interval delay.
- }
- LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "Flow start triggered by MQTT topic " + _topic);
- }
- else
- {
- LogFile.WriteToFile(ESP_LOG_WARN, TAG, "Flow start triggered by MQTT topic " + _topic + ", but flow is not active!");
- }
- #ifdef DEBUG_DETAIL_ON
- LogFile.WriteHeapInfo("MQTTCtrlFlowStart - Done");
- #endif
- return ESP_OK;
- }
- #endif // ENABLE_MQTT
- esp_err_t handler_json(httpd_req_t *req)
- {
- #ifdef DEBUG_DETAIL_ON
- LogFile.WriteHeapInfo("handler_json - Start");
- #endif
- ESP_LOGD(TAG, "handler_JSON uri: %s", req->uri);
- if (bTaskAutoFlowCreated && bFlowInitialized)
- {
- httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*");
- httpd_resp_set_type(req, "application/json");
- std::string zw = flowctrl.getJSON();
- if (zw.length() > 0)
- {
- httpd_resp_send(req, zw.c_str(), zw.length());
- }
- else
- {
- httpd_resp_send(req, NULL, 0);
- }
- }
- else
- {
- httpd_resp_send_err(req, HTTPD_403_FORBIDDEN, "Flow not (yet) started: REST API /json not yet available!");
- return ESP_ERR_NOT_FOUND;
- }
- #ifdef DEBUG_DETAIL_ON
- LogFile.WriteHeapInfo("handler_JSON - Done");
- #endif
- return ESP_OK;
- }
- /**
- * Generates a http response containing the OpenMetrics (https://openmetrics.io/) text wire format
- * according to https://github.com/OpenObservability/OpenMetrics/blob/main/specification/OpenMetrics.md#text-format.
- *
- * A MetricFamily with a Metric for each Sequence is provided. If no valid value is available, the metric is not provided.
- * MetricPoints are provided without a timestamp. Additional metrics with some device information is also provided.
- *
- * The metric name prefix is 'ai_on_the_edge_device_'.
- *
- * example configuration for Prometheus (`prometheus.yml`):
- *
- * - job_name: watermeter
- * static_configs:
- * - targets: ['watermeter.fritz.box']
- *
- */
- esp_err_t handler_openmetrics(httpd_req_t *req)
- {
- #ifdef DEBUG_DETAIL_ON
- LogFile.WriteHeapInfo("handler_openmetrics - Start");
- #endif
- ESP_LOGD(TAG, "handler_openmetrics uri: %s", req->uri);
- if (bTaskAutoFlowCreated && bFlowInitialized)
- {
- httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*");
- httpd_resp_set_type(req, "text/plain"); // application/openmetrics-text is not yet supported by prometheus so we use text/plain for now
- const string metricNamePrefix = "ai_on_the_edge_device";
- // get current measurement (flow)
- string response = createSequenceMetrics(metricNamePrefix, flowctrl.getNumbers());
- // CPU Temperature
- response += createMetric(metricNamePrefix + "_cpu_temperature_celsius", "current cpu temperature in celsius", "gauge", std::to_string((int)temperatureRead()));
- // WiFi signal strength
- response += createMetric(metricNamePrefix + "_rssi_dbm", "current WiFi signal strength in dBm", "gauge", std::to_string(get_WIFI_RSSI()));
- // memory info
- response += createMetric(metricNamePrefix + "_memory_heap_free_bytes", "available heap memory", "gauge", std::to_string(getESPHeapSize()));
- // device uptime
- response += createMetric(metricNamePrefix + "_uptime_seconds", "device uptime in seconds", "gauge", std::to_string((long)getUpTime()));
- // data aquisition round
- response += createMetric(metricNamePrefix + "_rounds_total", "data aquisition rounds since device startup", "counter", std::to_string(countRounds));
- // the response always contains at least the metadata (HELP, TYPE) for the MetricFamily so no length check is needed
- httpd_resp_send(req, response.c_str(), response.length());
- }
- else
- {
- httpd_resp_send_err(req, HTTPD_403_FORBIDDEN, "Flow not (yet) started: REST API /metrics not yet available!");
- return ESP_ERR_NOT_FOUND;
- }
- #ifdef DEBUG_DETAIL_ON
- LogFile.WriteHeapInfo("handler_openmetrics - Done");
- #endif
- return ESP_OK;
- }
- esp_err_t handler_wasserzaehler(httpd_req_t *req)
- {
- #ifdef DEBUG_DETAIL_ON
- LogFile.WriteHeapInfo("handler water counter - Start");
- #endif
- if (bTaskAutoFlowCreated)
- {
- bool _rawValue = false;
- bool _noerror = false;
- bool _all = false;
- std::string _type = "value";
- std::string zw;
- ESP_LOGD(TAG, "handler water counter uri: %s", req->uri);
- char _query[100] = ""; // stays empty when the request has no query string
- char _size[10];
- if (httpd_req_get_url_query_str(req, _query, 100) == ESP_OK)
- {
- // ESP_LOGD(TAG, "Query: %s", _query);
- if (httpd_query_key_value(_query, "all", _size, 10) == ESP_OK)
- {
- #ifdef DEBUG_DETAIL_ON
- ESP_LOGD(TAG, "all is found%s", _size);
- #endif
- _all = true;
- }
- if (httpd_query_key_value(_query, "type", _size, 10) == ESP_OK)
- {
- #ifdef DEBUG_DETAIL_ON
- ESP_LOGD(TAG, "all is found: %s", _size);
- #endif
- _type = std::string(_size);
- }
- if (httpd_query_key_value(_query, "rawvalue", _size, 10) == ESP_OK)
- {
- #ifdef DEBUG_DETAIL_ON
- ESP_LOGD(TAG, "rawvalue is found: %s", _size);
- #endif
- _rawValue = true;
- }
- if (httpd_query_key_value(_query, "noerror", _size, 10) == ESP_OK)
- {
- #ifdef DEBUG_DETAIL_ON
- ESP_LOGD(TAG, "noerror is found: %s", _size);
- #endif
- _noerror = true;
- }
- }
- httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*");
- if (_all)
- {
- httpd_resp_set_type(req, "text/plain");
- ESP_LOGD(TAG, "TYPE: %s", _type.c_str());
- int _intype = READOUT_TYPE_VALUE;
- if (_type == "prevalue")
- {
- _intype = READOUT_TYPE_PREVALUE;
- }
- if (_type == "raw")
- {
- _intype = READOUT_TYPE_RAWVALUE;
- }
- if (_type == "error")
- {
- _intype = READOUT_TYPE_ERROR;
- }
- zw = flowctrl.getReadoutAll(_intype);
- ESP_LOGD(TAG, "ZW: %s", zw.c_str());
- if (zw.length() > 0)
- {
- httpd_resp_send(req, zw.c_str(), zw.length());
- }
- return ESP_OK;
- }
- std::string status = flowctrl.getActStatus();
- std::string query = std::string(_query);
- // ESP_LOGD(TAG, "Query: %s, query.c_str());
- if (query.find("full") != std::string::npos)
- {
- std::string txt;
- txt = "<body style=\"font-family: arial\">";
- if ((countRounds <= 1) && (status != std::string("Flow finished")))
- {
- // First round not completed yet
- txt += "<h3>Please wait for the first round to complete!</h3><h3>Current state: " + status + "</h3>\n";
- }
- else
- {
- txt += "<h3>Value</h3>";
- }
- httpd_resp_sendstr_chunk(req, txt.c_str());
- }
- zw = flowctrl.getReadout(_rawValue, _noerror, 0);
- if (zw.length() > 0)
- {
- httpd_resp_sendstr_chunk(req, zw.c_str());
- }
- if (query.find("full") != std::string::npos)
- {
- std::string txt, zw;
- if ((countRounds <= 1) && (status != std::string("Flow finished")))
- {
- // First round not completed yet
- // Nothing to do
- }
- else
- {
- /* Digit ROIs */
- txt = "<body style=\"font-family: arial\">";
- txt += "<hr><h3>Recognized Digit ROIs (previous round)</h3>\n";
- txt += "<table style=\"border-spacing: 5px\"><tr style=\"text-align: center; vertical-align: top;\">\n";
- std::vector<HTMLInfo *> htmlinfodig;
- htmlinfodig = flowctrl.GetAllDigit();
- for (int i = 0; i < htmlinfodig.size(); ++i)
- {
- if (flowctrl.GetTypeDigit() == Digit)
- {
- // Numbers greater than 10 and less than 0 indicate NaN, since a Roi can only have values from 0 to 9.
- if ((htmlinfodig[i]->val >= 10) || (htmlinfodig[i]->val < 0))
- {
- zw = "NaN";
- }
- else
- {
- zw = std::to_string((int)htmlinfodig[i]->val);
- }
- txt += "<td style=\"width: 100px\"><h4>" + zw + "</h4><p><img src=\"/img_tmp/" + htmlinfodig[i]->filename + "\"></p></td>\n";
- }
- else
- {
- std::stringstream stream;
- stream << std::fixed << std::setprecision(1) << htmlinfodig[i]->val;
- zw = stream.str();
- // Numbers greater than 10 and less than 0 indicate NaN, since a Roi can only have values from 0 to 9.
- if ((std::stod(zw) >= 10) || (std::stod(zw) < 0))
- {
- zw = "NaN";
- }
- txt += "<td style=\"width: 100px\"><h4>" + zw + "</h4><p><img src=\"/img_tmp/" + htmlinfodig[i]->filename + "\"></p></td>\n";
- }
- delete htmlinfodig[i];
- }
- htmlinfodig.clear();
- txt += "</tr></table>\n";
- httpd_resp_sendstr_chunk(req, txt.c_str());
- /* Analog ROIs */
- txt = "<hr><h3>Recognized Analog ROIs (previous round)</h3>\n";
- txt += "<table style=\"border-spacing: 5px\"><tr style=\"text-align: center; vertical-align: top;\">\n";
- std::vector<HTMLInfo *> htmlinfoana;
- htmlinfoana = flowctrl.GetAllAnalog();
- for (int i = 0; i < htmlinfoana.size(); ++i)
- {
- std::stringstream stream;
- stream << std::fixed << std::setprecision(1) << htmlinfoana[i]->val;
- zw = stream.str();
-
- // Numbers greater than 10 and less than 0 indicate NaN, since a Roi can only have values from 0 to 9.
- if ((std::stod(zw) >= 10) || (std::stod(zw) < 0))
- {
- zw = "NaN";
- }
- txt += "<td style=\"width: 150px;\"><h4>" + zw + "</h4><p><img src=\"/img_tmp/" + htmlinfoana[i]->filename + "\"></p></td>\n";
- delete htmlinfoana[i];
- }
- htmlinfoana.clear();
- txt += "</tr>\n</table>\n";
- httpd_resp_sendstr_chunk(req, txt.c_str());
- /* Full Image
- * Only show it after the image got taken */
- txt = "<hr><h3>Full Image (current round)</h3>\n";
- if ((status == std::string("Initialization")) ||
- (status == std::string("Initialization (delayed)")) ||
- (status == std::string("Take Image")))
- {
- txt += "<p>Current state: " + status + "</p>\n";
- }
- else
- {
- txt += "<img src=\"/img_tmp/alg_roi.jpg\">\n";
- }
- httpd_resp_sendstr_chunk(req, txt.c_str());
- }
- }
- /* Respond with an empty chunk to signal HTTP response completion */
- httpd_resp_sendstr_chunk(req, NULL);
- }
- else
- {
- httpd_resp_send_err(req, HTTPD_403_FORBIDDEN, "Flow not (yet) started: REST API /value not available!");
- return ESP_ERR_NOT_FOUND;
- }
- #ifdef DEBUG_DETAIL_ON
- LogFile.WriteHeapInfo("handler_wasserzaehler - Done");
- #endif
- return ESP_OK;
- }
- esp_err_t handler_editflow(httpd_req_t *req)
- {
- #ifdef DEBUG_DETAIL_ON
- LogFile.WriteHeapInfo("handler_editflow - Start");
- #endif
- ESP_LOGD(TAG, "handler_editflow uri: %s", req->uri);
- char _query[512] = ""; // stays empty when the request has no query string
- char _valuechar[30];
- std::string _task;
- if (httpd_req_get_url_query_str(req, _query, 512) == ESP_OK)
- {
- if (httpd_query_key_value(_query, "task", _valuechar, 30) == ESP_OK)
- {
- #ifdef DEBUG_DETAIL_ON
- ESP_LOGD(TAG, "task is found: %s", _valuechar);
- #endif
- _task = std::string(_valuechar);
- }
- }
- if (_task.compare("namenumbers") == 0)
- {
- ESP_LOGD(TAG, "Get NUMBER list");
- return get_numbers_file_handler(req);
- }
- if (_task.compare("data") == 0)
- {
- ESP_LOGD(TAG, "Get data list");
- return get_data_file_handler(req);
- }
- if (_task.compare("tflite") == 0)
- {
- ESP_LOGD(TAG, "Get tflite list");
- return get_tflite_file_handler(req);
- }
- if (_task.compare("copy") == 0)
- {
- std::string in, out, zw;
- httpd_query_key_value(_query, "in", _valuechar, 30);
- in = std::string(_valuechar);
- httpd_query_key_value(_query, "out", _valuechar, 30);
- out = std::string(_valuechar);
- #ifdef DEBUG_DETAIL_ON
- ESP_LOGD(TAG, "in: %s", in.c_str());
- ESP_LOGD(TAG, "out: %s", out.c_str());
- #endif
- in = "/sdcard" + in;
- out = "/sdcard" + out;
- CopyFile(in, out);
- zw = "Copy Done";
- httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*");
- httpd_resp_send(req, zw.c_str(), zw.length());
- }
- if (_task.compare("cutref") == 0)
- {
- std::string in, out, zw;
- int x = 0, y = 0, dx = 20, dy = 20;
- bool enhance = false;
- httpd_query_key_value(_query, "in", _valuechar, 30);
- in = std::string(_valuechar);
- httpd_query_key_value(_query, "out", _valuechar, 30);
- out = std::string(_valuechar);
- httpd_query_key_value(_query, "x", _valuechar, 30);
- std::string _x = std::string(_valuechar);
- if (isStringNumeric(_x))
- {
- x = std::stoi(_x);
- }
- httpd_query_key_value(_query, "y", _valuechar, 30);
- std::string _y = std::string(_valuechar);
- if (isStringNumeric(_y))
- {
- y = std::stoi(_y);
- }
- httpd_query_key_value(_query, "dx", _valuechar, 30);
- std::string _dx = std::string(_valuechar);
- if (isStringNumeric(_dx))
- {
- dx = std::stoi(_dx);
- }
- httpd_query_key_value(_query, "dy", _valuechar, 30);
- std::string _dy = std::string(_valuechar);
- if (isStringNumeric(_dy))
- {
- dy = std::stoi(_dy);
- }
- #ifdef DEBUG_DETAIL_ON
- ESP_LOGD(TAG, "in: %s", in.c_str());
- ESP_LOGD(TAG, "out: %s", out.c_str());
- ESP_LOGD(TAG, "x: %s", _x.c_str());
- ESP_LOGD(TAG, "y: %s", _y.c_str());
- ESP_LOGD(TAG, "dx: %s", _dx.c_str());
- ESP_LOGD(TAG, "dy: %s", _dy.c_str());
- #endif
- if (httpd_query_key_value(_query, "enhance", _valuechar, 10) == ESP_OK)
- {
- string _enhance = std::string(_valuechar);
- if (_enhance.compare("true") == 0)
- {
- enhance = true;
- }
- }
- in = "/sdcard" + in;
- out = "/sdcard" + out;
- std::string out2 = out.substr(0, out.length() - 4) + "_org.jpg";
- if ((flowctrl.SetupModeActive || IsFlowPaused() || (flowctrl.getActStatus() == std::string("Flow finished"))) && psram_init_shared_memory_for_take_image_step())
- {
- LogFile.WriteToFile(ESP_LOG_INFO, TAG, "Taking image for Alignment Mark Update...");
- bool operationOk = false;
- CAlignAndCutImage *caic = new (std::nothrow) CAlignAndCutImage("cutref", in);
- if (caic != NULL) {
- caic->CutAndSave(out2, x, y, dx, dy);
- delete caic;
- CImageBasis *cim = new (std::nothrow) CImageBasis("cutref", out2);
- if (cim != NULL && cim->ImageOkay()) {
- if (enhance) cim->Contrast(90);
- cim->SaveToFile(out);
- operationOk = true;
- }
- delete cim;
- }
- if (operationOk) zw = "CutImage Done";
- else {
- LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "Alignment mark update failed due to an allocation or image I/O error");
- zw = "CutImage Failed";
- }
- // Release only after every STBI-backed temporary image has been destroyed.
- psram_deinit_shared_memory_for_take_image_step();
- }
- else
- {
- LogFile.WriteToFile(ESP_LOG_WARN, TAG, std::string("Taking image for Alignment Mark not possible while device") + " is busy with a round (Current State: '" + flowctrl.getActStatus() + "')!");
- zw = "Device Busy";
- }
- httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*");
- httpd_resp_send(req, zw.c_str(), zw.length());
- }
- // wird beim Erstellen eines neuen Referenzbildes aufgerufen
- std::string sys_status = flowctrl.getActStatus();
- if ((sys_status != "Take Image") && (sys_status != "Aligning"))
- {
- if ((_task.compare("test_take") == 0) || (_task.compare("cam_settings") == 0))
- {
- std::string _host = "";
- // CFstatus is only used as the temporary settings copy for test_take.
- const bool isTestTake = (_task.compare("test_take") == 0);
- CameraSettings *settingsTarget = &static_cast<CameraSettings &>(CCstatus);
- if (isTestTake)
- {
- static_cast<CameraSettings &>(CFstatus) =
- static_cast<const CameraSettings &>(CCstatus);
- settingsTarget = &static_cast<CameraSettings &>(CFstatus);
- }
- CameraSettings &settings = *settingsTarget;
- if (httpd_query_key_value(_query, "host", _valuechar, 30) == ESP_OK)
- {
- _host = std::string(_valuechar);
- }
- if (httpd_query_key_value(_query, "xclk", _valuechar, 30) == ESP_OK)
- {
- std::string _xclk = std::string(_valuechar);
- if (isStringNumeric(_xclk))
- {
- settings.CamXclkFreqMhz = clipInt(std::stoi(_xclk), 20, 1);
- }
- }
- if (httpd_query_key_value(_query, "waitb", _valuechar, 30) == ESP_OK)
- {
- std::string _waitb = std::string(_valuechar);
- if (isStringNumeric(_waitb))
- {
- settings.WaitBeforePicture = std::max(0, std::stoi(_valuechar));
- }
- }
- if (httpd_query_key_value(_query, "aecgc", _valuechar, 30) == ESP_OK)
- {
- std::string _aecgc = std::string(_valuechar);
- if (isStringNumeric(_aecgc))
- {
- int _aecgc_ = std::stoi(_valuechar);
- switch (_aecgc_)
- {
- case 1:
- settings.ImageGainceiling = GAINCEILING_4X;
- break;
- case 2:
- settings.ImageGainceiling = GAINCEILING_8X;
- break;
- case 3:
- settings.ImageGainceiling = GAINCEILING_16X;
- break;
- case 4:
- settings.ImageGainceiling = GAINCEILING_32X;
- break;
- case 5:
- settings.ImageGainceiling = GAINCEILING_64X;
- break;
- case 6:
- settings.ImageGainceiling = GAINCEILING_128X;
- break;
- default:
- settings.ImageGainceiling = GAINCEILING_2X;
- }
- }
- else
- {
- if (_aecgc == "X4") {
- settings.ImageGainceiling = GAINCEILING_4X;
- }
- else if (_aecgc == "X8") {
- settings.ImageGainceiling = GAINCEILING_8X;
- }
- else if (_aecgc == "X16") {
- settings.ImageGainceiling = GAINCEILING_16X;
- }
- else if (_aecgc == "X32") {
- settings.ImageGainceiling = GAINCEILING_32X;
- }
- else if (_aecgc == "X64") {
- settings.ImageGainceiling = GAINCEILING_64X;
- }
- else if (_aecgc == "X128") {
- settings.ImageGainceiling = GAINCEILING_128X;
- }
- else {
- settings.ImageGainceiling = GAINCEILING_2X;
- }
- }
- }
- if (httpd_query_key_value(_query, "qual", _valuechar, 30) == ESP_OK)
- {
- std::string _qual = std::string(_valuechar);
- if (isStringNumeric(_qual))
- {
- int _qual_ = std::stoi(_valuechar);
- settings.ImageQuality = clipInt(_qual_, 63, 6);
- }
- }
- if (httpd_query_key_value(_query, "bri", _valuechar, 30) == ESP_OK)
- {
- std::string _bri = std::string(_valuechar);
- if (isStringNumeric(_bri))
- {
- int _bri_ = std::stoi(_valuechar);
- settings.ImageBrightness = clipInt(_bri_, 2, -2);
- }
- }
- if (httpd_query_key_value(_query, "con", _valuechar, 30) == ESP_OK)
- {
- std::string _con = std::string(_valuechar);
- if (isStringNumeric(_con))
- {
- int _con_ = std::stoi(_valuechar);
- settings.ImageContrast = clipInt(_con_, 2, -2);
- }
- }
- if (httpd_query_key_value(_query, "sat", _valuechar, 30) == ESP_OK)
- {
- std::string _sat = std::string(_valuechar);
- if (isStringNumeric(_sat))
- {
- int _sat_ = std::stoi(_valuechar);
- settings.ImageSaturation = clipInt(_sat_, 2, -2);
- }
- }
- if (httpd_query_key_value(_query, "shp", _valuechar, 30) == ESP_OK)
- {
- std::string _shp = std::string(_valuechar);
- if (isStringNumeric(_shp))
- {
- int _shp_ = std::stoi(_valuechar);
- if (CCstatus.CamSensor_id == OV2640_PID)
- {
- settings.ImageSharpness = clipInt(_shp_, 2, -2);
- }
- else
- {
- settings.ImageSharpness = clipInt(_shp_, 3, -3);
- }
- }
- }
- if (httpd_query_key_value(_query, "ashp", _valuechar, 30) == ESP_OK)
- {
- std::string _ashp = std::string(_valuechar);
- settings.ImageAutoSharpness = alphanumericToBoolean(_ashp);
- }
- if (httpd_query_key_value(_query, "spe", _valuechar, 30) == ESP_OK)
- {
- std::string _spe = std::string(_valuechar);
- if (isStringNumeric(_spe))
- {
- int _spe_ = std::stoi(_valuechar);
- settings.ImageSpecialEffect = clipInt(_spe_, 6, 0);
- }
- else
- {
- if (_spe == "negative") {
- settings.ImageSpecialEffect = 1;
- }
- else if (_spe == "grayscale") {
- settings.ImageSpecialEffect = 2;
- }
- else if (_spe == "red") {
- settings.ImageSpecialEffect = 3;
- }
- else if (_spe == "green") {
- settings.ImageSpecialEffect = 4;
- }
- else if (_spe == "blue") {
- settings.ImageSpecialEffect = 5;
- }
- else if (_spe == "retro") {
- settings.ImageSpecialEffect = 6;
- }
- else {
- settings.ImageSpecialEffect = 0;
- }
- }
- }
- if (httpd_query_key_value(_query, "wbm", _valuechar, 30) == ESP_OK)
- {
- std::string _wbm = std::string(_valuechar);
- if (isStringNumeric(_wbm))
- {
- int _wbm_ = std::stoi(_valuechar);
- settings.ImageWbMode = clipInt(_wbm_, 4, 0);
- }
- else
- {
- if (_wbm == "sunny") {
- settings.ImageWbMode = 1;
- }
- else if (_wbm == "cloudy") {
- settings.ImageWbMode = 2;
- }
- else if (_wbm == "office") {
- settings.ImageWbMode = 3;
- }
- else if (_wbm == "home") {
- settings.ImageWbMode = 4;
- }
- else {
- settings.ImageWbMode = 0;
- }
- }
- }
- if (httpd_query_key_value(_query, "awb", _valuechar, 30) == ESP_OK)
- {
- std::string _awb = std::string(_valuechar);
- settings.ImageAwb = alphanumericToBoolean(_awb);
- }
- if (httpd_query_key_value(_query, "awbg", _valuechar, 30) == ESP_OK)
- {
- std::string _awbg = std::string(_valuechar);
- settings.ImageAwbGain = alphanumericToBoolean(_awbg);
- }
- if (httpd_query_key_value(_query, "aec", _valuechar, 30) == ESP_OK)
- {
- std::string _aec = std::string(_valuechar);
- settings.ImageAec = alphanumericToBoolean(_aec);
- }
- if (httpd_query_key_value(_query, "aec2", _valuechar, 30) == ESP_OK)
- {
- std::string _aec2 = std::string(_valuechar);
- settings.ImageAec2 = alphanumericToBoolean(_aec2);
- }
- if (httpd_query_key_value(_query, "ael", _valuechar, 30) == ESP_OK)
- {
- std::string _ael = std::string(_valuechar);
- if (isStringNumeric(_ael))
- {
- int _ael_ = std::stoi(_valuechar);
- if (CCstatus.CamSensor_id == OV2640_PID)
- {
- settings.ImageAeLevel = clipInt(_ael_, 2, -2);
- }
- else
- {
- settings.ImageAeLevel = clipInt(_ael_, 5, -5);
- }
- }
- }
- if (httpd_query_key_value(_query, "aecv", _valuechar, 30) == ESP_OK)
- {
- std::string _aecv = std::string(_valuechar);
- if (isStringNumeric(_aecv))
- {
- int _aecv_ = std::stoi(_valuechar);
- settings.ImageAecValue = clipInt(_aecv_, 1200, 0);
- }
- }
- if (httpd_query_key_value(_query, "agc", _valuechar, 30) == ESP_OK)
- {
- std::string _agc = std::string(_valuechar);
- settings.ImageAgc = alphanumericToBoolean(_agc);
- }
- if (httpd_query_key_value(_query, "agcg", _valuechar, 30) == ESP_OK)
- {
- std::string _agcg = std::string(_valuechar);
- if (isStringNumeric(_agcg))
- {
- int _agcg_ = std::stoi(_valuechar);
- settings.ImageAgcGain = clipInt(_agcg_, 30, 0);
- }
- }
- if (httpd_query_key_value(_query, "bpc", _valuechar, 30) == ESP_OK)
- {
- std::string _bpc = std::string(_valuechar);
- settings.ImageBpc = alphanumericToBoolean(_bpc);
- }
- if (httpd_query_key_value(_query, "wpc", _valuechar, 30) == ESP_OK)
- {
- std::string _wpc = std::string(_valuechar);
- settings.ImageWpc = alphanumericToBoolean(_wpc);
- }
- if (httpd_query_key_value(_query, "rgma", _valuechar, 30) == ESP_OK)
- {
- std::string _rgma = std::string(_valuechar);
- settings.ImageRawGma = alphanumericToBoolean(_rgma);
- }
- if (httpd_query_key_value(_query, "lenc", _valuechar, 30) == ESP_OK)
- {
- std::string _lenc = std::string(_valuechar);
- settings.ImageLenc = alphanumericToBoolean(_lenc);
- }
- if (httpd_query_key_value(_query, "mirror", _valuechar, 30) == ESP_OK)
- {
- std::string _mirror = std::string(_valuechar);
- settings.ImageHmirror = alphanumericToBoolean(_mirror);
- }
- if (httpd_query_key_value(_query, "flip", _valuechar, 30) == ESP_OK)
- {
- std::string _flip = std::string(_valuechar);
- settings.ImageVflip = alphanumericToBoolean(_flip);
- }
- if (httpd_query_key_value(_query, "dcw", _valuechar, 30) == ESP_OK)
- {
- std::string _dcw = std::string(_valuechar);
- settings.ImageDcw = alphanumericToBoolean(_dcw);
- }
- if (httpd_query_key_value(_query, "den", _valuechar, 30) == ESP_OK)
- {
- std::string _idlv = std::string(_valuechar);
- if (isStringNumeric(_idlv))
- {
- int _ImageDenoiseLevel = std::stoi(_valuechar);
- if (CCstatus.CamSensor_id == OV2640_PID)
- {
- settings.ImageDenoiseLevel = 0;
- }
- else
- {
- settings.ImageDenoiseLevel = clipInt(_ImageDenoiseLevel, 8, 0);
- }
- }
- }
- if (httpd_query_key_value(_query, "zoom", _valuechar, 30) == ESP_OK)
- {
- std::string _zoom = std::string(_valuechar);
- settings.ImageZoomEnabled = alphanumericToBoolean(_zoom);
- }
- if (httpd_query_key_value(_query, "zoomx", _valuechar, 30) == ESP_OK)
- {
- std::string _zoomx = std::string(_valuechar);
- if (isStringNumeric(_zoomx))
- {
- int _ImageZoomOffsetX = std::stoi(_valuechar);
- if (CCstatus.CamSensor_id == OV2640_PID)
- {
- settings.ImageZoomOffsetX = clipInt(_ImageZoomOffsetX, 480, -480);
- }
- else if (CCstatus.CamSensor_id == OV3660_PID)
- {
- settings.ImageZoomOffsetX = clipInt(_ImageZoomOffsetX, 704, -704);
- }
- else if (CCstatus.CamSensor_id == OV5640_PID)
- {
- settings.ImageZoomOffsetX = clipInt(_ImageZoomOffsetX, 960, -960);
- }
- }
- }
- if (httpd_query_key_value(_query, "zoomy", _valuechar, 30) == ESP_OK)
- {
- std::string _zoomy = std::string(_valuechar);
- if (isStringNumeric(_zoomy))
- {
- int _ImageZoomOffsetY = std::stoi(_valuechar);
- if (CCstatus.CamSensor_id == OV2640_PID)
- {
- settings.ImageZoomOffsetY = clipInt(_ImageZoomOffsetY, 360, -360);
- }
- else if (CCstatus.CamSensor_id == OV3660_PID)
- {
- settings.ImageZoomOffsetY = clipInt(_ImageZoomOffsetY, 528, -528);
- }
- else if (CCstatus.CamSensor_id == OV5640_PID)
- {
- settings.ImageZoomOffsetY = clipInt(_ImageZoomOffsetY, 720, -720);
- }
- }
- }
- if (httpd_query_key_value(_query, "zooms", _valuechar, 30) == ESP_OK)
- {
- std::string _zooms = std::string(_valuechar);
- if (isStringNumeric(_zooms))
- {
- int _ImageZoomSize = std::stoi(_valuechar);
- if (CCstatus.CamSensor_id == OV2640_PID)
- {
- settings.ImageZoomSize = clipInt(_ImageZoomSize, 29, 0);
- }
- else if (CCstatus.CamSensor_id == OV3660_PID)
- {
- settings.ImageZoomSize = clipInt(_ImageZoomSize, 43, 0);
- }
- else if (CCstatus.CamSensor_id == OV5640_PID)
- {
- settings.ImageZoomSize = clipInt(_ImageZoomSize, 59, 0);
- }
- }
- }
- if (httpd_query_key_value(_query, "ledi", _valuechar, 30) == ESP_OK)
- {
- std::string _ledi = std::string(_valuechar);
- if (isStringNumeric(_ledi))
- {
- int _ImageLedIntensity = std::stoi(_valuechar);
- settings.ImageLedIntensity = Camera.SetLEDIntensity(_ImageLedIntensity);
- }
- }
- if (!isTestTake)
- {
- // Saved camera settings are committed in CCstatus.
- if (Camera.setSensorDatenFromCCstatus() != ESP_OK)
- {
- httpd_resp_send_err(req, HTTPD_500_INTERNAL_SERVER_ERROR, "Could not apply committed camera settings");
- return ESP_FAIL;
- }
- ESP_LOGD(TAG, "Cam Settings set");
- std::string _zw = "CamSettingsSet";
- httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*");
- httpd_resp_send(req, _zw.c_str(), _zw.length());
- }
- else
- {
- // Only test_take applies temporary camera settings.
- if (Camera.ApplyPreviewSettings(settings) != ESP_OK)
- {
- httpd_resp_send_err(req, HTTPD_500_INTERNAL_SERVER_ERROR, "Could not apply temporary camera settings");
- return ESP_FAIL;
- }
- ESP_LOGD(TAG, "test_take - vor TakeImage");
- std::string image_temp = flowctrl.doSingleStep("[TakeImage]", _host);
- const std::string rawImagePath = "/img_tmp/raw.jpg";
- const std::size_t rawImagePosition = image_temp.find(rawImagePath);
- if (rawImagePosition != std::string::npos)
- {
- image_temp.replace(rawImagePosition, rawImagePath.length(),
- rawImagePath + "?preview=1");
- }
- httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*");
- httpd_resp_send(req, image_temp.c_str(), image_temp.length());
- }
- }
- if (_task.compare("test_align") == 0)
- {
- std::string _host = "";
- if (httpd_query_key_value(_query, "host", _valuechar, 30) == ESP_OK)
- {
- _host = std::string(_valuechar);
- }
- std::string zw = flowctrl.doSingleStep("[Alignment]", _host);
- httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*");
- httpd_resp_send(req, zw.c_str(), zw.length());
- }
- }
- else
- {
- std::string _zw = "DeviceIsBusy";
- httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*");
- httpd_resp_send(req, _zw.c_str(), _zw.length());
- }
- #ifdef DEBUG_DETAIL_ON
- LogFile.WriteHeapInfo("handler_editflow - Done");
- #endif
- return ESP_OK;
- }
- esp_err_t handler_statusflow(httpd_req_t *req)
- {
- #ifdef DEBUG_DETAIL_ON
- LogFile.WriteHeapInfo("handler_statusflow - Start");
- #endif
- const char *resp_str;
- httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*");
- if (bTaskAutoFlowCreated)
- {
- #ifdef DEBUG_DETAIL_ON
- ESP_LOGD(TAG, "handler_statusflow: %s", req->uri);
- #endif
- std::string zw = flowctrl.getActStatusWithTime();
- resp_str = zw.c_str();
- httpd_resp_send(req, resp_str, HTTPD_RESP_USE_STRLEN);
- }
- else
- {
- resp_str = "Flow task not yet created";
- httpd_resp_send(req, resp_str, HTTPD_RESP_USE_STRLEN);
- }
- #ifdef DEBUG_DETAIL_ON
- LogFile.WriteHeapInfo("handler_statusflow - Done");
- #endif
- return ESP_OK;
- }
- esp_err_t handler_cputemp(httpd_req_t *req)
- {
- #ifdef DEBUG_DETAIL_ON
- LogFile.WriteHeapInfo("handler_cputemp - Start");
- #endif
- httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*");
- httpd_resp_send(req, std::to_string((int)temperatureRead()).c_str(), HTTPD_RESP_USE_STRLEN);
- #ifdef DEBUG_DETAIL_ON
- LogFile.WriteHeapInfo("handler_cputemp - End");
- #endif
- return ESP_OK;
- }
- esp_err_t handler_rssi(httpd_req_t *req)
- {
- #ifdef DEBUG_DETAIL_ON
- LogFile.WriteHeapInfo("handler_rssi - Start");
- #endif
- if (getWIFIisConnected())
- {
- httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*");
- httpd_resp_send(req, std::to_string(get_WIFI_RSSI()).c_str(), HTTPD_RESP_USE_STRLEN);
- }
- else
- {
- httpd_resp_send_err(req, HTTPD_403_FORBIDDEN, "WIFI not (yet) connected: REST API /rssi not available!");
- return ESP_ERR_NOT_FOUND;
- }
- #ifdef DEBUG_DETAIL_ON
- LogFile.WriteHeapInfo("handler_rssi - End");
- #endif
- return ESP_OK;
- }
- esp_err_t handler_current_date(httpd_req_t *req)
- {
- #ifdef DEBUG_DETAIL_ON
- LogFile.WriteHeapInfo("handler_uptime - Start");
- #endif
- std::string formatedDateAndTime = getCurrentTimeString("%Y-%m-%d %H:%M:%S");
- // std::string formatedDate = getCurrentTimeString("%Y-%m-%d");
- httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*");
- httpd_resp_send(req, formatedDateAndTime.c_str(), formatedDateAndTime.length());
- #ifdef DEBUG_DETAIL_ON
- LogFile.WriteHeapInfo("handler_uptime - End");
- #endif
- return ESP_OK;
- }
- esp_err_t handler_uptime(httpd_req_t *req)
- {
- #ifdef DEBUG_DETAIL_ON
- LogFile.WriteHeapInfo("handler_uptime - Start");
- #endif
- std::string formatedUptime = getFormatedUptime(false);
- httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*");
- httpd_resp_send(req, formatedUptime.c_str(), formatedUptime.length());
- #ifdef DEBUG_DETAIL_ON
- LogFile.WriteHeapInfo("handler_uptime - End");
- #endif
- return ESP_OK;
- }
- esp_err_t handler_prevalue(httpd_req_t *req)
- {
- #ifdef DEBUG_DETAIL_ON
- LogFile.WriteHeapInfo("handler_prevalue - Start");
- ESP_LOGD(TAG, "handler_prevalue: %s", req->uri);
- #endif
- // Default usage message when handler gets called without any parameter
- const std::string RESTUsageInfo =
- "00: Handler usage:<br>"
- "- To retrieve actual PreValue, please provide only a numbersname, e.g. /setPreValue?numbers=main<br>"
- "- To set PreValue to a new value, please provide a numbersname and a value, e.g. /setPreValue?numbers=main&value=1234.5678<br>"
- "NOTE:<br>"
- "value >= 0.0: Set PreValue to provided value<br>"
- "value < 0.0: Set PreValue to actual RAW value (as long RAW value is a valid number, without N)";
- // Default return error message when no return is programmed
- std::string sReturnMessage = "E90: Uninitialized";
- char _query[100] = ""; // stays empty when the request has no query string
- char _numbersname[50] = "default";
- char _value[20] = "";
- httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*");
- if (httpd_req_get_url_query_str(req, _query, 100) == ESP_OK)
- {
- #ifdef DEBUG_DETAIL_ON
- ESP_LOGD(TAG, "Query: %s", _query);
- #endif
- if (httpd_query_key_value(_query, "numbers", _numbersname, 50) != ESP_OK)
- {
- // If request is incomplete
- sReturnMessage = "E91: Query parameter incomplete or not valid!<br> "
- "Call /setPreValue to show REST API usage info and/or check documentation";
- httpd_resp_send(req, sReturnMessage.c_str(), sReturnMessage.length());
- return ESP_FAIL;
- }
- if (httpd_query_key_value(_query, "value", _value, 20) == ESP_OK)
- {
- #ifdef DEBUG_DETAIL_ON
- ESP_LOGD(TAG, "Value: %s", _value);
- #endif
- }
- }
- else
- {
- // if no parameter is provided, print handler usage
- httpd_resp_send(req, RESTUsageInfo.c_str(), RESTUsageInfo.length());
- return ESP_OK;
- }
- if (strlen(_value) == 0)
- {
- // If no value is povided --> return actual PreValue
- sReturnMessage = flowctrl.GetPrevalue(std::string(_numbersname));
- if (sReturnMessage.empty())
- {
- sReturnMessage = "E92: Numbers name not found";
- httpd_resp_send(req, sReturnMessage.c_str(), sReturnMessage.length());
- return ESP_FAIL;
- }
- }
- else
- {
- // New value is positive: Set PreValue to provided value and return value
- // New value is negative and actual RAW value is a valid number: Set PreValue to RAW value and return value
- LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "REST API handler_prevalue called: numbersname: " + std::string(_numbersname) + ", value: " + std::string(_value));
- if (!flowctrl.UpdatePrevalue(_value, _numbersname, true))
- {
- sReturnMessage = "E93: Update request rejected. Please check device logs for more details";
- httpd_resp_send(req, sReturnMessage.c_str(), sReturnMessage.length());
- return ESP_FAIL;
- }
- sReturnMessage = flowctrl.GetPrevalue(std::string(_numbersname));
- if (sReturnMessage.empty())
- {
- sReturnMessage = "E94: Numbers name not found";
- httpd_resp_send(req, sReturnMessage.c_str(), sReturnMessage.length());
- return ESP_FAIL;
- }
- }
- httpd_resp_send(req, sReturnMessage.c_str(), sReturnMessage.length());
- #ifdef DEBUG_DETAIL_ON
- LogFile.WriteHeapInfo("handler_prevalue - End");
- #endif
- return ESP_OK;
- }
- void task_autodoFlow(void *pvParameter)
- {
- int64_t fr_start, fr_delta_ms;
- bTaskAutoFlowCreated = true;
- if (!isPlannedReboot && (esp_reset_reason() == ESP_RST_PANIC))
- {
- flowctrl.setActStatus("Initialization (delayed)");
- // #ifdef ENABLE_MQTT
- // MQTTPublish(mqttServer_getMainTopic() + "/" + "status", "Initialization (delayed)", false); // Right now, not possible -> MQTT Service is going to be started later
- // #endif //ENABLE_MQTT
- vTaskDelay(60 * 5000 / portTICK_PERIOD_MS); // Wait 5 minutes to give time to do an OTA update or fetch the log
- }
- ESP_LOGD(TAG, "task_autodoFlow: start");
- doInit();
- flowctrl.setAutoStartInterval(auto_interval);
- autostartIsEnabled = flowctrl.getIsAutoStart();
- if (isSetupModusActive())
- {
- LogFile.WriteToFile(ESP_LOG_INFO, TAG, "We are in Setup Mode -> Not starting Auto Flow!");
- autostartIsEnabled = false;
- // 15.7.0 Setup Wizard cannot take a Reference Picture #2953
- // std::string zw_time = getCurrentTimeString(LOGFILE_TIME_FORMAT);
- // flowctrl.doFlowTakeImageOnly(zw_time);
- }
- if (autostartIsEnabled)
- {
- LogFile.WriteToFile(ESP_LOG_INFO, TAG, "Starting Flow...");
- }
- else
- {
- LogFile.WriteToFile(ESP_LOG_INFO, TAG, "Autostart is not enabled -> Not starting Flow");
- }
- while (autostartIsEnabled)
- {
- if (UpdateFlowPauseStateForTask())
- {
- if (flowctrl.getActStatus() != "Flow paused")
- {
- flowctrl.setActStatus("Flow paused");
- LogFile.WriteToFile(ESP_LOG_INFO, TAG, "Flow paused; waiting for resume or one manual round");
- }
- vTaskDelay(pdMS_TO_TICKS(250));
- continue;
- }
- LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "----------------------------------------------------------------"); // Clear separation between runs
- time_t roundStartTime = getUpTime();
- std::string _zw = "Round #" + std::to_string(++countRounds) + " started";
- LogFile.WriteToFile(ESP_LOG_INFO, TAG, _zw);
- fr_start = esp_timer_get_time();
- if (IsFlowRunning())
- {
- #ifdef DEBUG_DETAIL_ON
- ESP_LOGD(TAG, "Autoflow: doFlow is already running!");
- #endif
- }
- else
- {
- #ifdef DEBUG_DETAIL_ON
- ESP_LOGD(TAG, "Autoflow: doFlow is started");
- #endif
- doflow();
- #ifdef DEBUG_DETAIL_ON
- ESP_LOGD(TAG, "Remove older log files");
- #endif
- LogFile.RemoveOldLogFile();
- LogFile.RemoveOldDataLog();
- }
- // Round finished -> Logfile
- LogFile.WriteToFile(ESP_LOG_INFO, TAG, "Round #" + std::to_string(countRounds) + " completed (" + std::to_string(getUpTime() - roundStartTime) + " seconds)");
- // CPU Temp -> Logfile
- LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "CPU Temperature: " + std::to_string((int)temperatureRead()) + "°C");
- // WIFI Signal Strength (RSSI) -> Logfile
- LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "WIFI Signal (RSSI): " + std::to_string(get_WIFI_RSSI()) + "dBm");
- // Check if time is synchronized (if NTP is configured)
- if (getUseNtp() && !getTimeIsSet())
- {
- LogFile.WriteToFile(ESP_LOG_WARN, TAG, "Time server is configured, but time is not yet set!");
- StatusLED(TIME_CHECK, 1, false);
- }
- #if (defined WLAN_USE_MESH_ROAMING && defined WLAN_USE_MESH_ROAMING_ACTIVATE_CLIENT_TRIGGERED_QUERIES)
- wifiRoamingQuery();
- #endif
- // Scan channels and check if an AP with better RSSI is available, then disconnect and try to reconnect to AP with better RSSI
- // NOTE: Keep this direct before the following task delay, because scan is done in blocking mode and this takes ca. 1,5 - 2s.
- #ifdef WLAN_USE_ROAMING_BY_SCANNING
- wifiRoamByScanning();
- #endif
- fr_delta_ms = (esp_timer_get_time() - fr_start) / 1000;
- if (IsFlowPauseRequested())
- {
- continue; // Finish the current round, then enter the paused state at the top of the loop.
- }
- if (auto_interval > fr_delta_ms)
- {
- const TickType_t xDelay = (auto_interval - fr_delta_ms) / portTICK_PERIOD_MS;
- ESP_LOGD(TAG, "Autoflow: sleep for: %ldms", (long)xDelay);
- vTaskDelay(xDelay);
- }
- }
- while (1)
- {
- // Keep flow task running to handle necessary sub tasks like reboot handler, etc..
- vTaskDelay(2000 / portTICK_PERIOD_MS);
- }
- vTaskDelete(NULL); // Delete this task if it exits from the loop above
- xHandletask_autodoFlow = NULL;
- ESP_LOGD(TAG, "task_autodoFlow: end");
- }
- void InitializeFlowTask(void)
- {
- BaseType_t xReturned;
- ResetFlowControlState();
- ESP_LOGD(TAG, "getESPHeapInfo: %s", getESPHeapInfo().c_str());
- uint32_t stackSize = 16 * 1024;
- xReturned = xTaskCreatePinnedToCore(&task_autodoFlow, "task_autodoFlow", stackSize, NULL, tskIDLE_PRIORITY + 2, &xHandletask_autodoFlow, 0);
- if (xReturned != pdPASS)
- {
- LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "Creation task_autodoFlow failed. Requested stack size:" + std::to_string(stackSize));
- LogFile.WriteHeapInfo("Creation task_autodoFlow failed");
- }
- ESP_LOGD(TAG, "getESPHeapInfo: %s", getESPHeapInfo().c_str());
- }
- void register_server_main_flow_task_uri(httpd_handle_t server)
- {
- ESP_LOGI(TAG, "server_main_flow_task - Registering URI handlers");
- httpd_uri_t camuri = {};
- camuri.method = HTTP_GET;
- camuri.uri = "/doinit";
- camuri.handler = APPLY_BASIC_AUTH_FILTER(handler_init);
- camuri.user_ctx = (void *)"Light On";
- httpd_register_uri_handler(server, &camuri);
- // Legacy API => New: "/setPreValue"
- camuri.uri = "/setPreValue.html";
- camuri.handler = APPLY_BASIC_AUTH_FILTER(handler_prevalue);
- camuri.user_ctx = (void *)"Prevalue";
- httpd_register_uri_handler(server, &camuri);
- camuri.uri = "/setPreValue";
- camuri.handler = APPLY_BASIC_AUTH_FILTER(handler_prevalue);
- camuri.user_ctx = (void *)"Prevalue";
- httpd_register_uri_handler(server, &camuri);
- camuri.uri = "/flow_start";
- camuri.handler = APPLY_BASIC_AUTH_FILTER(handler_flow_start);
- camuri.user_ctx = (void *)"Flow Start";
- httpd_register_uri_handler(server, &camuri);
- camuri.uri = "/flow_pause";
- camuri.handler = APPLY_BASIC_AUTH_FILTER(handler_flow_pause);
- camuri.user_ctx = (void *)"Flow Pause";
- httpd_register_uri_handler(server, &camuri);
- camuri.uri = "/flow_resume";
- camuri.handler = APPLY_BASIC_AUTH_FILTER(handler_flow_resume);
- camuri.user_ctx = (void *)"Flow Resume";
- httpd_register_uri_handler(server, &camuri);
- camuri.uri = "/statusflow.html";
- camuri.handler = APPLY_BASIC_AUTH_FILTER(handler_statusflow);
- camuri.user_ctx = (void *)"Light Off";
- httpd_register_uri_handler(server, &camuri);
- camuri.uri = "/statusflow";
- camuri.handler = APPLY_BASIC_AUTH_FILTER(handler_statusflow);
- camuri.user_ctx = (void *)"Light Off";
- httpd_register_uri_handler(server, &camuri);
- // Legacy API => New: "/cpu_temperature"
- camuri.uri = "/cputemp.html";
- camuri.handler = APPLY_BASIC_AUTH_FILTER(handler_cputemp);
- camuri.user_ctx = (void *)"Light Off";
- httpd_register_uri_handler(server, &camuri);
- camuri.uri = "/cpu_temperature";
- camuri.handler = APPLY_BASIC_AUTH_FILTER(handler_cputemp);
- camuri.user_ctx = (void *)"Light Off";
- httpd_register_uri_handler(server, &camuri);
- // Legacy API => New: "/rssi"
- camuri.uri = "/rssi.html";
- camuri.handler = APPLY_BASIC_AUTH_FILTER(handler_rssi);
- camuri.user_ctx = (void *)"Light Off";
- httpd_register_uri_handler(server, &camuri);
- camuri.uri = "/rssi";
- camuri.handler = APPLY_BASIC_AUTH_FILTER(handler_rssi);
- camuri.user_ctx = (void *)"Light Off";
- httpd_register_uri_handler(server, &camuri);
- camuri.uri = "/date";
- camuri.handler = APPLY_BASIC_AUTH_FILTER(handler_current_date);
- camuri.user_ctx = (void *)"Light Off";
- httpd_register_uri_handler(server, &camuri);
- camuri.uri = "/uptime";
- camuri.handler = APPLY_BASIC_AUTH_FILTER(handler_uptime);
- camuri.user_ctx = (void *)"Light Off";
- httpd_register_uri_handler(server, &camuri);
- camuri.uri = "/editflow";
- camuri.handler = APPLY_BASIC_AUTH_FILTER(handler_editflow);
- camuri.user_ctx = (void *)"EditFlow";
- httpd_register_uri_handler(server, &camuri);
- // Legacy API => New: "/value"
- camuri.uri = "/value.html";
- camuri.handler = APPLY_BASIC_AUTH_FILTER(handler_wasserzaehler);
- camuri.user_ctx = (void *)"Value";
- httpd_register_uri_handler(server, &camuri);
- camuri.uri = "/value";
- camuri.handler = APPLY_BASIC_AUTH_FILTER(handler_wasserzaehler);
- camuri.user_ctx = (void *)"Value";
- httpd_register_uri_handler(server, &camuri);
- // Legacy API => New: "/value"
- camuri.uri = "/wasserzaehler.html";
- camuri.handler = APPLY_BASIC_AUTH_FILTER(handler_wasserzaehler);
- camuri.user_ctx = (void *)"Wasserzaehler";
- httpd_register_uri_handler(server, &camuri);
- camuri.uri = "/json";
- camuri.handler = APPLY_BASIC_AUTH_FILTER(handler_json);
- camuri.user_ctx = (void *)"JSON";
- httpd_register_uri_handler(server, &camuri);
- camuri.uri = "/heap";
- camuri.handler = APPLY_BASIC_AUTH_FILTER(handler_get_heap);
- camuri.user_ctx = (void *)"Heap";
- httpd_register_uri_handler(server, &camuri);
- camuri.uri = "/stream";
- camuri.handler = APPLY_BASIC_AUTH_FILTER(handler_stream);
- camuri.user_ctx = (void *)"stream";
- httpd_register_uri_handler(server, &camuri);
- /** will handle metrics requests */
- camuri.uri = "/metrics";
- camuri.handler = APPLY_BASIC_AUTH_FILTER(handler_openmetrics);
- camuri.user_ctx = (void *)"metrics";
- httpd_register_uri_handler(server, &camuri);
- /** when adding a new handler, make sure to increment the value for config.max_uri_handlers in `main/server_main.cpp` */
- }
|