Triggers not working offline, backup solutions? [arduino]

Hi, this is my first real project with Cayenne and i’ve been loving everything about it but i am a bit stuck.

I am building a fermentation chamber for home brewing beer, in which the temperature has to stay within a certain range for the yeast not to die (~20°C), so i linked an arduino mega to an ethernet shield 5100 and a couple temperature sensors to act as a simple thermostat, switching on and off a heater plugged into a relay. A little overkill, but i do love the ability to see real-time graphs and all of the other neat web-based features like checking the temperature from the app and sending SMS alerts.

First I set up two basic triggers, one to turn on the heater whenever the temperature goes below a certain threshold and another to turn it off when it’s back in the range.
Yesterday I ran a few tests (without the beer, just a bucket of water as a test) during the day, constantly checking on it, worked like a charm. I went to sleep and when i checked back on it in the morning i found my chamber at a staggering 52°C and the heater still running. Beer would have been completely ruined, but hey no biggie, that’s why we run tests, right?

I found out that the board went offline in the middle of the night and triggers won’t work when arduino isn’t online.
It disconnected during an heating cycle and never got back online to switch it back off.
Now this is a BIG deal for my project, as i cannot afford such an error again. I would trust a plain arduino with my life for such a simple task, but i really don’t want to give up the aforementioned cool web-based features, so i’m asking for community help…

  1. How can i make sure the board doesn’t disconnect on its own when idle (i mean when there’s not an open tab on the project running on my computer or phone)? The home network has been running perfectly, so i guess it’s not a connectivity issue. The “keep a tab open and active at all times” workaround looks like it’s working, but it’s not a long-term solution for sure.
  2. I’d use Cayenne basically as a logging/monitoring solution, so my sketch is just a couple libraries to read from the sensors and a few CAYENNE_OUT() functions for my widgets to read from. All of the if-then choices are made via triggers, because i didn’t want to mess with the loop consisting of only Cayenne.run();. What would happen if i let the arduino take the decision of switching the relay on and off within the loop, with the same exact conditions, only in a more old-fashioned way? This would also solve the delay in the trigger activation that sometimes causes the relay to switch a little late, i guess. Would the loop run even when offline as it would normally do, or does the Cayenne.run command take all of the time, resulting in the whole loop running only once?
  3. Does the CAYENNE_OUT() function provide data only when requested by the active widget on a open webpage or do widgets gather data continuously? If it’s the first, is there a way to store data in the sd card slot so that the widgets don’t skip measurements should the board is idle/offline?

Thank you in advance for your help, i’ve been using arduino for quite a while but i’m super new to cayenne!

Tl;Dr Board sometimes goes offline, triggers stop working. Can i code those same triggers in the arduino code so that it runs them itself even when offline?

Most certanly you can, Marfie never sleeps but keeping thermostate code on “your side” and not on net at least you eliminate one chance for him to act :slight_smile:

Write the Temperature on and off to work inside arduino, and use data loging as you do now with Cayenne.

As for data sending, you have both options available which one you use depends on the coding.

@giacomo1574 welcome to cayenne community.

First of all if you can try shifting cayenne arduino library to cayenne MQTT library which is more stable : Converting Cayenne Arduino LIbrary sketches to Cayenne MQTT Arduino

you can do this but when connection is lost ,cayenne.loop function waits till connection is reestablished and then continues with rest of the code. so if you do your triggers in arduino code they wont run. so this feature is currently on cayenne roadmap. but there is a workaround, you can try this. Arduino Online/Offline Override

Oh no, exactly what i feared! Thanks, I’ll try both solutions and i will keep you updated

1 Like