naiive work around: recreate and close http client after each transaction

This commit is contained in:
2020-09-15 23:12:41 -05:00
parent 5c7341487f
commit 91fe8a3b46

View File

@@ -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)