Open matthijskooijman opened 3 years ago
To feed the GPS time to the RTC:
uint32_t unixt = unixTimestamp(myGPS.getYear(),myGPS.getMonth(),myGPS.getDay(),myGPS.getHour(),myGPS.getMinute(),myGPS.getSecond());
RTC.setEpoch(unixt);
(Here, myGPS
is an SFE_UBLOX_GPS
object, code should be adapted for whatever library we'll be using)
To implement waking up at a specific moment in time, you can set an RTC alarm for that time and then just call STM32L0.stop()
without arguments. e.g.:
time_t t = ...;
struct tm tm;
gmtime_r(&t, &tm);
RTC.setAlarmTime(tm.tm_hour, tm.tm_min, tm.tm_sec);
RTC.setAlarmDay(tm.tm_mday);
RTC.enableAlarm(RTC.MATCH_HHMMSS);
RTC.attachInterrupt(alarmMatch);
The above examples were taken from https://github.com/LacunaSpace/LibLacuna/tree/phase-I-release/examples/automated-satellite-uplink
Also note that this requires a new radio protocol, since the current protocol assumes that the time of transmission is the same as the time of measurement.
MJS2020 has an accurate RTC that stays running during sleep, so allows accurate timing of measurements. By feeding the GPS time into the RTC, this also allows nodes to have an absolute sense of time.
Combined, these two things allow nodes to coordinate their measurements (i.e. have all nodes measure at exactly the whole hour, a quarter passed, etc.).
Note that data transmission still needs to be randomized, so nodes would measure at one point in time and then need a random delay before sending their data.