Arduino loose connection with dashboard

Arduino Uno with W5100 ethernet shield

Android

Hello.

I create a program to monitorize a DHT22 sensor. Everything works fine, but after some time the dashboard lose the connetion with arduino.

To run again I have to estart de arduino…

Someone have an idea what could be happen?

Are you able to post what the serial output is when your Arduino goes offline??

-B

“DHT22 test!
[0] Using static IP
[1300] My IP: 255.255.255.255
Humidity: 61.60 % Temperature: 21.80 *C 71.24 *F Heat index: 21.64 *C 70.96 *F
[6589] state 0, tconn 0
[6615] Connecting to arduino.mydevices.com:8442
[6666] Connect failure”

I defined a static ip… 192.168.1.100… I can’t understand why it changes with no apparently reason…

Can you post the sketch?

#include "DHT.h"
#define CAYENNE_DEBUG         // Uncomment to show debug messages
#define CAYENNE_PRINT Serial  // Comment this out to disable prints and save space
#define DHTPIN 2 
#define VIRTUAL_PIN 1
#define VIRTUAL_PIN2 2
#define RELAY_DIGITAL_PIN 4
#define RELAY_DIGITAL_PIN2 7
#include <CayenneEthernet.h>

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

byte arduino_mac[] = { 0xFE, 0x6A, 0xCF, 0xAC, 0x9C, 0xD2 };
IPAddress arduino_ip(192, 168, 1, 100);
IPAddress dns_ip(192, 168, 1, 1);
IPAddress gateway_ip(192, 168, 1, 1);
IPAddress subnet_mask(255, 255, 255, 0);
#define DHTTYPE DHT22   // DHT 22  (AM2302), AM2321
DHT dht(DHTPIN, DHTTYPE);

void setup()
{
   // set digital pin to output
  pinMode(RELAY_DIGITAL_PIN, OUTPUT);
  pinMode(RELAY_DIGITAL_PIN2, OUTPUT);
  Serial.begin(9600);
  Serial.println("DHT22 test!");
  Cayenne.begin(token, arduino_ip, dns_ip, gateway_ip, subnet_mask, arduino_mac);
  dht.begin();
}

void loop()
{
  Cayenne.run();

  // Wait a few seconds between measurements.
  delay(5000);

  // Reading temperature or humidity takes about 250 milliseconds!
  // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
  float h = dht.readHumidity();
  // Read temperature as Celsius (the default)
  float t = dht.readTemperature();
  // Read temperature as Fahrenheit (isFahrenheit = true)
  float f = dht.readTemperature(true);

  // Check if any reads failed and exit early (to try again).
    if (isnan(h) || isnan(t) || isnan(f)){
    Serial.println("Failed to read from DHT sensor!");
    return;
  }

  // Compute heat index in Fahrenheit (the default)
 float hif = dht.computeHeatIndex(f, h);
  // Compute heat index in Celsius (isFahreheit = false)
  float hic = dht.computeHeatIndex(t, h, false);

  Serial.print("Humidity: ");
  Serial.print(h);
  Serial.print(" %\t");
  Serial.print("Temperature: ");
  Serial.print(t);
  Serial.print(" *C ");
  Serial.print(f);
  Serial.print(" *F\t");
  Serial.print("Heat index: ");
  Serial.print(hic);
  Serial.print(" *C ");
 Serial.print(hif);
 Serial.println(" *F");
}

CAYENNE_IN(VIRTUAL_PIN)
{
  // get value sent from dashboard
  int currentValue = getValue.asInt(); // 0 to 1

  // assuming you wire your relay as normally open
  if (currentValue == 0) {
    digitalWrite(RELAY_DIGITAL_PIN, HIGH);
  } else {
    digitalWrite(RELAY_DIGITAL_PIN, LOW);
  }
}
CAYENNE_IN(VIRTUAL_PIN2)
{
  // get value sent from dashboard
  int currentValue = getValue.asInt(); // 0 to 1

  // assuming you wire your relay as normally open
  if (currentValue == 0) {
    digitalWrite(RELAY_DIGITAL_PIN2, HIGH);
  } else {
    digitalWrite(RELAY_DIGITAL_PIN2, LOW);
  }
}
// These functions are called when the Cayenne widget requests data for the Virtual Pin.
CAYENNE_OUT(V0)
{
  Cayenne.virtualWrite(V0, dht.readTemperature());
}

CAYENNE_OUT(V1)
{
  Cayenne.virtualWrite(V1, dht.readHumidity());
}

CAYENNE_OUT(V2)
{
  Cayenne.virtualWrite(V2, dht.readTemperature(true));
}

CAYENNE_OUT(V3)
{
  Cayenne.virtualWrite(V3, dht.readHumidity());
}

CAYENNE_OUT(V4)
{
  Cayenne.virtualWrite(V4, dht.readTemperature(true));
}Preformatted text

Are you shure of the ip address of router?
I think is a problem of dns.
Try to use a simple ping code. Verify the connection in LAN and out LAN.

Yes…

The sketch work’s fine for a period of time (for example 1 hour) with the initials static ip definitions, but after the ip of arduino changes to 255.255.255.255.

Hi,

After a few days I (finally/casually) figured out the cause of my problem.

I simply removed the SD card of the Ethernet shield and I no longer lost the communication between arduino and dashboard.

I can’t understand the relationship between this but… the most important…

It’s solved. :slight_smile:

Thank you guys,

1 Like

Ah, yes, I remember seeing thread about the SD card slot on the shield causing issues. Wonder what the root cause is?

Woohoo! Glad to hear. And thanks for telling us how we resolve, now we can help future people who may have same problem!

-B