Arduino Connectivity

Hi all,

My arduino keeps randomly disconnecting from the dash board (chrome) and then comes back… Its intermittent.

Its a Wimos D2. Sketch below, but basically it polls from serial and sends the information to a virtual pin.
I put in a delay into the main loop of 5000ms to see if that helped, and it actually made it worse.
Any help would be appreciated.

#include <ModbusMaster.h>
#include <ESP8266WiFi.h>
#include “CayenneDefines.h”
#include “BlynkSimpleEsp8266.h”
#include “CayenneWiFiClient.h”
const int debug = 1; //change to 0 when you are finished debugging
float bvoltage, ctemp, btemp, bremaining, lpower, lcurrent, pvvoltage, pvcurrent, pvpower;

// instantiate ModbusMaster object
ModbusMaster node;

// put something here if you want it to occur before or after transmission to the serial interface…i.e. delay etc. I have these blank and it works fine
void preTransmission()


void postTransmission()


// Cayenne authentication token. This should be obtained from the Cayenne Dashboard.
char token = “ubyb8ppfx0”;

char ssid = “Swamp”; // your network SSID (name)
char pass = “martyman123”; // your network password
// Virtual Pin of the widget.
#define VIRTUAL_PIN V1
#define VIRTUAL_PIN2 V2
#define VIRTUAL_PIN3 V3
#define VIRTUAL_PIN4 V4
#define VIRTUAL_PIN5 V5
#define VIRTUAL_PIN6 V6
#define VIRTUAL_PIN7 V7
#define VIRTUAL_PIN8 V8
#define VIRTUAL_PIN9 V9

void setup()

// Modbus communication runs at 115200 baud → you can make this slower if you want, but works fine either way. I would suggest unplugging the RS485 from the ESP when you are uploading the code. Plug it back in as soon as the code successfully uploads

// Modbus slave ID 1 → this is the default for the 2210, so shouldn’t need to change
node.begin(1, Serial);
// Callbacks allow us to configure the RS485 transceiver correctly

Cayenne.begin(token, ssid, pass);


bool rs485DataReceived = true;

void loop()
uint8_t result,time1, time2, time3, date1, date2, date3, dateDay, dateMonth, dateYear, timeHour, timeMinute, timeSecond;
// uint16_t data[6];
char buf[10];
String dtString;

if (debug == 1){
Serial.print("Beginning Loop ");


//Get Date and Time, and update Controller Data and Time


// Read 20 registers starting at 0x3100)

result = node.readInputRegisters(0x3100, 20);
if (result == node.ku8MBSuccess)
if (debug == 1){
Serial.print("Controller Temperature: ");
ctemp = node.getResponseBuffer(0x11)/100.0f;
if (debug == 1){
Serial.print("Battery Voltage: ");
bvoltage = node.getResponseBuffer(0x04)/100.0f;
if (debug == 1){
Serial.print("Load Power: ");
lpower = ((long)node.getResponseBuffer(0x0F)<<16|node.getResponseBuffer(0x0E))/100.0f;
if (debug == 1){
Serial.print("Load Current: ");
lcurrent = (long)node.getResponseBuffer(0x0D)/100.0f;
if (debug == 1){
Serial.print("PV Voltage: ");
pvvoltage = (long)node.getResponseBuffer(0x00)/100.0f;
if (debug == 1){
Serial.print("PV Current: ");
pvcurrent = (long)node.getResponseBuffer(0x01)/100.0f;
if (debug == 1){
Serial.print(“PV Power: “);
pvpower = ((long)node.getResponseBuffer(0x03)<<16|node.getResponseBuffer(0x02))/100.0f;
if (debug == 1){
rs485DataReceived = false;


result = node.readInputRegisters(0x311A, 2);
if (result == node.ku8MBSuccess)
if (debug == 1){
Serial.print("Battery Remaining %: ");
bremaining = node.getResponseBuffer(0x00)/1.0f;
if (debug == 1){
Serial.print(“Battery Temperature: “);
btemp = node.getResponseBuffer(0x01)/100.0f;
if (debug == 1){
rs485DataReceived = false;


// Read data from the sensor and send it to the virtual channel here.
// You can write data using virtualWrite or other Cayenne write functions.
// For example, to send a temperature in Celsius you can use the following:
//unsigned int uS =; // Send ping, get ping time in microseconds (uS).
//Cayenne.virtualWrite(VIRTUAL_PIN,(uS / US_ROUNDTRIP_CM/2));
/* The following trigPin/echoPin cycle is used to determine the
distance of the nearest object by bouncing soundwaves off of it. */

float result = (100);


su che cosa lo usi? inverter aurora?

Its used to pull information from a solar charge controller - i.e. how much power is coming from the solar panels, whats the load on the system, how much battery left etc

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.

1 Like

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.

1 Like

Hello @bestes

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


1 Like