Hi all, I have a sort of multi-function application I wrote for one of my Photons which basically drives several relays that perform different functions in my garage. This includes turning on and off my outside lights at sunrise and sunset via Weather Underground webhook, several IFTTT button webhooks to trigger relays on and off, and most importantly in this case, a “sequencer” to ring an alarm bell (for fun, not actual security purposes). The bell is technically a fire bell, and it’s triggered by a fire alarm pull I have, so the functions in the code are named as such.
I finally got to test the digital input (my first ever!) last night, but I found that the performance was unreliable when I used a basic check in void loop() to check the state of the input, so I figured it might make sense to use interrupts instead. I read the documentation on interrupts, and implemented what I think is correct, but now my Photon just randomly hangs up on its own, usually shortly after boot. The breathing cyan light will freeze “in place”, and the device goes unresponsive.
It’s possible that I’ve written the worst code in the world, but I think it’s more likely that I’m either misusing interrupts, or I’m locking up the processor via some other function I wrote inappropriately. I did notice that with this code, the device goes unresponsive typically right after a webhook (any webhook) is triggered. For example, I triggered the garageBellControl function, which is supposed to turn on an output for 200 msec, then turn it back off, but all it did was turn the output on; it never got to the next step.
Here’s a link to my code: https://go.particle.io/shared_apps/5b4f39c4d487c461050010f1
I’ve already commented out the attachInterrupt statements for now, but they can be found on lines 50 and 51. All of the functions are below void loop(). The functions triggered by the interrupts start at line 133 and 139, respectively. The basic design I had in mind for most of the functions like garageControl was to use the webhooks to modify an associated bool variable, then each time I loop through void loop(), I check that variable, and if it changed, I change the state of the associated relay output.
Let me know if you have suggestions on any part of the code, or any questions. Thanks!