From 89581085ab06addc85036865698af7d8af106de6 Mon Sep 17 00:00:00 2001 From: Dave Akerman Date: Tue, 10 Oct 2023 16:17:32 +0100 Subject: [PATCH] V1.10.5 - fully handle all documented return codes from Sondehub uploads --- README.md | 3 +++ gateway.c | 2 +- global.h | 2 -- sondehub.c | 21 ++++++++++++++++++--- 4 files changed, 22 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index e67a2a3..55e6200 100644 --- a/README.md +++ b/README.md @@ -296,6 +296,9 @@ Many thanks to David Brooke for coding this feature and the AFC. Change History ============== +## 08/10/2023 - V1.10.5 + Fully handle all documented Sondehub responses - see https://github.com/projecthorus/sondehub-infra/wiki/API-(Beta)#notes-on-api-response-codes + ## 14/9/2023 - V1.10.4 Clear InUse flag in SH upload so new telemetry is only uploaded once diff --git a/gateway.c b/gateway.c index 4e6f12a..204fe3e 100644 --- a/gateway.c +++ b/gateway.c @@ -45,7 +45,7 @@ #include "udpclient.h" #include "lifo_buffer.h" -#define VERSION "V1.10.4" +#define VERSION "V1.10.5" bool run = TRUE; // RFM98 diff --git a/global.h b/global.h index 87ad56d..90a9a2d 100644 --- a/global.h +++ b/global.h @@ -116,9 +116,7 @@ struct TConfig double latitude, longitude, altitude; // Receiver's location int EnableSSDV; - int EnableHablink; int EnableSondehub; - char HablinkAddress[32]; int EnableTelemetryLogging; int EnablePacketLogging; int CallingTimeout; diff --git a/sondehub.c b/sondehub.c index bf3c57f..8da6b47 100755 --- a/sondehub.c +++ b/sondehub.c @@ -106,22 +106,37 @@ int UploadJSONToServer(char *url, char *json) res = curl_easy_perform( curl ); // Check for errors - if ( res == CURLE_OK ) + if (res == CURLE_OK) { curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &http_resp); if (http_resp == 200) { + // Data submitted OK result = true; } - else if (http_resp == 400) + else if ((http_resp >= 201) && (http_resp <= 209)) { - LogMessage("400 response to %s\n", json); + //Data submitted, but with some issues. Refer to response for details. + LogMessage("20x response to %s\n", json); + LogError(http_resp, "JSON: ", json); + LogError(http_resp, "RESP: ", curl_error); + result = true; // Don't retry - this partially failed due to the uploaded JSON containing something that the server complained about + } + else if ((http_resp >= 400) && (http_resp <= 409)) + { + LogMessage("%d response to %s\n", http_resp, json); LogError(http_resp, "JSON: ", json); LogError(http_resp, "RESP: ", curl_error); result = true; // Don't retry - this failed due to the uploaded JSON containing something that the server rejected } + else if ((http_resp >= 500) && (http_resp <= 509)) + { + // Server busy, retry + result = false; + } else { + // Undocumented response; log but don't retry LogMessage("Unexpected HTTP response %ld for URL '%s'\n", http_resp, url); LogError(http_resp, "JSON: ", json); LogError(http_resp, "RESP: ", curl_error);