The callback is as follows:
Code: Select all
void timeSyncCallback(struct timeval* tv) {
struct tm timeinfo;
Serial.printf("Time dif: tv->tv_sec - rtc.getEpoch() : %ld\n", tv->tv_sec - rtc.getEpoch());
if (tv->tv_sec - rtc.getEpoch() && getLocalTime(&timeinfo)) {
rtc.setTimeStruct(timeinfo);
}
}
Code: Select all
void loop() {
static theSensor sensor = theSensor(false); //false = test data
static int looping = 0;
static unsigned long now = 0;
if (xSemaphoreTake(minuteSemaphore, 0) == pdTRUE) {
now = (rtc.getEpoch());
vector<float> sensorData = sensor.getSensorData();
Observation m = Observation(now, sensorData);
HourCollection.push(m);
if (rtc.getMinute() == 0) { //on the hour
Observation h = HourCollection.getAverage(now);
DayCollection.push(h);
Serial.println(DayCollection.toString());
if (rtc.getHour() == 0) { //on midnight
Observation d = DayCollection.getAverage(now);
YearCollection.push(d);
Serial.println(YearCollection.toString());
}
}
if (++looping == 5) {
looping = 0;
Serial.println("");
Serial.println(HourCollection.toString());
Serial.println(HourCollection.JsonString());
} else {
Serial.print(".");
}
vTaskDelay(10 / portTICK_PERIOD_MS);
}
}
Code: Select all
void ARDUINO_ISR_ATTR onMinute() {
// portENTER_CRITICAL_ISR(&timerMux);
// trigger = millis(); //rtc.getEpoch();
// portEXIT_CRITICAL_ISR(&timerMux);
xSemaphoreGiveFromISR(minuteSemaphore, NULL);
}
Code: Select all
minuteSemaphore = xSemaphoreCreateBinary();
// Set timer frequency to 1Mhz
mTimer = timerBegin(1000000);
// Attach onMinute function to timer.
timerAttachInterrupt(mTimer, &onMinute);
// Set alarm to call onMinute function every second (value in microseconds).
timerAlarm(mTimer, 1000000 * 60, true, 0);