TimeAlarms scheduler

Hi @bko. Thanks for checking on this for me. Here’s my results:

When adding Time.now() back in to replace instances of now() I get the correct time, calibrated for my set timezone again, and it compiles and runs properly.

I do have another issue I’d like your advice on. No matter which way I do it (with or without the #undef now()) I still can’t get the alarms to fire. I might be doing it wrong.

I have a global struct array:

struct ScheduledTime schedule[112];

Then in setup() I have this loop for testing:

for(int i = 0; i < 112;i++) {
    schedule[i].tstamp = Time.now() + (i * 2);
    schedule[i].active = (i%2 ? true : false);
    if(schedule[i].active) {
        AlarmId aid = Alarm.alarmRepeat(schedule[i].tstamp,EnableDoorbell);
        Spark.publish("Alarm set", "Alarm ID: " + String(aid) + " -- " + "Alarm Time: " + Time.timeStr(schedule[i].tstamp));
    } else {
        Alarm.alarmRepeat(schedule[i].tstamp,disableDoorbell);
    }
}

When I monitor the events for this device, all the alarms set to EnableDoorbell report their ID as 255, and none of the alarms (regardless of their task) actually go off. The beginning of my loop() function is:

Alarm.delay(0);

if(doorbellEnabledSchedule) {
    digitalWrite(D7, HIGH);
} else {
    digitalWrite(D7, LOW);
}

At the bottom of my file I have these two callback functions:

void EnableDoorbell() {
    doorbellEnabledSchedule = true;
    Spark.publish("doorbellState","enabled:" + String(schedule[scheduleCurrentEntry].tstamp));
}

void disableDoorbell() {
    doorbellEnabledSchedule = false;
    Spark.publish("doorbellState","disabled:" + String(schedule[scheduleCurrentEntry].tstamp));
}

With this code in appropriate places, it never executes the callbacks. I never get events published, nor a blinking LED.