UIPEthernet problems sending data when interval gets to big

Hey everyone

I’m on a project to Log data from a remote ATTiny with DHT and RH 433MHz Transmitter.
The receiving Uno has a DHT Sensor, a Receiver counterpart and a mini ENC28j60 Network adapter.

I was able to get all the parts up and running when isolated but not when all work together. For some time I thought RH and Ethernet don’t go along well - but a lot of testing and tuning shows me now, that RH has nothing to do with it.

In my testing sketch I cleared out quite a lot. RH is not part of it anymore, so the ATTiny is also gone.
Im only collecting some local DHT data and sending this to a server over and over again. First 5 Times with no delay, then again 5 times with 1 second delay, then with 2 seconds and so on…
As soon as the delay reaches 10 Seconds it gets spooky, no data will be transmitted anymore.

00:37:34.878 -> ##### Sending Data with waittime 9000
00:37:35.638 -> sending data...  ...done
00:37:45.451 -> sending data...  ...done
00:37:55.230 -> sending data...  ...done
00:38:05.063 -> sending data...  ...done
00:38:14.869 -> sending data...  ...done
00:38:23.883 -> ##### Sending Data with waittime 10000
00:38:24.663 -> sending data...  ...done
00:38:35.484 -> sending data...  ...done
00:38:46.283 -> sending data...  ...done
00:38:57.093 -> sending data...  ...done
00:39:07.384 -> Connection could not be established...
00:39:17.398 -> ##### Sending Data with waittime 11000
00:39:17.662 -> Connection could not be established...
00:39:28.968 -> Connection could not be established...
00:39:40.239 -> Connection could not be established...
// DHT related
#include "dht22.h"
#define DHT_PIN PB1 //pin 9 due fastdht22 lib 
dht22 dht;

// Ethernet related (CS:Pin 10, SI:Pin 11, SO:Pin 12, SCK:Pin 13
#include <UIPEthernet.h>
EthernetClient client;
const uint8_t mac[6]  = {0xEC, 0x14, 0x73, 0xCF, 0xD0, 0xF4};
const uint8_t ip[4]   = {192, 168, 0, 20};

int it = 0;  // inside  Temperature
int ih = 0;  // inside  Humidity
int ot = 0;  // outside Temperature
int oh = 0;  // outisde Humidity
byte ob = 0; // outside Battery
char data[40]; // data to be sent to webserver

int i = 0; // counter for number of rows to write

int waittime = 10000;
int count = 0;

void setup() {
  Serial.begin(9600);
  Ethernet.begin(mac, ip);
  dht_init(&dht, DHT_PIN);

  Serial.println(F("init done"));
}

void loop() {
  Serial.print(F("##### Sending Data with waittime "));
  Serial.println(waittime);

  // indicator or counter visible on db
  ob = waittime / 1000;

  // write n rows for testing then increase waittime
  for (int i = 0; i < 5; i++) {

    dht_read_data(&dht, &it, &ih);

    // create a string for add.php eg."it=22.3&ih=45.2&ot=12.0&oh=77.2&ob=90"
    sprintf(data, "it=%2d.%1d&ih=%2d.%1d&ot=%2d.%1d&oh=%2d.%1d&ob=%2d",
    
            it / 10, abs(it % 10), ih / 10, abs(ih % 10), ot / 10, abs(ot % 10), oh / 10, abs(oh % 10), ob);
    
    if (client.connect(IPAddress(192, 168, 0, 11), 80)) {
      Serial.print(F("sending data... "));
      client.println(F("POST /dht/add.php HTTP/1.1"));
      client.println(F("Host: 192.168.0.11"));
      client.println(F("Content-Type: application/x-www-form-urlencoded"));
      client.print(F("Content-Length: "));
      client.println(strlen(data));
      client.println();
      client.print(data);
    } else {
      Serial.println(F("Connection could not be established..."));
    }

    if (client.connected()) {
      client.stop();
      Serial.println(F(" ...done"));
    }
    delay(waittime);
  }
  waittime += 1000;
}

I can’t imagine of a reason why this is. Also because the client always closes the connection. → In my understanding, since a possible previous connection always gets closed (cilent.stop()) , all new connections should be the same procedure and have the same outcome.

Is someone familiar with this behaviour?

Thank you in advance
Best regards

the library handles all the Ethernet traffic so it must be called periodically. if you don't call any function of server or client call Ethernet.maintain().

Juraj:
the library handles all the Ethernet traffic so it must be called periodically. if you don't call any function of server or client call Ethernet.maintain().

Thank you, that's how easy it can be. maintain() every 5 seconds and it works just well :slight_smile: