Rest Server
Posted: Sun Apr 11, 2021 8:10 pm
Colleagues programmers would like information, I set up through esp32 a rest application according to the example of Espressif. Everything is working but it has a detail that I couldn't solve about a variable.
this is part of the espressif example
What I did I replaced
const char * sys_info
for
std :: string sys_info
and removed
free((void *)sys_info);
this is working but the only problem is that whenever I make a request like for example in the postman I keep monitoring the memory and with each request the impression it creates a new variable std :: string sys_info because the available memory drops, work as in the first example with free ((void *) sys_info); the available memory does not change. Can someone give me guidance
this is part of the espressif example
Code: Select all
/* Simple handler for getting system handler */
static esp_err_t system_info_get_handler(httpd_req_t *req)
{
httpd_resp_set_type(req, "application/json");
cJSON *root = cJSON_CreateObject();
esp_chip_info_t chip_info;
esp_chip_info(&chip_info);
cJSON_AddStringToObject(root, "version", IDF_VER);
cJSON_AddNumberToObject(root, "cores", chip_info.cores);
const char *sys_info = cJSON_Print(root);
httpd_resp_sendstr(req, sys_info);
free((void *)sys_info);
cJSON_Delete(root);
return ESP_OK;
}
const char * sys_info
for
std :: string sys_info
and removed
free((void *)sys_info);
Code: Select all
static esp_err_t system_info_get_handler(httpd_req_t *req)
{
httpd_resp_set_type(req, "application/json");
cJSON *root = cJSON_CreateObject();
esp_chip_info_t chip_info;
esp_chip_info(&chip_info);
cJSON_AddStringToObject(root, "version", IDF_VER);
cJSON_AddNumberToObject(root, "cores", chip_info.cores);
//const char *sys_info = cJSON_Print(root); (replace)
std::string sys_info = cJSON_Print(root);
httpd_resp_sendstr(req, sys_info);
//free((void *)sys_info); (removed)
cJSON_Delete(root);
return ESP_OK;
}