Go Down

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

awsiukie

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

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
st: 192.168.0.101
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
-----------------------------------------------------
Status:1
new client
GET / HTTP/1.1
User-Agent: Wget/1.14 (linux-gnu)
Accept: */*
Host: 192.168.0.101
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:
https://forum.arduino.cc/index.php?topic=623360.0
https://github.com/arduino-libraries/WiFiNINA/issues/47
https://forum.arduino.cc/index.php?topic=608321.0

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) {
server.begin();
}

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:
-----------------------------------------------------
Status:1
new client
st: 192.168.0.101
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;
  
  odebrana_ramka.crc=0;
  odebrana_ramka.dane.powietrze_temperatura=0;
  odebrana_ramka.dane.powietrze_wilgotnosc=0;
  odebrana_ramka.dane.grunt_wilgotnosc=0;
  odebrana_ramka.dane.lux=0;


  CurrentMillis = millis();

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

      else {
        Serial.println("Niezgodne CRC!");
        Serial1.println("Niezgodne CRC!");
      }
   }
 
    Serial.println("-----------------------------------------------------");
    Serial.print("Status:");
    Serial1.print("Status:");
    server_status=server.status();
    Serial.print(server_status);
    Serial1.print(server_status);
    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) {
      server.begin();
      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();
        Serial.write(c);
        // 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();
          client.println("<!DOCTYPE HTML>");
          client.println("<html>");
          
          client.print("temperatura powietrza:");
          client.print(dane_pogodowe.powietrze_temperatura);
          client.println("<br />");
          client.print("wilgotnosc powietrza:");
          client.print(dane_pogodowe.powietrze_wilgotnosc);
          client.println("<br />");
          client.print("wilgotnosc gruntu:");
          client.print(dane_pogodowe.grunt_wilgotnosc);
          client.println("<br />");
          client.print("LUX:");
          client.print(dane_pogodowe.lux);
          client.println("<br />");
          client.print("reset in (s):");
          client.print( (reset_call-CurrentMillis)/1000 );
          client.println("<br />");
          client.println("</html>");
          break;
        }
        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
    delay(10);

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



BR
Lukas

pert

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:
https://www.arduino.cc/en/Main/Software#hourly
Same installation process as usual.

Also reported at:
https://github.com/arduino/Arduino/issues/9085

Go Up