From 35ed5af1a2d59010f6f56eb88b1188d72a4416bf Mon Sep 17 00:00:00 2001 From: Uskompuf <22492406+Uskompuf@users.noreply.github.com> Date: Sat, 29 May 2021 19:17:43 +1000 Subject: [PATCH] get UTC time from NTP server --- RX_FSK/RX_FSK.ino | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/RX_FSK/RX_FSK.ino b/RX_FSK/RX_FSK.ino index e34d9d3..af590d2 100644 --- a/RX_FSK/RX_FSK.ino +++ b/RX_FSK/RX_FSK.ino @@ -3054,6 +3054,18 @@ void sondehub_send_data(WiFiClient *client, SondeInfo *s, struct st_sondehub *co return; } + //Get real UTC time from NTP server + const char* ntpServer = "pool.ntp.org"; + const long gmtOffset_sec = 0; //UTC + const int daylightOffset_sec = 0; //UTC + configTime(gmtOffset_sec, daylightOffset_sec, ntpServer); + + struct tm timeinfo; + if(!getLocalTime(&timeinfo)){ + Serial.println("Failed to obtain time"); + return; + } + if ( s->type == STYPE_RS41 || s->type == STYPE_RS92 || s->type == STYPE_M10 || s->type == STYPE_M20 ) { t += 18; // convert back to GPS time from UTC time +18s } @@ -3082,7 +3094,7 @@ void sondehub_send_data(WiFiClient *client, SondeInfo *s, struct st_sondehub *co "\"sats\": %d," "\"rssi\": %.1f,", version_name, version_id, conf->callsign, - ts.tm_year + 1900, ts.tm_mon + 1, ts.tm_mday, ts.tm_hour, ts.tm_min, ts.tm_sec + s->sec, + timeinfo.tm_year + 1900, timeinfo.tm_mon + 1, timeinfo.tm_mday, timeinfo.tm_hour, timeinfo.tm_min, timeinfo.tm_sec, manufacturer_string[s->type], s->ser, ts.tm_year + 1900, ts.tm_mon + 1, ts.tm_mday, ts.tm_hour, ts.tm_min, ts.tm_sec + s->sec, (float)s->lat, (float)s->lon, (float)s->alt, (float)s->freq, (float)s->hs, (float)s->vs,