Arduino Connectivity


che dispositivo inverte usi?


Hello and Welcome to the Cayenne community!
Can you see for me, when the device goes offline, what is the time of the last data package sent? You can see this in the bottom of the page. Also, when the device is offline, is ti still continues to display values ?
Thank you.


Unfortunately there are currently some known issues with the dashboard incorrectly showing devices offline. If you watch your data it should still be updating. There will be an official announcement when these issues have been fixed.


Thanks all,

I couldn’t see anything weird in the serial monitor, apart from a slight delay. Then the device goes offline in the portal and comes back shortly after.

Ill wait for the official announcement and then loop back if i’m still having issues.


don’t use delay() function. If you have to, don’t delay for more than 1000 (1sec) or you will get disconnects. You could also try adding “;” that runs in the main loop to other parts of your code, perhaps after a delay so it can stay connected to the servers.


Hi @meriksson, we pushed a fix today for Online/Offline status issues for MQTT devices.

I realize that’s not the connectivity you’re using for your device in this thread, so in that sense this doesn’t apply to you, but I wanted to let you know because we have a ESP8266 MQTT Library that you can use to connect your device as a “Bring Your Own Thing” device in Cayenne rather than through the Arduino option, and we believe it to be stable now with regards to online/offline status.

If you instead prefer to troubleshoot the non-MQTT sketch you’ve posted here, I’d be interested in the Serial Monitor output from the Arduino IDE while it is running and having online/offline issues. This may shed some light on whether it is another server side issue on our end, or if it’s the sketch code/something local for you.


I have three Rpi and two Arduinos running. They seem to drop off line randomly as well.

The Arduinos seem to be more stable than the Rpi’s and go off line less often. I generally re-upload the sketches to force a reboot of the Arduinos in our remote offices. I keep the connected by USB to the servers there. Cayenne and MyDevices has proven to be a useful tool for monitoring our remote server rooms with motion, temp and light sensors.

More stability in the Rpi connections would allow us to use them more.


I encounter this behavior with the Arduino Yun, connect via WiFi.
I only have setup a test case, just switching on and off LEDs and I use the example sketch from Cayenne when setting up an actuator --> Light --> Button LED.
Any hints to solved this much appreciated.


Hi @wwerner,

Welcome to the Cayenne community! Thanks for letting us know about this…

Do the Rpi’s come back online on their own? Or do you have to reboot them?



Hi @Silverfern,

Would you mind pasting the sketch code you are using?



Hi @bestes
just that one from mydevices

Cayenne Light Switch Example

This sketch shows how to set up a Light Switch with Cayenne

The Cayenne Library is required to run this sketch. If you have not already done so you can install it from the Arduino IDE Library Manager.

1. In the Cayenne Dashboard add a new Light Switch Widget.
2. Select a digital pin number. Do not use digital pins 0 or 1 since those conflict with the use of Serial.
3. Attach the negative leg of an LED to ground and the other leg to the selected digital pin.
   [Ground] -- [LED] -- [Resistor] -- [Digital Pin]
4. Set the token variable to match the Arduino token from the Dashboard.
5. Compile and upload this sketch.
6. Once the Arduino connects to the Dashboard you can toggle the LED switch.

Notice that there isn't much coding involved to interact with the digital pins.
Most of it is handled automatically from the Cayenne library.

#define CAYENNE_PRINT Serial  // Comment this out to disable prints and save space

// If you're not using the Ethernet W5100 shield, change this to match your connection type. See Communications examples.
#include <CayenneEthernet.h>

// Cayenne authentication token. This should be obtained from the Cayenne Dashboard.
char token[] = "YouWishToKnow";

void setup()

void loop()

The sketch works, I was able to trigger LEDs via Browser and App



Thank you for your reply and follow up. With the Rpi’s I usually have to reboot them to get them back online.

I have been mostly using the web interface while monitoring and not the phone app. But the app is great after hours to check on the server rooms or when I am out of town. I know sometimes there is a delay on the web page and they will come back online in few minutes but aside from the occasional delay it seems when it is really off line it takes a reboot to get the Rpi’s back on line.

When I left the office yesterday they were all on line. This morning when logging in one Arduino was down and one Rpi was down. The Arduino came back on in a minute or so after logging into the web page. The Rpi did not come back after waiting a few minutes so I rebooted and it came back online. This seems typical of the issue.



Hi @Silverfern,

I think I see what the issue may be. The sketch you are using is not made for the Yun.

If you go through the add device process again for adding an Arduino, you should see a specific option come up for the Yun. You should copy and paste that code into your Arduino IDE and use that.

Here’s a pic of what I am referencing…



I used that, I selected the Yun and when I follow the path and select Sketch I get this:


Right. Use the code from the section in the image I pasted. It contains the CayenneYun.h file that is needed.

The sketch file that you are clicking on is not dynamic so it does not produce the Yun specific sketch file.

Alternatively, you can change the #include CayenneEthernet.h> to #include <CayenneYun.h> in your current sketch file.

Does that make sense?



Hi @bestes
Ok I thought i was dynamic.
I will give it a try and change the include.


Hello @bestes

Now it looks stable. Thanks for this hint. ~solved (for me)



Hi @meriksson (and anyone else reading and interested)

After writing up a tutorial today on how to convert from Arduino to Arduino MQTT sketches, I wanted to reach out and see if you could try following it when you have some free time. It should apply to your ESP8266 as well, although you’ll need the Cayenne MQTT ESP8266 library rather than the Arduino one I linked in that tutorial.

I think this would be a good option for you as we believe our MQTT connectivity to be more stable than the original Arduino connectivity, and it should be much more tolerant to the delay() statements in that code as it uses a push design rather than continuous polling which can be thrown off and cause disconnects with large delays.

I want to make myself available to you to assist with switching the code over or any other questions you might have about the difference in the two connectivities.


I can confirm that MQTT is more stable.
I was facing the well known stability issues with my Yun and with Dragino Yun schield on a mega.
I changed to MQTT protocol for YUN and ALL my problems were gone … is working for many days non-stop now :wink:
PS: I started using MQTT on WeMos D1 mini … and it works fine there too … for many days …
@rsiegel … for the Yun I needed to define a new WeMos device so I could get the right credentials to use on a Yun with MQTT … the choice for MQTT is NOT available when defining a Yun Device ??? … could be a suggestion to add this … :slight_smile:


Thanks for the feedback @Jodi, and glad you’re having better stability with MQTT. In short, the Bring Your Own Thing category is intended as a catch-all bucket that you can connect any device with an MQTT client as, including ones that have other connectivity options like Raspberry Pi and Arduino.

We’ll going to be improving the UI for this in the near future so it isn’t as confusing where you need to go to connect each device.