automatically fetch ephemeris once per hour on startup

This commit is contained in:
Hansi, dl9rdz 2019-06-02 12:01:58 +02:00
parent 1b192b6471
commit 01cccdcb75
1 changed files with 24 additions and 3 deletions

View File

@ -39,15 +39,36 @@ void geteph() {
return; return;
} }
// Check time of last update
int year = tinfo.tm_year + 1900;
int day = tinfo.tm_yday + 1;
Serial.printf("year %d, day %d\n", year, day);
char nowstr[20];
snprintf(nowstr, 20, "%04d%03d%02d", year, day, tinfo.tm_hour);
File status = SPIFFS.open("/brdc.time", "r");
if(status) {
String ts = status.readStringUntil('\n');
const char *tsstr = ts.c_str();
if(tsstr && strlen(tsstr)>=9) {
if(strcmp(nowstr, ts.c_str())<=0) {
Serial.println("local brdc is up to date\n");
return;
}
}
Serial.printf("now: %s, existing: %s => updating\n", nowstr, tsstr);
}
status.close();
status = SPIFFS.open("/brdc.time","w");
status.println(nowstr);
status.close();
// fetch rinex from server // fetch rinex from server
File fh = SPIFFS.open("/brdc.gz","w"); File fh = SPIFFS.open("/brdc.gz","w");
if(!fh) { if(!fh) {
Serial.println("cannot open file\n"); Serial.println("cannot open file\n");
return; return;
} }
int year = tinfo.tm_year + 1900;
int day = tinfo.tm_yday;
Serial.printf("year %d, day %d\n", year, day);
char buf[256]; char buf[256];
snprintf(buf, 128, "/cors/rinex/%04d/%03d/brdc%03d0.%02dn.gz", year, day, day, year-2000); snprintf(buf, 128, "/cors/rinex/%04d/%03d/brdc%03d0.%02dn.gz", year, day, day, year-2000);
Serial.println("running geteph\n"); Serial.println("running geteph\n");