WAF - Wife acceptance factor


#1

So I’ve got a Particle powered doorbell which has been working reliably for ages now. It does more than monitor a single button, by the way, this isn’t IoT overkill!

Only yesterday for at least about half an hour, the doorbell wasn’t working. Leading to my wife getting complaints from her friends who were trying to gain access at the time! My wife of course passed on the complaints in full to me when I got home. I tried the doorbell and of course, it worked just fine! Arrg. So I didn’t THINK my code was dependent on either a WiFi Connection or a Cloud Connection but maybe it is?! Would you guys mind just checking over a couple of the salient bits of my code to advise if I’m labouring under a misapprehension? Otherwise (short of a loose connection) I’m really unsure what was going on.

SYSTEM_THREAD(ENABLED);
ButtonPressAction doorButton([]() {
    if (Time.hour() >= 7 && Time.hour() <= 22) {
        if (DoorBellPushed == 0 && dooropen == 0) {
            Particle.publish(DEVICE_NAME, FDOOR_MSSG, 60, PRIVATE);
            doorbellLED.on();
            doorbelltimer.start();
            DoorAnswered = 0;
            DoorBellPushed = 1;
            DoorSequence = 1;
            Debounce12v = 1;
            relayPin.on();
            relaytimer.start();
            relaydebouncetimer.start();
        } 
});

then in loop

ButtonPressAction::update();

obviously I can post the entire code if it’s desired, but it’s 500 lines and that’s without the libraries…

thank you if anyone has any pointers!! At this stage I’m thinking it might be preferable to go back to linking the doorbell push directly to bell and then somehow having a Photon safe “tap” off that circuit at logic level to let the Photon know the doorbell has been rung…


#2

Particle.publish most definitely depends on the cloud. If there is no cloud connection it may block for up to 5 minutes. You should always surround any call to Particle publish with a test:

if (Particle.connected()) {
  Particle.publish(...);
}

#3

I’d also make sure to have a failsafe for the case that Time.isValid() == false which could cause the doorbell to be active at night but not when someone wants to come for a :coffee: & :cake: chat behind your back during the day hours :sunglasses:


#4

Thanks - but then, if this is what was causing the code not to execute, at the end of the five minute delay, wouldn’t you then expect the doorbell to sound? As in, doesn’t it just move onto the next line of code? Thank you both, ScruffR too!