Commit db37a578 authored by Jacob Priddy's avatar Jacob Priddy 👌

Merge branch 'header-fetch-fix-2' into 'master'

Fix slow API calls and failing to connect to API

See merge request !10
parents 2fc2f977 d3935a73
Pipeline #12721 passed with stages
in 1 minute and 41 seconds
......@@ -21,7 +21,7 @@ build_tests:
build_esp32_application:
stage: build
script:
- echo $WEBSERVER_ROOT_CERT | base64 -d -w 0 > main/doorcode_root_cert.cert
- mv main/doorcode_root_cert.cert.prod main/doorcode_root_cert.cert
- cp main/include/config.h.example main/include/config.h
- /opt/esp/entrypoint.sh bash
- idf.py build
......
-----BEGIN CERTIFICATE-----
MIIB6jCCAZECFDb5sh03iLzvv3lh9hGvPShVD+XxMAoGCCqGSM49BAMCMHcxCzAJ
BgNVBAYTAlVTMRMwEQYDVQQIDApXYXNoaW5ndG9uMRYwFAYDVQQHDA1Db2xsZWdl
IFBsYWNlMQwwCgYDVQQKDANXV1UxHTAbBgNVBAsMFGVsb2NrIFJPT1QgQ0EgSVNT
VUVSMQ4wDAYDVQQDDAVlbG9jazAgFw0yMDA2MjcyMzIyNTFaGA8yMDcwMDYxNTIz
MjI1MVowdzELMAkGA1UEBhMCVVMxEzARBgNVBAgMCldhc2hpbmd0b24xFjAUBgNV
BAcMDUNvbGxlZ2UgUGxhY2UxDDAKBgNVBAoMA1dXVTEdMBsGA1UECwwUZWxvY2sg
Uk9PVCBDQSBJU1NVRVIxDjAMBgNVBAMMBWVsb2NrMFkwEwYHKoZIzj0CAQYIKoZI
zj0DAQcDQgAEAhPkFYRa4nWox26JCB8ClUg/PORZvkkzGMV4/yKZNWPSRtqS8QKD
09dRt55MVj5W4AmRkRHwqbXTAvujt7eovzAKBggqhkjOPQQDAgNHADBEAiBjDRHN
wmkwISOF2AE3cAgyMiUlXPA+WAZKHgbxKX1MUwIgdW47WeuGJ53939yX1vOiYDky
GLh8/I3sv/uEnA0TIFI=
-----END CERTIFICATE-----
-----BEGIN CERTIFICATE-----
MIIDlTCCAn0CFFXlCyRWA31vhnSP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tYbULjdYtysrigl
IZFQrM+oXpKEDKq+Fqax27O9RrgmIIrxpAU0/KxASbKgpCkW+T2UZTjOjms8NpdO
EH7zjGq59lewpAyG5trG/OAVzmi4sIKiRwXQwdHjcGXwjio+isDbu0s2HI5nCZSh
MlKGC4g2E4bP
-----END CERTIFICATE-----
......@@ -48,8 +48,10 @@
#define MIN_CODE_LENGTH 4
// 15 minutes
#define STATUS_MAX_NO_CONTACT_TIME_MS (1000 * 60 * 15)
// Set to 1 minute instead of something like 15 minutes to keep the SSL connection alive
// so it can be reused as much as possible, as it takes around 2 seconds with RSA 2048 keys
// and a whopping 5 seconds with ECDSA keys :(
#define STATUS_MAX_NO_CONTACT_TIME_MS (1000 * 60)
// How often to update the keypad state
#define KEYPAD_SCAN_PERIOD_MS 50
......
......@@ -166,16 +166,22 @@ int door_http_get(door_http_client_handle_t client, const char* path, door_http_
esp_http_client_set_url(handle, path);
esp_http_client_set_method(handle, HTTP_METHOD_GET);
esp_err_t err = esp_http_client_perform(handle);
if (err != ESP_OK)
{
ESP_LOGE(TAG, "Error perform http request %s", esp_err_to_name(err));
return DOOR_HTTP_ERR_FAIL;
}
// Bug in the framework, have to retry until it works
// https://github.com/espressif/esp-idf/issues/2684
for (int tries = 0; tries < 3; ++tries) {
esp_err_t err = esp_http_client_perform(handle);
int status_code = esp_http_client_get_status_code(handle);
ESP_LOGI(TAG, "Status code from GET call: %d", status_code);
return status_code;
if (err == ESP_OK)
{
int status_code = esp_http_client_get_status_code(handle);
ESP_LOGI(TAG, "Status code from GET call: %d", status_code);
return status_code;
}
ESP_LOGE(TAG, "Error perform http request %s. Retrying...", esp_err_to_name(err));
esp_http_client_close(handle);
}
return DOOR_HTTP_ERR_FAIL;
}
int door_http_post(
......@@ -197,15 +203,23 @@ int door_http_post(
esp_http_client_set_url(handle, path);
esp_http_client_set_method(handle, HTTP_METHOD_POST);
esp_http_client_set_post_field(client, data, strlen(data));
esp_err_t err = esp_http_client_perform(handle);
if (err != ESP_OK)
{
ESP_LOGE(TAG, "Error perform http request %s", esp_err_to_name(err));
return DOOR_HTTP_ERR_FAIL;
// Bug in the framework, have to retry until it works
// https://github.com/espressif/esp-idf/issues/2684
for (int tries = 0; tries < 3; ++tries) {
esp_err_t err = esp_http_client_perform(handle);
if (err == ESP_OK)
{
int status_code = esp_http_client_get_status_code(handle);
ESP_LOGI(TAG, "Status code from POST call: %d", status_code);
return status_code;
}
ESP_LOGE(TAG, "Error perform http request %s. Retrying...", esp_err_to_name(err));
esp_http_client_close(handle);
}
int status_code = esp_http_client_get_status_code(handle);
ESP_LOGI(TAG, "Status code from POST call: %d", status_code);
return status_code;
return DOOR_HTTP_ERR_FAIL;
}
static esp_err_t door_http_ota_update_validate_image_header(esp_app_desc_t* new_app_info)
......
This diff is collapsed.
1.0.2.1
\ No newline at end of file
1.0.3.0
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment