From e368dd50dc182b9604a3a2a000e74d96592c2f91 Mon Sep 17 00:00:00 2001 From: "Hansi, dl9rdz" Date: Sat, 29 May 2021 14:03:28 +0200 Subject: [PATCH] +time check for SondeHub --- RX_FSK/RX_FSK.ino | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/RX_FSK/RX_FSK.ino b/RX_FSK/RX_FSK.ino index 7739100..43e4774 100644 --- a/RX_FSK/RX_FSK.ino +++ b/RX_FSK/RX_FSK.ino @@ -3015,6 +3015,8 @@ const char *dfmSubtypeStrSH[16] = { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL }; +// in hours.... max allowed diff UTC <-> sonde time +#define SONDEHUB_TIME_THRESHOLD (3) void sondehub_send_data(WiFiClient *client, SondeInfo *s, struct st_sondehub *conf) { Serial.println("sondehub_send_data()"); @@ -3060,16 +3062,23 @@ void sondehub_send_data(WiFiClient *client, SondeInfo *s, struct st_sondehub *co } struct tm timeinfo; - if(!getLocalTime(&timeinfo, 0)){ + time_t now; + time(&now); + gmtime_r(&now, &timeinfo); + if(timeinfo.tm_year <= (2016-1900)) { Serial.println("Failed to obtain time"); return; } + if( abs(now - s->time) > (3600*SONDEHUB_TIME_THRESHOLD) ) { + Serial.println("Sonde time too far from current UTC 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 } - ts = *gmtime(&t); + gmtime_r(&t, &ts); memset(rs_msg, 0, MSG_SIZE); w = rs_msg;