Rest handler: Use none chunked transfer (#1797)

* Resthandler info,sysinfo,starttime: no chunk trans

* flowstart,statusflow,cputemp,rssi,uptime,prevalue

* Renamed error messages
This commit is contained in:
Slider0007
2023-01-10 19:37:30 +01:00
committed by GitHub
parent 4b38c1ef00
commit eefdc74e9a
3 changed files with 64 additions and 97 deletions

View File

@@ -48,7 +48,7 @@ esp_err_t handler_lightOn(httpd_req_t *req)
} }
else else
{ {
httpd_resp_send_err(req, HTTPD_403_FORBIDDEN, "Camera Light On API not yet initialized. Please retry later..."); httpd_resp_send_err(req, HTTPD_403_FORBIDDEN, "Camera not initialized: REST API /lighton not available!");
return ESP_ERR_NOT_FOUND; return ESP_ERR_NOT_FOUND;
} }
@@ -75,7 +75,7 @@ esp_err_t handler_lightOff(httpd_req_t *req)
} }
else else
{ {
httpd_resp_send_err(req, HTTPD_403_FORBIDDEN, "Camera Light Off API not yet initialized. Please retry later..."); httpd_resp_send_err(req, HTTPD_403_FORBIDDEN, "Camera not initialized: REST API /lightoff not available!");
return ESP_ERR_NOT_FOUND; return ESP_ERR_NOT_FOUND;
} }
@@ -117,7 +117,7 @@ esp_err_t handler_capture(httpd_req_t *req)
} }
else else
{ {
httpd_resp_send_err(req, HTTPD_403_FORBIDDEN, "Camera Capture API not yet initialized. Please retry later..."); httpd_resp_send_err(req, HTTPD_403_FORBIDDEN, "Camera not initialized: REST API /capture not available!");
return ESP_ERR_NOT_FOUND; return ESP_ERR_NOT_FOUND;
} }
} }
@@ -177,7 +177,7 @@ esp_err_t handler_capture_with_ligth(httpd_req_t *req)
} }
else else
{ {
httpd_resp_send_err(req, HTTPD_403_FORBIDDEN, "Camera Capture + flashlight API not yet initialized. Please retry later..."); httpd_resp_send_err(req, HTTPD_403_FORBIDDEN, "Camera not initialized: REST API /capture_with_flashlight not available!");
return ESP_ERR_NOT_FOUND; return ESP_ERR_NOT_FOUND;
} }
} }
@@ -248,7 +248,7 @@ esp_err_t handler_capture_save_to_file(httpd_req_t *req)
} }
else else
{ {
httpd_resp_send_err(req, HTTPD_403_FORBIDDEN, "Camera Capture + save API not yet initialized. Please retry later..."); httpd_resp_send_err(req, HTTPD_403_FORBIDDEN, "Camera not initialized: REST API /save not available!");
return ESP_ERR_NOT_FOUND; return ESP_ERR_NOT_FOUND;
} }
} }

View File

@@ -38,6 +38,8 @@ bool isPlannedReboot = false;
static const char *TAG = "TFLITE SERVER"; static const char *TAG = "TFLITE SERVER";
//#define DEBUG_DETAIL_ON
void CheckIsPlannedReboot() void CheckIsPlannedReboot()
{ {
@@ -156,6 +158,8 @@ esp_err_t handler_get_heap(httpd_req_t *req)
} }
#endif #endif
httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*");
if (zw.length() > 0) if (zw.length() > 0)
{ {
httpd_resp_send(req, zw.c_str(), zw.length()); httpd_resp_send(req, zw.c_str(), zw.length());
@@ -180,16 +184,14 @@ esp_err_t handler_init(httpd_req_t *req)
ESP_LOGD(TAG, "handler_doinit uri: %s", req->uri); ESP_LOGD(TAG, "handler_doinit uri: %s", req->uri);
#endif #endif
httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*");
const char* resp_str = "Init started<br>"; const char* resp_str = "Init started<br>";
httpd_resp_send(req, resp_str, strlen(resp_str)); httpd_resp_send(req, resp_str, HTTPD_RESP_USE_STRLEN);
doInit(); doInit();
resp_str = "Init done<br>"; resp_str = "Init done<br>";
httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*"); httpd_resp_send(req, resp_str, HTTPD_RESP_USE_STRLEN);
httpd_resp_send(req, resp_str, strlen(resp_str));
/* Respond with an empty chunk to signal HTTP response completion */
httpd_resp_send_chunk(req, NULL, 0);
#ifdef DEBUG_DETAIL_ON #ifdef DEBUG_DETAIL_ON
LogFile.WriteHeapInfo("handler_init - Done"); LogFile.WriteHeapInfo("handler_init - Done");
@@ -207,23 +209,20 @@ esp_err_t handler_flow_start(httpd_req_t *req) {
ESP_LOGD(TAG, "handler_flow_start uri: %s", req->uri); ESP_LOGD(TAG, "handler_flow_start uri: %s", req->uri);
httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*");
if (auto_isrunning) { if (auto_isrunning) {
xTaskAbortDelay(xHandletask_autodoFlow); // Delay will be aborted if task is in blocked (waiting) state. If task is already running, no action xTaskAbortDelay(xHandletask_autodoFlow); // Delay will be aborted if task is in blocked (waiting) state. If task is already running, no action
LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "Flow start triggered by REST API /flow_start"); 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 or is already running"; const char* resp_str = "The flow is going to be started immediately or is already running";
httpd_resp_send(req, resp_str, strlen(resp_str)); httpd_resp_send(req, resp_str, HTTPD_RESP_USE_STRLEN);
} }
else { else {
LogFile.WriteToFile(ESP_LOG_WARN, TAG, "Flow start triggered by REST API, but flow is not active!"); LogFile.WriteToFile(ESP_LOG_WARN, TAG, "Flow start triggered by REST API, but flow is not active!");
const char* resp_str = "WARNING: Flow start triggered by REST API, but flow is not active"; const char* resp_str = "WARNING: Flow start triggered by REST API, but flow is not active";
httpd_resp_send(req, resp_str, strlen(resp_str)); httpd_resp_send(req, resp_str, HTTPD_RESP_USE_STRLEN);
} }
httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*");
/* Respond with an empty chunk to signal HTTP response completion */
httpd_resp_send_chunk(req, NULL, 0);
#ifdef DEBUG_DETAIL_ON #ifdef DEBUG_DETAIL_ON
LogFile.WriteHeapInfo("handler_flow_start - Done"); LogFile.WriteHeapInfo("handler_flow_start - Done");
#endif #endif
@@ -285,7 +284,7 @@ esp_err_t handler_json(httpd_req_t *req)
} }
else else
{ {
httpd_resp_send_err(req, HTTPD_403_FORBIDDEN, "JSON API not yet initialized. Please retry later..."); httpd_resp_send_err(req, HTTPD_403_FORBIDDEN, "Flow not (yet) started: REST API /json not yet available!");
return ESP_ERR_NOT_FOUND; return ESP_ERR_NOT_FOUND;
} }
@@ -369,8 +368,8 @@ esp_err_t handler_wasserzaehler(httpd_req_t *req)
zw = tfliteflow.getReadoutAll(_intype); zw = tfliteflow.getReadoutAll(_intype);
ESP_LOGD(TAG, "ZW: %s", zw.c_str()); ESP_LOGD(TAG, "ZW: %s", zw.c_str());
if (zw.length() > 0) if (zw.length() > 0)
httpd_resp_sendstr_chunk(req, zw.c_str()); httpd_resp_send(req, zw.c_str(), zw.length());
httpd_resp_sendstr_chunk(req, NULL);
return ESP_OK; return ESP_OK;
} }
@@ -439,7 +438,7 @@ esp_err_t handler_wasserzaehler(httpd_req_t *req)
} }
else else
{ {
httpd_resp_send_err(req, HTTPD_403_FORBIDDEN, "Value API not yet initialized. Please retry later..."); httpd_resp_send_err(req, HTTPD_403_FORBIDDEN, "Flow not (yet) started: REST API /value not available!");
return ESP_ERR_NOT_FOUND; return ESP_ERR_NOT_FOUND;
} }
@@ -514,7 +513,7 @@ esp_err_t handler_editflow(httpd_req_t *req)
CopyFile(in, out); CopyFile(in, out);
zw = "Copy Done"; zw = "Copy Done";
httpd_resp_sendstr_chunk(req, zw.c_str()); httpd_resp_send(req, zw.c_str(), zw.length());
} }
@@ -583,7 +582,7 @@ esp_err_t handler_editflow(httpd_req_t *req)
delete cim; delete cim;
zw = "CutImage Done"; zw = "CutImage Done";
httpd_resp_sendstr_chunk(req, zw.c_str()); httpd_resp_send(req, zw.c_str(), zw.length());
} }
@@ -626,8 +625,7 @@ esp_err_t handler_editflow(httpd_req_t *req)
Camera.SetLEDIntensity(intens); Camera.SetLEDIntensity(intens);
ESP_LOGD(TAG, "test_take - vor MakeImage"); ESP_LOGD(TAG, "test_take - vor MakeImage");
std::string zw = tfliteflow.doSingleStep("[MakeImage]", _host); std::string zw = tfliteflow.doSingleStep("[MakeImage]", _host);
httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*"); httpd_resp_send(req, zw.c_str(), zw.length());
httpd_resp_sendstr_chunk(req, zw.c_str());
} }
@@ -641,12 +639,9 @@ esp_err_t handler_editflow(httpd_req_t *req)
// string zwzw = "Do " + _task + " start\n"; ESP_LOGD(TAG, zwzw.c_str()); // string zwzw = "Do " + _task + " start\n"; ESP_LOGD(TAG, zwzw.c_str());
std::string zw = tfliteflow.doSingleStep("[Alignment]", _host); std::string zw = tfliteflow.doSingleStep("[Alignment]", _host);
httpd_resp_sendstr_chunk(req, zw.c_str()); httpd_resp_send(req, zw.c_str(), zw.length());
} }
/* Respond with an empty chunk to signal HTTP response completion */
httpd_resp_sendstr_chunk(req, NULL);
#ifdef DEBUG_DETAIL_ON #ifdef DEBUG_DETAIL_ON
LogFile.WriteHeapInfo("handler_editflow - Done"); LogFile.WriteHeapInfo("handler_editflow - Done");
#endif #endif
@@ -673,13 +668,11 @@ esp_err_t handler_statusflow(httpd_req_t *req)
resp_str = zw->c_str(); resp_str = zw->c_str();
httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*"); httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*");
httpd_resp_send(req, resp_str, strlen(resp_str)); httpd_resp_send(req, resp_str, HTTPD_RESP_USE_STRLEN);
/* Respond with an empty chunk to signal HTTP response completion */
httpd_resp_send_chunk(req, NULL, 0);
} }
else else
{ {
httpd_resp_send_err(req, HTTPD_403_FORBIDDEN, "Flowstatus API not yet initialized. Please retry later..."); httpd_resp_send_err(req, HTTPD_403_FORBIDDEN, "Flow not (yet) started: REST API /flowstatus not available!");
return ESP_ERR_NOT_FOUND; return ESP_ERR_NOT_FOUND;
} }
@@ -705,9 +698,7 @@ esp_err_t handler_cputemp(httpd_req_t *req)
resp_str = cputemp; resp_str = cputemp;
httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*"); httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*");
httpd_resp_send(req, resp_str, strlen(resp_str)); httpd_resp_send(req, resp_str, HTTPD_RESP_USE_STRLEN);
/* Respond with an empty chunk to signal HTTP response completion */
httpd_resp_send_chunk(req, NULL, 0);
#ifdef DEBUG_DETAIL_ON #ifdef DEBUG_DETAIL_ON
LogFile.WriteHeapInfo("handler_cputemp - End"); LogFile.WriteHeapInfo("handler_cputemp - End");
@@ -733,13 +724,11 @@ esp_err_t handler_rssi(httpd_req_t *req)
resp_str = rssi; resp_str = rssi;
httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*"); httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*");
httpd_resp_send(req, resp_str, strlen(resp_str)); httpd_resp_send(req, resp_str, HTTPD_RESP_USE_STRLEN);
/* Respond with an empty chunk to signal HTTP response completion */
httpd_resp_send_chunk(req, NULL, 0);
} }
else else
{ {
httpd_resp_send_err(req, HTTPD_403_FORBIDDEN, "RSSI API not yet initialized. Please retry later..."); httpd_resp_send_err(req, HTTPD_403_FORBIDDEN, "WIFI not (yet) connected: REST API /rssi not available!");
return ESP_ERR_NOT_FOUND; return ESP_ERR_NOT_FOUND;
} }
@@ -761,9 +750,7 @@ esp_err_t handler_uptime(httpd_req_t *req)
std::string formatedUptime = getFormatedUptime(false); std::string formatedUptime = getFormatedUptime(false);
httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*"); httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*");
httpd_resp_send(req, formatedUptime.c_str(), strlen(formatedUptime.c_str())); httpd_resp_send(req, formatedUptime.c_str(), formatedUptime.length());
/* Respond with an empty chunk to signal HTTP response completion */
httpd_resp_send_chunk(req, NULL, 0);
#ifdef DEBUG_DETAIL_ON #ifdef DEBUG_DETAIL_ON
LogFile.WriteHeapInfo("handler_uptime - End"); LogFile.WriteHeapInfo("handler_uptime - End");
@@ -792,9 +779,9 @@ esp_err_t handler_prevalue(httpd_req_t *req)
if (httpd_req_get_url_query_str(req, _query, 100) == ESP_OK) if (httpd_req_get_url_query_str(req, _query, 100) == ESP_OK)
{ {
#ifdef DEBUG_DETAIL_ON #ifdef DEBUG_DETAIL_ON
ESP_LOGD(TAG, "Query: %s", _query); ESP_LOGD(TAG, "Query: %s", _query);
#endif #endif
if (httpd_query_key_value(_query, "value", _size, 10) == ESP_OK) if (httpd_query_key_value(_query, "value", _size, 10) == ESP_OK)
{ {
@@ -818,11 +805,8 @@ esp_err_t handler_prevalue(httpd_req_t *req)
resp_str = zw.c_str(); resp_str = zw.c_str();
httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*"); httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*");
httpd_resp_send(req, resp_str, HTTPD_RESP_USE_STRLEN);
httpd_resp_send(req, resp_str, strlen(resp_str));
/* Respond with an empty chunk to signal HTTP response completion */
httpd_resp_send_chunk(req, NULL, 0);
#ifdef DEBUG_DETAIL_ON #ifdef DEBUG_DETAIL_ON
LogFile.WriteHeapInfo("handler_prevalue - End"); LogFile.WriteHeapInfo("handler_prevalue - End");

View File

@@ -46,155 +46,139 @@ esp_err_t info_get_handler(httpd_req_t *req)
ESP_LOGD(TAG, "type is found: %s", _valuechar); ESP_LOGD(TAG, "type is found: %s", _valuechar);
_task = std::string(_valuechar); _task = std::string(_valuechar);
} }
}; }
httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*"); httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*");
if (_task.compare("GitBranch") == 0) if (_task.compare("GitBranch") == 0)
{ {
httpd_resp_sendstr_chunk(req, libfive_git_branch()); httpd_resp_sendstr(req, libfive_git_branch());
httpd_resp_sendstr_chunk(req, NULL);
return ESP_OK; return ESP_OK;
} }
else if (_task.compare("GitTag") == 0) else if (_task.compare("GitTag") == 0)
{ {
httpd_resp_sendstr_chunk(req, libfive_git_version()); httpd_resp_sendstr(req, libfive_git_version());
httpd_resp_sendstr_chunk(req, NULL);
return ESP_OK; return ESP_OK;
} }
else if (_task.compare("GitRevision") == 0) else if (_task.compare("GitRevision") == 0)
{ {
httpd_resp_sendstr_chunk(req, libfive_git_revision()); httpd_resp_sendstr(req, libfive_git_revision());
httpd_resp_sendstr_chunk(req, NULL);
return ESP_OK; return ESP_OK;
} }
else if (_task.compare("BuildTime") == 0) else if (_task.compare("BuildTime") == 0)
{ {
httpd_resp_sendstr_chunk(req, build_time()); httpd_resp_sendstr(req, build_time());
httpd_resp_sendstr_chunk(req, NULL);
return ESP_OK; return ESP_OK;
} }
else if (_task.compare("FirmwareVersion") == 0) else if (_task.compare("FirmwareVersion") == 0)
{ {
httpd_resp_sendstr_chunk(req, getFwVersion().c_str()); httpd_resp_sendstr(req, getFwVersion().c_str());
httpd_resp_sendstr_chunk(req, NULL);
return ESP_OK; return ESP_OK;
} }
else if (_task.compare("HTMLVersion") == 0) else if (_task.compare("HTMLVersion") == 0)
{ {
httpd_resp_sendstr_chunk(req, getHTMLversion().c_str()); httpd_resp_sendstr(req, getHTMLversion().c_str());
httpd_resp_sendstr_chunk(req, NULL);
return ESP_OK; return ESP_OK;
} }
else if (_task.compare("Hostname") == 0) else if (_task.compare("Hostname") == 0)
{ {
std::string zw; std::string zw;
zw = std::string(hostname); zw = std::string(hostname);
httpd_resp_sendstr_chunk(req, zw.c_str()); httpd_resp_sendstr(req, zw.c_str());
httpd_resp_sendstr_chunk(req, NULL);
return ESP_OK; return ESP_OK;
} }
else if (_task.compare("IP") == 0) else if (_task.compare("IP") == 0)
{ {
std::string *zw; std::string *zw;
zw = getIPAddress(); zw = getIPAddress();
httpd_resp_sendstr_chunk(req, zw->c_str()); httpd_resp_sendstr(req, zw->c_str());
httpd_resp_sendstr_chunk(req, NULL);
return ESP_OK; return ESP_OK;
} }
else if (_task.compare("SSID") == 0) else if (_task.compare("SSID") == 0)
{ {
std::string *zw; std::string *zw;
zw = getSSID(); zw = getSSID();
httpd_resp_sendstr_chunk(req, zw->c_str()); httpd_resp_sendstr(req, zw->c_str());
httpd_resp_sendstr_chunk(req, NULL);
return ESP_OK; return ESP_OK;
} }
else if (_task.compare("FlowStatus") == 0) else if (_task.compare("FlowStatus") == 0)
{ {
std::string zw; std::string zw;
zw = std::string("FlowStatus"); zw = std::string("FlowStatus");
httpd_resp_sendstr_chunk(req, zw.c_str()); httpd_resp_sendstr(req, zw.c_str());
httpd_resp_sendstr_chunk(req, NULL);
return ESP_OK; return ESP_OK;
} }
else if (_task.compare("Round") == 0) else if (_task.compare("Round") == 0)
{ {
char formated[10] = ""; char formated[10] = "";
snprintf(formated, sizeof(formated), "%d", getCountFlowRounds()); snprintf(formated, sizeof(formated), "%d", getCountFlowRounds());
httpd_resp_sendstr_chunk(req, formated); httpd_resp_sendstr(req, formated);
httpd_resp_sendstr_chunk(req, NULL);
return ESP_OK; return ESP_OK;
} }
else if (_task.compare("SDCardPartitionSize") == 0) else if (_task.compare("SDCardPartitionSize") == 0)
{ {
std::string zw; std::string zw;
zw = getSDCardPartitionSize(); zw = getSDCardPartitionSize();
httpd_resp_sendstr_chunk(req, zw.c_str()); httpd_resp_sendstr(req, zw.c_str());
httpd_resp_sendstr_chunk(req, NULL);
return ESP_OK; return ESP_OK;
} }
else if (_task.compare("SDCardFreePartitionSpace") == 0) else if (_task.compare("SDCardFreePartitionSpace") == 0)
{ {
std::string zw; std::string zw;
zw = getSDCardFreePartitionSpace(); zw = getSDCardFreePartitionSpace();
httpd_resp_sendstr_chunk(req, zw.c_str()); httpd_resp_sendstr(req, zw.c_str());
httpd_resp_sendstr_chunk(req, NULL);
return ESP_OK; return ESP_OK;
} }
else if (_task.compare("SDCardPartitionAllocationSize") == 0) else if (_task.compare("SDCardPartitionAllocationSize") == 0)
{ {
std::string zw; std::string zw;
zw = getSDCardPartitionAllocationSize(); zw = getSDCardPartitionAllocationSize();
httpd_resp_sendstr_chunk(req, zw.c_str()); httpd_resp_sendstr(req, zw.c_str());
httpd_resp_sendstr_chunk(req, NULL);
return ESP_OK; return ESP_OK;
} }
else if (_task.compare("SDCardManufacturer") == 0) else if (_task.compare("SDCardManufacturer") == 0)
{ {
std::string zw; std::string zw;
zw = getSDCardManufacturer(); zw = getSDCardManufacturer();
httpd_resp_sendstr_chunk(req, zw.c_str()); httpd_resp_sendstr(req, zw.c_str());
httpd_resp_sendstr_chunk(req, NULL);
return ESP_OK; return ESP_OK;
} }
else if (_task.compare("SDCardName") == 0) else if (_task.compare("SDCardName") == 0)
{ {
std::string zw; std::string zw;
zw = getSDCardName(); zw = getSDCardName();
httpd_resp_sendstr_chunk(req, zw.c_str()); httpd_resp_sendstr(req, zw.c_str());
httpd_resp_sendstr_chunk(req, NULL);
return ESP_OK; return ESP_OK;
} }
else if (_task.compare("SDCardCapacity") == 0) else if (_task.compare("SDCardCapacity") == 0)
{ {
std::string zw; std::string zw;
zw = getSDCardCapacity(); zw = getSDCardCapacity();
httpd_resp_sendstr_chunk(req, zw.c_str()); httpd_resp_sendstr(req, zw.c_str());
httpd_resp_sendstr_chunk(req, NULL);
return ESP_OK; return ESP_OK;
} }
else if (_task.compare("SDCardSectorSize") == 0) else if (_task.compare("SDCardSectorSize") == 0)
{ {
std::string zw; std::string zw;
zw = getSDCardSectorSize(); zw = getSDCardSectorSize();
httpd_resp_sendstr_chunk(req, zw.c_str()); httpd_resp_sendstr(req, zw.c_str());
httpd_resp_sendstr_chunk(req, NULL);
return ESP_OK; return ESP_OK;
} }
return ESP_OK; return ESP_OK;
} }
esp_err_t starttime_get_handler(httpd_req_t *req) esp_err_t starttime_get_handler(httpd_req_t *req)
{ {
httpd_resp_send(req, starttime.c_str(), strlen(starttime.c_str())); httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*");
/* Respond with an empty chunk to signal HTTP response completion */
httpd_resp_send_chunk(req, NULL, 0); httpd_resp_send(req, starttime.c_str(), starttime.length());
return ESP_OK; return ESP_OK;
} }
esp_err_t hello_main_handler(httpd_req_t *req) esp_err_t hello_main_handler(httpd_req_t *req)
{ {
#ifdef DEBUG_DETAIL_ON #ifdef DEBUG_DETAIL_ON
@@ -286,6 +270,7 @@ esp_err_t hello_main_handler(httpd_req_t *req)
return ESP_OK; return ESP_OK;
} }
esp_err_t img_tmp_handler(httpd_req_t *req) esp_err_t img_tmp_handler(httpd_req_t *req)
{ {
char filepath[50]; char filepath[50];
@@ -310,6 +295,7 @@ esp_err_t img_tmp_handler(httpd_req_t *req)
return ESP_OK; return ESP_OK;
} }
esp_err_t img_tmp_virtual_handler(httpd_req_t *req) esp_err_t img_tmp_virtual_handler(httpd_req_t *req)
{ {
#ifdef DEBUG_DETAIL_ON #ifdef DEBUG_DETAIL_ON
@@ -390,13 +376,12 @@ esp_err_t sysinfo_handler(httpd_req_t *req)
resp_str = zw.c_str(); resp_str = zw.c_str();
httpd_resp_set_type(req, "application/json"); httpd_resp_set_type(req, "application/json");
httpd_resp_send(req, resp_str, strlen(resp_str)); httpd_resp_sendstr(req, resp_str);
/* Respond with an empty chunk to signal HTTP response completion */
httpd_resp_send_chunk(req, NULL, 0);
return ESP_OK; return ESP_OK;
} }
void register_server_main_uri(httpd_handle_t server, const char *base_path) void register_server_main_uri(httpd_handle_t server, const char *base_path)
{ {
httpd_uri_t info_get_handle = { httpd_uri_t info_get_handle = {
@@ -423,8 +408,6 @@ void register_server_main_uri(httpd_handle_t server, const char *base_path)
}; };
httpd_register_uri_handler(server, &starttime_tmp_handle); httpd_register_uri_handler(server, &starttime_tmp_handle);
httpd_uri_t img_tmp_handle = { httpd_uri_t img_tmp_handle = {
.uri = "/img_tmp/*", // Match all URIs of type /path/to/file .uri = "/img_tmp/*", // Match all URIs of type /path/to/file
.method = HTTP_GET, .method = HTTP_GET,
@@ -433,7 +416,6 @@ void register_server_main_uri(httpd_handle_t server, const char *base_path)
}; };
httpd_register_uri_handler(server, &img_tmp_handle); httpd_register_uri_handler(server, &img_tmp_handle);
httpd_uri_t main_rest_handle = { httpd_uri_t main_rest_handle = {
.uri = "/*", // Match all URIs of type /path/to/file .uri = "/*", // Match all URIs of type /path/to/file
.method = HTTP_GET, .method = HTTP_GET,
@@ -445,7 +427,6 @@ void register_server_main_uri(httpd_handle_t server, const char *base_path)
} }
httpd_handle_t start_webserver(void) httpd_handle_t start_webserver(void)
{ {
httpd_handle_t server = NULL; httpd_handle_t server = NULL;
@@ -486,6 +467,7 @@ httpd_handle_t start_webserver(void)
return NULL; return NULL;
} }
void stop_webserver(httpd_handle_t server) void stop_webserver(httpd_handle_t server)
{ {
httpd_stop(server); httpd_stop(server);
@@ -503,6 +485,7 @@ void disconnect_handler(void* arg, esp_event_base_t event_base,
} }
} }
void connect_handler(void* arg, esp_event_base_t event_base, void connect_handler(void* arg, esp_event_base_t event_base,
int32_t event_id, void* event_data) int32_t event_id, void* event_data)
{ {