+time check for SondeHub

pull/87/head
Hansi, dl9rdz 2021-05-29 14:03:28 +02:00
rodzic faa9fc1630
commit e368dd50dc
1 zmienionych plików z 11 dodań i 2 usunięć

Wyświetl plik

@ -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;