ENC28J60 & lag

Hello
I made a little DIY to store values of temps sensors in a Mysql Db & display to an lcd 20*4
everything works well but after a random time arduino stops logging.

I’m an Rpi as a webserver (php, & mysql)
and an Arduino nano + ENC28J60 with <UIPEthernet.h> lib+ lcd20*4 lcd1602 i2c + dht11 + dht22, and I desabled the code part of the soil sensor to drop water.

Here is a part of the code

if(millis() - milis_time >= 59999 || millis() <= 1000){
    milis_time = millis();
   SaveToMysql(DHT11temp, DHT11hum, DHT22temp, DHT22hum);

& here is the SaveToMysql function

float SaveToMysql(float dht11temp, float dht11hum, float dht22temp, float dht22hum){
  lcd.setCursor(0, 3);
  lcd.print("Connect apache. ");
  delay(1000);
  lcd.setCursor(0, 3);
  if (client.connect(server, 80)) {
    Serial.print("connected");
    client.print("GET /lemmy/add.php?");
    client.print("dht11temp=");
    client.print(dht11temp);
    client.print("&&");
    client.print("dht11hum=");
    client.print(dht11hum);
    client.print("&&");
    client.print("dht22temp=");
    client.print(dht22temp);
    client.print("&&");
    client.print("dht22hum=");
    client.print(dht22hum);
    client.println(" HTTP/1.0");
    client.println();
    lcd.print(client.read());
  } else {
    Serial.println("Connection failed");
  }
    char c = client.read();
    //lcd.setCursor(0, 3);
   // Serial.print(c);
   // lcd.print(c);

    if (client.available()) {
        char c = client.read();
        Serial.print(c);
        lcd.print(c);
      }

    if (!client.connected()) {
      //Ethernet.init(mac);
      Serial.println("disconnecting.");
      lcd.print("disconnecting.");
      client.stop();
      //Ethernet.begin(mac, ip);
      // for(;;)
      // ;
    }
}

any help will be welcome :slight_smile:

What is a randon time ? For example a few minutes until an hour and more ? It could be a voltage regulator shutting down because it is getting hot. It could be a library that goes wrong. It could be interrupts causing delays. It could be hundred other things.

It is (almost) impossible to say.

Can you run a few tests ? Disable parts of the code, to see if that changes anything. I use defines with ENABLE_ for that.

//          #define ... to enable it.
//          // #define ... to disable it.
#define ENABLE_DHT22

#ifdef ENABLE_DHT22
// Here your code for the DHT22
#endif

Hi Peter_n, thx for the answer By random time I mean a variable time, sometimes it does not work for an hour or two (data logging) sometimes it jumps 2 or 3 loops

I disabled lcd, & BH1750FVI libs and unplugged them from the circuit. and i'v got the same probleme & then I tested the sketch with 5000ms in the loop, as you can see in the log i attached data logging is not logging every 5000ms wich means that logging don't work every time I run the SaveToMysql function

https://dl.dropboxusercontent.com/u/74653071/dht22.sql

I don't know what it could be. Sorry. There is too much going on. Perhaps you run into a bug in the UIPEthernet library. Or you run out of memory ( use code at bottom of http://playground.arduino.cc/Code/AvailableMemory ). It could be a timing problem between the Raspberry Pi and the Arduino. But I don't know how to test that. I have added some delays sometimes. For example after the 'GET' or after the client.connect. Just 1 ms or 5 ms is sometimes enough.

Lately I like to know the number of available bytes, when client.available() is used in a loop.

int n = client.available();
Serial.println( n);

I use that to read the available bytes that are returned. When normal burst of 30 or 400 bytes are returned, everything is okay. When there are 0 bytes availabe for some time, it could be a timing error. The sketch should have a timeout to handle that. However, I don't know how to use that in your code.

If you can't find the problem and no one else knows what to do, you could try it again with an W5100 / W5200 Ethernet Shield.

Hi, Peter :slight_smile:
I optimised my code and used only UIPEthernet lib

after 12-24 hours of use same probleme, it is 13:40 here and the last saved value is at : 1214

1150,1151,1152,1153,1154,1155,1156,1157,1158,1159,1200,1201,1202,1203,1204,1205,1206,1207,1208,1209,1210,1211,1212,1213,1214

Here is my code

#include <SPI.h>
#include <UIPEthernet.h>


byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xAD };
byte ip[] = { 192, 168, 2, 216 };
//byte dnServer[] = { 192, 168, 2, 1 };
//byte gateway[] = { 192, 168, 2, 1 };
byte subnet [] = { 255, 255, 255, 0 };
byte server[] = { 192, 168, 2, 211 }; // Rpi 
EthernetClient client;


float soilSensorVal;
///// Delays values ////////
int sprayTime = 5000000;
int LoopReadDelay = 5000;
////////////////////////////
double maxx = 0.00;
double minn = 100.00;


int soilSensorPinOnOff = 9;

int relayPin = A2;
#define DHT11PIN A3
int soilSensorPin = A0;
int D5 = 5;


long milis_time;
long milis_time_loop;
long milis_time_spray;

void setup() {


  analogReference(EXTERNAL);
  Serial.begin(9600);

  pinMode(soilSensorPin, INPUT);
  pinMode(relayPin, OUTPUT);
  pinMode(soilSensorPinOnOff, OUTPUT);

  digitalWrite(relayPin, LOW);
  digitalWrite(soilSensorPinOnOff, LOW);
  milis_time = 0;
  milis_time_loop = millis();
  milis_time_spray = millis();

  pinMode(D5, OUTPUT);
  Ethernet.begin(mac, ip, subnet);
}

void loop() {

  if(millis() - milis_time >= 59999 || milis_time == 0){


    float DHT22hum = 11.2;
    float DHT22temp = 22.3;
    float DHT11hum = 44.5;
    float DHT11temp = 66.7;

    
    milis_time = millis();
    SaveToMysql(DHT11temp, DHT11hum, DHT22temp, DHT22hum);
    
  }
  

}

void SaveToMysql(float dht11temp, float dht11hum, float dht22temp, float dht22hum){


  int retour = Gedfdfdfdfft( dht11temp,  dht11hum,  dht22temp,  dht22hum);

    if (client.available()) {
        Serial.println();
        Serial.println(client.available());
        Serial.println();
        Serial.println(client.read());
       // lcd.print(c);
      }

    if (!client.connected()) {
      //Ethernet.init(mac);
      Serial.println("disconnecting.");
      client.stop();
    }
}

int Gedfdfdfdfft(float dht11temp, float dht11hum, float dht22temp, float dht22hum){
  if (client.connect(server, 80)) {
    client.print("GET /lemmy/add.php?");
    client.print("dht11temp=");
    client.print(dht11temp);
    client.print("&&");
    client.print("dht11hum=");
    client.print(dht11hum);
    client.print("&&");
    client.print("dht22temp=");
    client.print(dht22temp);
    client.print("&&");
    client.print("dht22hum=");
    client.print(dht22hum);
    client.println(" HTTP/1.0");
    client.println();
    Serial.println("HTTP GET Sent");
    //lcd.print(client.read());
  } else {
    Serial.println("Connection failed");
  }

  Serial.println(client.available());
}

Hi,

I was using the same uipethernet library, and was using a sample to test the ping. It was running fine but all of a sudden after around 5-8 minutes, the ping started to show destination host unreachable. It never worked afterwards unless i reset the arduino, and again after 5 minutes its started happening. I am using arduino uno. Would anyone please explain what is happening here?

Thanks, Debojit

Hi all
just a suggestion from my brief experience: ENC module coupled with an Arduino Uno with very basic server usage using UIPEthernet or Ethercard libraries have given me a big (and I mean a very big!) headache for quite some time. A few months ago I turned to W5200 module and everything went so smooth, absolutely no problem and no hangouts of any sorts. I have developed quite a nice control of my heating system, and so far so good since the start of the winter season last november.
Last week I have returned to the ENC module that was hanging on the lab hoping to give it a second life: again is giving me a big headache.
My two cents suggestions: abandon the ENC unless you really want to waste your time!
Ruben