Skip to content

Commit 92aa9e7

Browse files
committed
update
- disable pid scan if autpid protocol not selected - remove unnecessary bytes from car profile json after the last }
1 parent f7daf0c commit 92aa9e7

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

main/config_server.c

+18-3
Original file line numberDiff line numberDiff line change
@@ -573,12 +573,16 @@ static esp_err_t load_pid_auto_config_handler(httpd_req_t *req)
573573
return ESP_OK;
574574
}
575575

576-
// Null-terminate the read buffer
577-
buf[read_len] = '\0';
576+
// Find the last closing brace and terminate the string there
577+
char *last_brace = strrchr(buf, '}');
578+
if (last_brace != NULL) {
579+
*(last_brace + 1) = '\0'; // Terminate string right after the last }
580+
read_len = last_brace - buf + 1; // Update length to new size
581+
}
578582

579583
ESP_LOGI(TAG, "Sending response: %s", buf);
580584
httpd_resp_set_type(req, "application/json");
581-
httpd_resp_send(req, buf, HTTPD_RESP_USE_STRLEN);
585+
httpd_resp_send(req, buf, read_len); // Use actual content length instead of HTTPD_RESP_USE_STRLEN
582586

583587
free(buf);
584588
return ESP_OK;
@@ -589,6 +593,8 @@ static esp_err_t load_config_handler(httpd_req_t *req)
589593
const char* resp_str = (const char*)device_config_file;
590594
httpd_resp_send(req, (const char*)resp_str, HTTPD_RESP_USE_STRLEN);
591595
ESP_LOGI(TAG, "device_config_file: %s", device_config_file);
596+
UBaseType_t stack_high_watermark = uxTaskGetStackHighWaterMark(NULL);
597+
ESP_LOGI(TAG, "Task stack high watermark: %u words", stack_high_watermark);
592598
return ESP_OK;
593599
}
594600

@@ -1338,6 +1344,14 @@ static esp_err_t scan_available_pids_handler(httpd_req_t *req)
13381344
char param[32];
13391345
uint8_t protocol_num = 6; // Default protocol
13401346

1347+
if(config_server_protocol() != AUTO_PID)
1348+
{
1349+
httpd_resp_set_type(req, "application/json");
1350+
const char *resp_str = "{\"text\":\"Set protocol to AutoPid and reboot to be able to scan\"}";
1351+
httpd_resp_send(req, resp_str, strlen(resp_str));
1352+
return ESP_OK;
1353+
}
1354+
13411355
if (httpd_req_get_url_query_str(req, param, sizeof(param)) == ESP_OK) {
13421356
if (httpd_query_key_value(param, "protocol", protocol, sizeof(protocol)) == ESP_OK) {
13431357
protocol_num = atoi(protocol);
@@ -2137,6 +2151,7 @@ static httpd_handle_t config_server_init(void)
21372151

21382152
// Start the httpd server
21392153
config.max_uri_handlers = 18;
2154+
config.stack_size = 5120;
21402155
ESP_LOGI(TAG, "Starting server on port: '%d'", config.server_port);
21412156
if (httpd_start(&server, &config) == ESP_OK)
21422157
{

0 commit comments

Comments
 (0)