Pi schedules when internet down

I have had Cayenne running on an Arduino Mega for quite a while but am concerned at what may happen if the internet goes down when I am in the middle of a scheduled action i.e. something turned on but doesnt turn off because of the loss of connection.
Soo… I bought a Raspberry Pi B running Rasbian Jessie Lite as I was under the impression that with Pi the schedules are stored locally, once entered on the dashboard?
Setup went OK and I tried toggling a LED on/off on a schedule with the internet available -all OK. Then I entered another schedule and pulled the ethernet cable from the Pi to emulate loss of connection. The schedule did not run.
Should it have?

Yes, schedules should run even when the device is offline. Triggers will require a connection to the Cayenne servers. What was the schedule you had set up?

Hey @cr.stubbs,

I’ve been spending some time with this with our Raspberry Pi agent developer today after seeing your post, and running some sanity tests. The Pi indeed should run events while disconnected from Cayenne, so long as it is powered on and still running our software agent.

In my personal testing, I initially found that sometimes my event would fire with the cable pulled, and sometimes not. I eventually narrowed it down to the timing of when I pulled the cable. It appears that if I pull it within ~25 seconds or so before the fire time, then it would work OK even with the cable pulled. If I did it minutes before, it never fired (what you were seeing).

So effectively, I don’t think it will currently fire the event in most real world cases (unless they were an outage very close to the event time). It looks like once the agent ‘realizes’ it is offline and begins to attempt to reconnect, it causes the event to error and not fire. By pulling the cable so close to the event time, it’s still running normally and thus fires the event OK.

The logs were different in both cases in some very clear ways that already have him on the road to a possible fix. To that end, if you don’t mind zipping up the log file /var/log/myDevices.log and attaching it to an email to support@mydevices.com, I’d like see if your log looks the same as my failure cases. If its too much trouble, no worries, it may not be strictly necessary here.

This is sort of thing we can likely get in the test agent more immediately even if it takes some time to make it into the official agent – if that’s the case I’ll update you as soon as its available and show you how to run the pre-release agent.

Hi,
Thanks for your replies - its a great service you guys offer! I will try to run the code tonight. My schedule was simply - turn light on 8:30pm, turn light off 8:35pm.
While I have you… I am wanting to operate the Raspberry from Cayenne, then send serial signals to my arduino project which currently runs my Xbee radio network. Thing is - I need lots of physical or virtual pins to either toggle or write data to - probably about 80. i.e Cayenne toggles on a button - raspberry tells arduino it is on, arduino sends Xbee signal to turn on, replies that signal is ok (if not, send back to toggle on a two state widget and send SMS etc. Plus Xbee occasionally sends battery voltages from field to arduino hence serial to raspberry to be displayed on Cayenne.
I am doing this OK on the Arduino mega using physical and virtual pins but if we can get the raspberry to run its schedules while it is offline then it would be worth the change over. I think I have mentioned to you already that my great fear is to start an irrigation program and then lose connection and have it stay running!
Any thoughts? The raspberry only has a few GPIO - are there any or enough virtual pins available?
Thanks again,
Craig

We have a couple ways to connect a Raspberry Pi: the Raspberry Pi agent (what you’re using and we’re troubleshooting here – available through the ‘Raspberry Pi’ option in Cayenne), and as “Bring Your Own Thing” (MQTT) device using an MQTT client like the ones we provide in the Cayenne MQTT Python library.

Using the Raspberry Pi agent method, you have the advantage of the agent software kicking off your scheduled tasks while offline (at least when we squash this bug and it’s working that way), but our implementation is fairly rigid – we don’t have any concept of Virtual Pins through that connectivity, so you’re limited to the physical pins on the Pi itself plus a handful of supported GPIO extensions.

Using the MQTT connectivity method, the data communication with Cayenne occurs on virtual ‘channels’ of which you can have thousands and thousands, and you’re in full control of your code more like an Arduino device. The tradeoff is that the agent itself is a very simple bit of code – it just publishes and receives values to and from Cayenne. So you can still use our event scheduler, but more like the Arduino connectivity, you’re beholden to your internet connection (and our server stability) for those events to fire on time.

If you’re comfortable writing/extending code, with both the Arduino and MQTT connectivity methods, you can write code in your sketch file / MQTT client that handles contingency/failsafe cases to handle this. On a Raspberry Pi this means you have the whole Linux OS at your service, so you could just handle scheduling with something like cron and not have to worry about connectivity scenarios in general.

That’s a lot of words to say that there are positives and negatives to consider for either path. :slight_smile:

Ok … thanks for that Rsiegel. Reading through that neither is perfect for my needs. The MQTT option because it is probably beyond my abilities! and I will still have scheduling only through the cloud as I do now with the Arduino anyway. The RPi option because there are not enough GPIO pins.
Just thinking though… if you were able to sort the issues with RPi scheduling, then I could use the RPi to start/stop irrigation PROGRAMS which typically hold 4 or 5 individual valves. Pass that on to the Arduino to carry out the individual Xbee transmissions. Both Arduino and RPi could have icons on the same Cayenne dashboard. That way I would see that say Program 1 is running, which valves are open and any errors and also battery voltages.
That way if connection is dropped - the irrigation will still occur (start and stop), I will just lose the extra info I get from the Arduino. Can you let me know when the issue with RPi schedules running when connection is dropped is sorted out?
Thanks again,
Craig

You could use a GPIO expander like the MCP23017

Hi Rsiegel,
Has there been any action here? I would love to have Cayenne Pi schedules that still run when the internet is down!
Craig

Our Pi developer just checked in a fix for this for code review yesterday, so the process is taking its course.

I know we’re planning to release a new Raspberry Pi agent soon (the same one I’ve been talking about that was intended to fix the 4.9 kernel issues that you may have run into, along with many users on this forum), and we’ve changed things so that it’s no longer blocked by needing an update to our Android app.

There is a good chance this fix will make it into that update, and that it will come sooner than later now that there is no longer a dependency on a new Android version.