Arduino+Ethernet Shield+Iot

Hi everyone. I made a new project which i get sensor value and post this values to iot server. i run my arduino it work well but after a month or two month later my arduino stops send data to server and if i can't reset arduino it never send data again and ethernet shield's orange led blink continiously. i think arduino lost connection to internet or client stuck one time and try to send over over data to after time. Is there anyone use a stable and continuous sample code for send data to iot server? Thanks for help.

Post your code and the ethernet shield you are using.

my ethernet shield is wiznet W5100 chipset hanrun.
my code is:

#include <OneWire.h>
#include <Ethernet.h>
//#include <SPI.h>
char thingSpeakAddress[] = "thingspeak";
String writeAPIKey = "my api key";
OneWire ds(2); // on pin 10 (a 4.7K resistor is necessary)
OneWire ds_2(3);
float derece1;
int sayma1,sayma2;
char s1[8];
char s2[8];
int sayi,sayma;
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
EthernetClient client;
IPAddress ip(192, 168, 2, 151);
void setup(void) {
Serial.begin(9600);
delay(200);
Ethernet.begin(mac,ip);
delay(1000);
sayma=0;
sayma1=0;
sayma2=0;
Serial.println(Ethernet.localIP());

}

float ds1(float derece1){
byte i;
byte present = 0;
byte type_s;
byte data[12];
byte addr[8];
float celsius, fahrenheit;

if ( !ds.search(addr)) {
ds.reset_search();
delay(250);
}

// the first ROM byte indicates which chip
switch (addr[0]) {
case 0x10:
type_s = 1;
break;
case 0x28:
type_s = 0;
break;
case 0x22:
type_s = 0;
break;
}

ds.reset();
ds.select(addr);
ds.write(0x44, 1); // start conversion, with parasite power on at the end
delay(1000); // maybe 750ms is enough, maybe not
present = ds.reset();
ds.select(addr);
ds.write(0xBE); // Read Scratchpad
for ( i = 0; i < 9; i++) { // we need 9 bytes
data = ds.read();
}
// Convert the data to actual temperature
// because the result is a 16 bit signed integer, it should
// be stored to an "int16_t" type, which is always 16 bits
// even when compiled on a 32 bit processor.
int16_t raw = (data[1] << 8) | data[0];
if (type_s) {

  • raw = raw << 3; // 9 bit resolution default*
  • if (data[7] == 0x10) {*
  • // "count remain" gives full 12 bit resolution*
  • raw = (raw & 0xFFF0) + 12 - data[6];*
  • }*
    } else {
  • byte cfg = (data[4] & 0x60);*
  • // at lower res, the low bits are undefined, so let's zero them*
  • if (cfg == 0x00) raw = raw & ~7; // 9 bit resolution, 93.75 ms*
  • else if (cfg == 0x20) raw = raw & ~3; // 10 bit res, 187.5 ms*
  • else if (cfg == 0x40) raw = raw & ~1; // 11 bit res, 375 ms*
  • //// default is 12 bit resolution, 750 ms conversion time*
    }
    celsius = (float)raw / 16.0;
    fahrenheit = celsius * 1.8 + 32.0;
    derece1=celsius;
    return derece1;
    }
    float ds2(float derece1){
    byte i;
    byte present = 0;
    byte type_s;
    byte data[12];
    byte addr[8];
    float celsius, fahrenheit;

if ( !ds_2.search(addr)) {

  • ds_2.reset_search();*
  • delay(250);*
    }
    // the first ROM byte indicates which chip
    switch (addr[0]) {
  • case 0x10:*
  • type_s = 1;*
  • break;*
  • case 0x28:*
  • type_s = 0;*
  • break;*
  • case 0x22:*
  • type_s = 0;*
  • break;*
    }
    ds_2.reset();
    ds_2.select(addr);
    ds_2.write(0x44, 1); // start conversion, with parasite power on at the end
    delay(1000); // maybe 750ms is enough, maybe not
    present = ds_2.reset();
    ds_2.select(addr); *
    ds_2.write(0xBE); // Read Scratchpad
    for ( i = 0; i < 9; i++) { // we need 9 bytes
    data = ds_2.read();
    _
    }_
    _
    // Convert the data to actual temperature*_
    // because the result is a 16 bit signed integer, it should
    // be stored to an "int16_t" type, which is always 16 bits
    // even when compiled on a 32 bit processor.
    int16_t raw = (data[1] << 8) | data[0];
    if (type_s) {
    * raw = raw << 3; // 9 bit resolution default*
    * if (data[7] == 0x10) {*
    * // "count remain" gives full 12 bit resolution*
    * raw = (raw & 0xFFF0) + 12 - data[6];*
    * }*
    } else {
    * byte cfg = (data[4] & 0x60);*
    * // at lower res, the low bits are undefined, so let's zero them*
    * if (cfg == 0x00) raw = raw & ~7; // 9 bit resolution, 93.75 ms*
    * else if (cfg == 0x20) raw = raw & ~3; // 10 bit res, 187.5 ms*
    * else if (cfg == 0x40) raw = raw & ~1; // 11 bit res, 375 ms*
    * //// default is 12 bit resolution, 750 ms conversion time*
    }
    celsius = (float)raw / 16.0;
    fahrenheit = celsius * 1.8 + 32.0;
    derece1=celsius;
    return derece1;
    }
    int kontrol(){
    if (client.connect("www.google.com.tr", 80)){
    client.stop();
    return 1;
    }
    else{
    * client.stop();*
    * return 0;*
    }
    * }*
    _ void(* resetFunc) (void) = 0; //declare reset function @ address 0_
    void updateThingSpeak(String tsData)
    {
    if (client.connect(thingSpeakAddress, 80))
    *{ *
    * client.println("GET /update?key="+writeAPIKey+"&"+tsData+" HTTP/1.1");*
    * client.println("Host: thingspeak adress);*
    * client.println("Connection: close");*
    * client.println();*
    * Serial.println("value sent");*
    }
    else{
    * Serial.println("can't connect ");*
    * sayma=sayma+1;*
    * if (sayma>3){*
    * client.stop();*
    * delay(2000);*
    * client.flush();*
    * delay(5000);*
    resetFunc();
    * }*
    * }*
    }
    void loop(void) {
    sayi=kontrol();
    if (sayi==0){
    * sayma=sayma+1;*
    * delay(30000);*
    * Serial.println(sayma);*
    }
    else if (sayi==1){
    if(!client.connected())
    {
    * sayma=0;*
    * Serial.println(Ethernet.localIP());*
    * String tamyazi,yazi1,yazi2;*
    * yazi1= "field1=";*
    * yazi2="&field2=";*
    * dtostrf((ds1(derece1)),2,2,s1);*
    * dtostrf((ds2(derece1)),2,2,s2);*
    * tamyazi= yazi1+s1+yazi2+ s2;*
    * updateThingSpeak(tamyazi);*
    * delay(2000);*
    * client.stop();*
    delay(100000);
    }
    }
    if (sayma>3){
    * client.stop();*
    * delay(2000);*
    * client.flush();*
    * delay(5000);*
    resetFunc();
    * }*
    }

What is the output when it fails? Why are you not retrieving and displaying the server's response?

i don't use this arduino in serial. This "serial.write" code for when i try to check code after upload for a one time for check any code problem. if arduino run first time i clear "serial.write" codes. in my project i use arduino with external power cause i cannot see any response or fail code. only i see ethernet shield's orange led blink continuously.

Then there is no way to troubleshoot it. Resetting is your only option.

Thanks for help SurferTim. yes if it doesn't work i am ressetting and works fine. but i check thingspeak iot server public channels too many devices works very long time and can't stop working. i want to know anybody have sample code for like this devices.