@@ -573,12 +573,16 @@ static esp_err_t load_pid_auto_config_handler(httpd_req_t *req)
573
573
return ESP_OK ;
574
574
}
575
575
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
+ }
578
582
579
583
ESP_LOGI (TAG , "Sending response: %s" , buf );
580
584
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
582
586
583
587
free (buf );
584
588
return ESP_OK ;
@@ -589,6 +593,8 @@ static esp_err_t load_config_handler(httpd_req_t *req)
589
593
const char * resp_str = (const char * )device_config_file ;
590
594
httpd_resp_send (req , (const char * )resp_str , HTTPD_RESP_USE_STRLEN );
591
595
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 );
592
598
return ESP_OK ;
593
599
}
594
600
@@ -1338,6 +1344,14 @@ static esp_err_t scan_available_pids_handler(httpd_req_t *req)
1338
1344
char param [32 ];
1339
1345
uint8_t protocol_num = 6 ; // Default protocol
1340
1346
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
+
1341
1355
if (httpd_req_get_url_query_str (req , param , sizeof (param )) == ESP_OK ) {
1342
1356
if (httpd_query_key_value (param , "protocol" , protocol , sizeof (protocol )) == ESP_OK ) {
1343
1357
protocol_num = atoi (protocol );
@@ -2137,6 +2151,7 @@ static httpd_handle_t config_server_init(void)
2137
2151
2138
2152
// Start the httpd server
2139
2153
config .max_uri_handlers = 18 ;
2154
+ config .stack_size = 5120 ;
2140
2155
ESP_LOGI (TAG , "Starting server on port: '%d'" , config .server_port );
2141
2156
if (httpd_start (& server , & config ) == ESP_OK )
2142
2157
{
0 commit comments