improved report function to pause current requests

This commit is contained in:
Lurkars 2020-12-12 13:33:13 +01:00
parent c8410e0354
commit 48d80cfd62
2 changed files with 35 additions and 2 deletions

View File

@ -38,6 +38,23 @@ static time_t request_sleep = 0;
static uint32_t request_sleep_waiting = 30; static uint32_t request_sleep_waiting = 30;
static time_t last_check = 0; static time_t last_check = 0;
static bool wait_for_request = false; static bool wait_for_request = false;
static bool request_pause = false;
void ena_eke_proxy_pause(void)
{
while (wait_for_request || request_pause)
{
ESP_LOGD(ENA_EKE_PROXY_LOG, "waiting for other requests to finish...");
vTaskDelay(1000 / portTICK_PERIOD_MS);
}
request_pause = true;
}
void ena_eke_proxy_resume(void)
{
request_pause = false;
}
esp_err_t ena_eke_proxy_fetch_event_handler(esp_http_client_event_t *evt) esp_err_t ena_eke_proxy_fetch_event_handler(esp_http_client_event_t *evt)
{ {
@ -256,7 +273,7 @@ void ena_eke_proxy_run(void)
last_check = (time_t)ena_storage_read_last_exposure_date(); last_check = (time_t)ena_storage_read_last_exposure_date();
check_diff = difftime(current_time, last_check); check_diff = difftime(current_time, last_check);
if (check_diff > HOUR_IN_SECONDS && !wait_for_request && current_time > request_sleep) if (check_diff > HOUR_IN_SECONDS && !wait_for_request && !request_pause && current_time > request_sleep)
{ {
if (wifi_controller_connection() == NULL && current_time > wifi_reconnect && wifi_reconnect_waiting < 86400) if (wifi_controller_connection() == NULL && current_time > wifi_reconnect && wifi_reconnect_waiting < 86400)
{ {
@ -323,6 +340,7 @@ esp_err_t ena_eke_proxy_fetch_upload_handler(esp_http_client_event_t *evt)
case HTTP_EVENT_ON_DATA: case HTTP_EVENT_ON_DATA:
break; break;
case HTTP_EVENT_ON_FINISH: case HTTP_EVENT_ON_FINISH:
ena_eke_proxy_resume();
break; break;
default: default:
break; break;
@ -333,6 +351,8 @@ esp_err_t ena_eke_proxy_fetch_upload_handler(esp_http_client_event_t *evt)
esp_err_t ena_eke_proxy_upload(char *token, uint32_t days_since_onset_of_symptoms) esp_err_t ena_eke_proxy_upload(char *token, uint32_t days_since_onset_of_symptoms)
{ {
ena_eke_proxy_pause();
ESP_LOGD(ENA_EKE_PROXY_LOG, "try to upload keys:"); ESP_LOGD(ENA_EKE_PROXY_LOG, "try to upload keys:");
esp_http_client_config_t config = { esp_http_client_config_t config = {
.url = ENA_EKE_PROXY_KEYFILES_UPLOAD_URL, .url = ENA_EKE_PROXY_KEYFILES_UPLOAD_URL,
@ -391,6 +411,7 @@ esp_err_t ena_eke_proxy_upload(char *token, uint32_t days_since_onset_of_symptom
else else
{ {
ESP_LOGW(ENA_EKE_PROXY_LOG, "Keyupload failed!"); ESP_LOGW(ENA_EKE_PROXY_LOG, "Keyupload failed!");
ena_eke_proxy_resume();
} }
free(output_buffer); free(output_buffer);

View File

@ -85,4 +85,16 @@ void ena_eke_proxy_run(void);
*/ */
esp_err_t ena_eke_proxy_upload(char *token, uint32_t days_since_onset_of_symptoms); esp_err_t ena_eke_proxy_upload(char *token, uint32_t days_since_onset_of_symptoms);
/**
* @brief pause requests
*
*/
void ena_eke_proxy_pause(void);
/**
* @brief resume requests
*
*/
void ena_eke_proxy_resume(void);
#endif #endif