Go Down

Topic: Web server hangs after like 15minutes (Read 261 times) previous topic - next topic


Jul 18, 2019, 12:02 am Last Edit: Jul 18, 2019, 01:54 pm by awsiukie

Board: Arduino WiFi rev 2 firmware 1.2.1 and 1.2.3 (both tested)

Been doing some simple coding here for my project. It's remote soil monitoring. I have 2 boards where 1 sends the data and 2nd (WiFi Rev 2 - firmware 1.2.1 & 1.2.3 tested) is getting it and show via Web server. Problem that I'm getting with Web Server is that is stops responding on port 80 (SYN_SENT to arduino and nothing happens) but ping still works. I also observe that from time to time it's not completing the connection with client doing this (cutting off begining of client connection- buffer issues?):

Powietrze: temperatura (C)=22.50, Wilgotność (%)=52.70
Grunt: Wilgotność (%)=13, natężenie światła=21
new client
Connection: Keep-Alive

client disonnected
Powietrze: temperatura (C)=22.60, Wilgotność (%)=52.80
Grunt: Wilgotność (%)=13, natężenie światła=26

where correct behaviour is:

Powietrze: temperatura (C)=22.50, Wilgotność (%)=51.90
Grunt: Wilgotność (%)=12, natężenie światła=24
new client
GET / HTTP/1.1
User-Agent: Wget/1.14 (linux-gnu)
Accept: */*
Connection: Keep-Alive

client disonnected
Powietrze: temperatura (C)=22.50, Wilgotność (%)=51.90
Grunt: Wilgotność (%)=12, natężenie światła=24

But that incomplete connection is not a problem as client connects again and gets the data. My worry is that it may leave some garbage and after while having such incomplete connections it stops responding. I'm not sure how to troubleshoot this issue.

I have found few similar issues:

2nd link suggests that it may stop serving on port 80 so it would be good to start server again if that happens, with begin().

I check the status and you can it in the code and serial as: "status:1". After while (~15mins) it may show 0 so i've added this:
if (server.status()!=1) {

But this seems to not bring that back to work. Sometimes it stops working even with status=1 and do not allow to connect. Then i get only few more connections like this:
new client
Connection: Keep-Alive

client disonnected

then nothing works except ping
I'm forced to do RESET. I can do the hard way by adding .end and again creating the server but I don't like such solutions.

Anyone knows why that happens or how to troubleshoot this? or better, how to fix it?

Been forced to do software reset after 10 mins, but that sucks. Dropping just the loop:

void loop() {
  char HC12ByteIn;
  byte incomingByte;
  char incoming_buf[sizeof(frame)];
  char CRC_buf[sizeof(pogoda)];
  int i=0,j=0,server_status=1;
  unsigned int crc=0;

  CurrentMillis = millis();

  if ( CurrentMillis - startMillis >= 1500 ) {
  while (HC12.available()) {              // If HC-12 has data
      incomingByte = HC12.read();
   if (  CurrentMillis - reset_counter >= reset_call ) { resetFunc(); }
   if ( i=sizeof(frame)-1  ) {
      for (i=0;i<sizeof(CRC_buf);i++) {
      if (crc==odebrana_ramka.crc) {
        Serial.print("Powietrze: temperatura (C)=");
        Serial.print(", Wilgotność (%)=");
        Serial.print("Grunt: Wilgotność (%)=");
        Serial.print(", natężenie światła=");

      else {
        Serial.println("Niezgodne CRC!");
        Serial1.println("Niezgodne CRC!");
    Serial.print(", sec to reset:");
    Serial1.print(", sec to reset:");
    Serial.println( (reset_call-CurrentMillis)/1000 );
    Serial1.println( (reset_call-CurrentMillis)/1000 );
    if (server_status!=1) {
      Serial.println("Restarting the server - calling server.beging()");
    startMillis = CurrentMillis;

   if ( dane_pogodowe.grunt_wilgotnosc <40 ) {
      //Serial.println("Włączam pompę --> ON");
      //analogWrite(A5, 0);           // dla przekaźnika z optoizolacją
      analogWrite(A5, 1023);      // dla przekaźnika zwykłego
   else {
    //Serial.println("Wyłączam pompę --> OFF");
    //analogWrite(A5, 1023);        // dla przekaźnika z optoizolacją
    analogWrite(A5, 0);      // dla przekaźnika zwykłego

 // listen for incoming clients
  WiFiClient client = server.available();
  if (client) {
    Serial.println("new client");
    // an http request ends with a blank line
    boolean currentLineIsBlank = true;
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();
        // if you've gotten to the end of the line (received a newline
        // character) and the line is blank, the http request has ended,
        // so you can send a reply
        if (c == '\n' && currentLineIsBlank) {
          // send a standard http response header
          client.println("HTTP/1.1 200 OK");
          client.println("Content-Type: text/html");
          client.println("Connection: close");  // the connection will be closed after completion of the response

          client.println("<!DOCTYPE HTML>");
          client.print("temperatura powietrza:");
          client.println("<br />");
          client.print("wilgotnosc powietrza:");
          client.println("<br />");
          client.print("wilgotnosc gruntu:");
          client.println("<br />");
          client.println("<br />");
          client.print("reset in (s):");
          client.print( (reset_call-CurrentMillis)/1000 );
          client.println("<br />");
        if (c == '\n') {
          // you're starting a new line
          currentLineIsBlank = true;
        } else if (c != '\r') {
          // you've gotten a character on the current line
          currentLineIsBlank = false;
    // give the web browser time to receive the data

    // close the connection:
    Serial.println("client disonnected");



You might try the new NINA firmware 1.2.4. It's available in the hourly build of the Arduino IDE, which you can download here:
Same installation process as usual.

Also reported at:

Go Up