diff --git a/README.md b/README.md index 13ceb23..60b5558 100644 --- a/README.md +++ b/README.md @@ -124,7 +124,7 @@ The global options are: EnableHabitat=. Enables uploading of telemetry packets to Habitat. - EnableSondhub=. Enables uploading of telemetry packets to the amateur Sondehub system. + EnableSondehub=. Enables uploading of telemetry packets to the amateur Sondehub system. EnableSSDV=. Enables uploading of SSDV image packets to the SSDV server. @@ -295,6 +295,10 @@ Many thanks to David Brooke for coding this feature and the AFC. Change History ============== +## 24/09/2222 - V1.9.5 + + Sondehub datetime field now contains payload timestamp plus current UTC date, corrected if necessary for UTC being the day after the telemetry was created (i.e. telemetry just before midnight UTC received just after midnight) + ## 24/09/2222 - V1.9.4 Include UKHAS sentence as "raw" value sent to sondehub/amateur diff --git a/a.out b/a.out new file mode 100755 index 0000000..79a606a Binary files /dev/null and b/a.out differ diff --git a/gateway.c b/gateway.c index 0876507..1b8dd16 100644 --- a/gateway.c +++ b/gateway.c @@ -47,7 +47,7 @@ #include "udpclient.h" #include "lifo_buffer.h" -#define VERSION "V1.9.4" +#define VERSION "V1.9.5" bool run = TRUE; // RFM98 diff --git a/sondehub.c b/sondehub.c index 5fa7ec4..83c49b1 100755 --- a/sondehub.c +++ b/sondehub.c @@ -1,3 +1,6 @@ +#define __USE_XOPEN +#define _GNU_SOURCE +#include #include #include #include @@ -223,21 +226,38 @@ void ExtractFields(char *Telemetry, char *ExtractedFields) // LogMessage("Extracted: '%s'\n", ExtractedFields); } +void BuildPayloadTime(char *Result, char *TimeInSentence, struct tm *tm) +{ + struct tm tm2; + + memcpy(&tm2, tm, sizeof(tm2)); + + strptime(TimeInSentence, "%H:%M:%S", &tm2); + + // Test for payload time being yesterday + + if ((tm2.tm_hour == 23) && (tm->tm_hour == 00)) + { + tm2.tm_mday--; + timegm(&tm2); + } + + strftime(Result, 32, "%Y-%0m-%0dT%H:%M:%SZ", &tm2); +} + int UploadSondehubPosition(int Channel) { char url[200]; - char json[1000], now[32], doc_time[32], ExtractedFields[256], uploader_position[256]; + char json[1000], now[32], payload_time[32], ExtractedFields[256], uploader_position[256]; time_t rawtime; - struct tm *tm, *doc_tm; + struct tm *tm; // Get formatted timestamp for now - time( &rawtime ); - tm = gmtime( &rawtime ); - strftime( now, sizeof( now ), "%Y-%0m-%0dT%H:%M:%SZ", tm ); + time(&rawtime); + tm = gmtime(&rawtime); + strftime(now, sizeof(now), "%Y-%0m-%0dT%H:%M:%SZ", tm); - // Get formatted timestamp for doc timestamp - doc_tm = gmtime( &rawtime ); - strftime(doc_time, sizeof( doc_time ), "%Y-%0m-%0dT%H:%M:%SZ", doc_tm); + BuildPayloadTime(payload_time, SondehubPayloads[Channel].Time, tm); // Find field list and extract fields ExtractFields(SondehubPayloads[Channel].Telemetry, ExtractedFields); @@ -277,7 +297,7 @@ int UploadSondehubPosition(int Channel) "\"uploader_antenna\": \"%s\"" "}]", Config.Version, Config.Tracker, now, - SondehubPayloads[Channel].Payload, doc_time, + SondehubPayloads[Channel].Payload, payload_time, SondehubPayloads[Channel].Latitude, SondehubPayloads[Channel].Longitude, SondehubPayloads[Channel].Altitude, SondehubPayloads[Channel].Frequency, Config.LoRaDevices[Channel].SpeedMode,