From 91fe8a3b467eb3ce388e57fb5f6debdf5e19897b Mon Sep 17 00:00:00 2001 From: Nam Tran Date: Tue, 15 Sep 2020 23:12:41 -0500 Subject: [PATCH] naiive work around: recreate and close http client after each transaction --- main/main.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/main/main.c b/main/main.c index 72d0386..812abe5 100644 --- a/main/main.c +++ b/main/main.c @@ -75,7 +75,7 @@ void app_main(void) ESP_ERROR_CHECK(example_connect()); // prepare url - init_http_clients(); + /* init_http_clients(); */ // setup the sensors 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, 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 char post_data[256]; snprintf(post_data, sizeof(post_data), @@ -173,6 +179,8 @@ static void post_data_http(esp_http_client_handle_t client, } else { 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)