From 0c8cd2cae7b8a84ac98dee2c3a98bec2aa7005cf Mon Sep 17 00:00:00 2001 From: David Brooke Date: Wed, 22 Jul 2015 20:09:50 +0100 Subject: [PATCH 1/3] Fix Tracker callsign uploaded with SSDV data. --- gateway.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gateway.c b/gateway.c index bb4b80a..9c199cd 100755 --- a/gateway.c +++ b/gateway.c @@ -596,7 +596,7 @@ void UploadImagePacket(char *EncodedCallsign, char *EncodedEncoding, char *Encod curl_easy_setopt(curl, CURLOPT_URL, "http://www.sanslogic.co.uk/ssdv/data.php"); /* Now specify the POST data */ - sprintf(PostFields, "callsign=%s&encoding=%s&packet=%s", EncodedCallsign, EncodedEncoding, EncodedData); + sprintf(PostFields, "callsign=%s&encoding=%s&packet=%s", Config.Tracker, EncodedEncoding, EncodedData); curl_easy_setopt(curl, CURLOPT_POSTFIELDS, PostFields); /* Perform the request, res will get the return code */ From 1ec0908fd128bd9673a7ee449a7c8543b345703b Mon Sep 17 00:00:00 2001 From: David Brooke Date: Mon, 5 Sep 2016 20:46:55 +0100 Subject: [PATCH 2/3] Retry habitat upload in case of save conflict --- habitat.c | 45 ++++++++++++++++++++++++++++++--------------- 1 file changed, 30 insertions(+), 15 deletions(-) diff --git a/habitat.c b/habitat.c index e3874c1..f4cee45 100644 --- a/habitat.c +++ b/habitat.c @@ -72,6 +72,8 @@ UploadTelemetryPacket( telemetry_t * t ) struct curl_slist *headers = NULL; time_t rawtime; struct tm *tm; + int retries; + long int http_resp; // Get formatted timestamp time( &rawtime ); @@ -85,7 +87,7 @@ UploadTelemetryPacket( telemetry_t * t ) curl_easy_setopt( curl, CURLOPT_TIMEOUT, 15 ); // RJH capture http errors and report - curl_easy_setopt( curl, CURLOPT_FAILONERROR, 1 ); + // curl_easy_setopt( curl, CURLOPT_FAILONERROR, 1 ); curl_easy_setopt( curl, CURLOPT_ERRORBUFFER, curl_error ); // Avoid curl library bug that happens if above timeout occurs (sigh) @@ -135,21 +137,34 @@ UploadTelemetryPacket( telemetry_t * t ) curl_easy_setopt( curl, CURLOPT_CUSTOMREQUEST, "PUT" ); curl_easy_setopt( curl, CURLOPT_POSTFIELDS, json ); - // Perform the request, res will get the return code - res = curl_easy_perform( curl ); + retries = 0; + do { + // Perform the request, res will get the return code + res = curl_easy_perform( curl ); - // Check for errors - if ( res == CURLE_OK ) - { - // LogMessage("OK\n"); - } - else - { - LogMessage( "Failed for URL '%s'\n", url ); - LogMessage( "curl_easy_perform() failed: %s\n", - curl_easy_strerror( res ) ); - LogMessage( "error: %s\n", curl_error ); - } + // Check for errors + if ( res == CURLE_OK ) + { + curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &http_resp); + if ( http_resp != 201 && http_resp != 409 ) + { + // unhandled response + LogMessage( "Failed for URL '%s'\n", url ); + LogMessage( "curl_easy_perform() failed: %s\n", + curl_easy_strerror( res ) ); + LogMessage( "error: %s\n", curl_error ); + LogMessage( "HTTP response %ld\n", http_resp ); + } + } + else + { + http_resp = 0; + LogMessage( "Failed for URL '%s'\n", url ); + LogMessage( "curl_easy_perform() failed: %s\n", + curl_easy_strerror( res ) ); + LogMessage( "error: %s\n", curl_error ); + } + } while ((http_resp == 409) && (++retries < 5)); // always cleanup curl_slist_free_all( headers ); From c71d7d17a6ca03e88f77329bc263e01e5e4876c0 Mon Sep 17 00:00:00 2001 From: David Brooke Date: Fri, 14 Oct 2016 14:03:38 +0100 Subject: [PATCH 3/3] Tidy up habitat exception reporting --- habitat.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/habitat.c b/habitat.c index 4a4621d..5f27778 100644 --- a/habitat.c +++ b/habitat.c @@ -146,14 +146,9 @@ UploadTelemetryPacket( telemetry_t * t ) if ( res == CURLE_OK ) { curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &http_resp); - if ( http_resp != 201 && http_resp != 409 ) + if (http_resp != 201 && http_resp != 403 && http_resp != 409) { - // unhandled response - LogMessage( "Failed for URL '%s'\n", url ); - LogMessage( "curl_easy_perform() failed: %s\n", - curl_easy_strerror( res ) ); - LogMessage( "error: %s\n", curl_error ); - LogMessage( "HTTP response %ld\n", http_resp ); + LogMessage("Unexpected HTTP response %ld for URL '%s'\n", http_resp, url); } } else