naiive work around: recreate and close http client after each transaction
This commit is contained in:
10
main/main.c
10
main/main.c
@@ -75,7 +75,7 @@ void app_main(void)
|
|||||||
ESP_ERROR_CHECK(example_connect());
|
ESP_ERROR_CHECK(example_connect());
|
||||||
|
|
||||||
// prepare url
|
// prepare url
|
||||||
init_http_clients();
|
/* init_http_clients(); */
|
||||||
|
|
||||||
// setup the sensors
|
// setup the sensors
|
||||||
setup_i2c();
|
setup_i2c();
|
||||||
@@ -158,6 +158,12 @@ static void post_error_http(esp_http_client_handle_t client,
|
|||||||
static void post_data_http(esp_http_client_handle_t client,
|
static void post_data_http(esp_http_client_handle_t client,
|
||||||
char* sensor, char *sensor_description, float temp, float humi, float pres)
|
char* sensor, char *sensor_description, float temp, float humi, float pres)
|
||||||
{
|
{
|
||||||
|
char url[80];
|
||||||
|
snprintf(url, 80, "%s/%s", db_worker_root, sensor);
|
||||||
|
esp_http_client_config_t config = { .url = url, .event_handler = _http_event_handler};
|
||||||
|
client = esp_http_client_init(&config);
|
||||||
|
esp_http_client_set_method(client, HTTP_METHOD_POST);
|
||||||
|
esp_http_client_set_header(client, "Content-Type", "application/json");
|
||||||
// POST
|
// POST
|
||||||
char post_data[256];
|
char post_data[256];
|
||||||
snprintf(post_data, sizeof(post_data),
|
snprintf(post_data, sizeof(post_data),
|
||||||
@@ -173,6 +179,8 @@ static void post_data_http(esp_http_client_handle_t client,
|
|||||||
} else {
|
} else {
|
||||||
ESP_LOGE(TAG, "HTTP POST request failed: %s", esp_err_to_name(err));
|
ESP_LOGE(TAG, "HTTP POST request failed: %s", esp_err_to_name(err));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
esp_http_client_cleanup(client);
|
||||||
}
|
}
|
||||||
|
|
||||||
esp_err_t _http_event_handler(esp_http_client_event_t *evt)
|
esp_err_t _http_event_handler(esp_http_client_event_t *evt)
|
||||||
|
|||||||
Reference in New Issue
Block a user