bportaluri / WiFiEsp

Arduino WiFi library for ESP8266 modules
GNU General Public License v3.0
548 stars 210 forks source link

Crash after 2h #104

Open merlin2539 opened 7 years ago

merlin2539 commented 7 years ago

We have use the libery to send Data as TCP to a Influx DB. After 2h the Arduino are crashes. The Lib of WifiESP tell TIMEOUT for the ESP-01. When we restart it it works correctly. We have try diffecence WifiHotspots and less Data (more Delays)

joaqrus commented 7 years ago

This is exaclty my problem: I am posting to an influxDB server from an Arduino Zero (Cortex ARM M0+), I am not using Hardware serial, but the real UART at 115.200 bps.

This is the relevant part of the code:

void POSTData(char* Body) {

    // (1) Establish TCP connection with Server
    if ( WiFiClient.connect("www.voliot.tech", 8086) ) {

       if (_DEBUG_) {
          SerialUSB.print(millis()); 
          SerialUSB.print(" (5.2)\tConnected to server: ");
          SerialUSB.println(server);
       }

       // Make a HTTP request: Headers + Body  
       WiFiClient.print("POST /write?db=");                       // -> Headers
             WiFiClient.print(influxDB);
             WiFiClient.println(" HTTP/1.1");
       WiFiClient.print("Host: ");
             WiFiClient.println(server);
             //WiFiClient.print(":");
             //WiFiClient.println(port);             
       WiFiClient.println("User-Agent: Arduino/1.1");
       WiFiClient.println("Connection: close");
       WiFiClient.println("Content-Type: text/plain");
       //WiFiClient.println("Content-Type: application/x-www-form-urlencoded");
       WiFiClient.print("Content-Length: ");
             WiFiClient.println(strlen(Body));
       WiFiClient.println();
       WiFiClient.println(Body);                                  // -> Body

       delay(50);
       //WiFiClient.stop();

    } else {

       if (_DEBUG_) {
          NumIntentos++;
          uUSB.print(millis());
          uUSB.print(" (5.2)\tFailed Connection to server: ");
          uUSB.print(server);
          uUSB.print(":");
          uUSB.print(port);
          uUSB.print("\tNº:");
          uUSB.println(NumIntentos);
       }

       WiFiClient.stop(); 

       if (NumIntentos > 5)   {
           WiFi.reset();
       }
    }
}

I received data in my server, however I get the following error from the WifiESP library:

[WiFiEsp] Connecting to www.myserver.tech
93972 (5.2) Connected to server: www.myserver.tech
[WiFiEsp] >>> TIMEOUT >>>
[WiFiEsp] Data packet send error (2)
[WiFiEsp] Failed to write to socket 3
[WiFiEsp] Disconnecting  3

I tried all kind of combinations in the Headers, but I can not get rid of the error message. As explained, although it works for about 40 minutes in my case, the board freezes and needs to be reseted.

joaqrus commented 7 years ago

Any help?

joaqrus commented 7 years ago

And this is what I can see if I enable DEBUG:

> startClient www.myserver.tech 8086
----------------------------------------------
>> AT+CIPSTART=3,"TCP","www.myserver.tech",8086
3,CONNECT

OK
---------------------------------------------- > 0

14719 (5.2) Connected to server: www.myserver.tech
> sendData: 3 15

OK
> 
Recv 15 bytes

SEND OK
> sendData: 3 4

OK
> 
Recv 4 bytes

SEND OK
> sendData: 3 9

OK
> 
Recv 9 bytes

SEND OK
> sendData: 3 2

OK
> 
Recv 2 bytes

SEND OK
> sendData: 3 6

OK
> 
Recv 6 bytes

SEND OK
> sendData: 3 15

OK
> 
Recv 15 bytes

SEND OK
> sendData: 3 2

OK
> 
Recv 2 bytes

SEND OK
> sendData: 3 22

OK
> 
Recv 22 bytes

SEND OK
> sendData: 3 2

OK
> 
Recv 2 bytes

SEND OK
> sendData: 3 17

OK
> 
Recv 17 bytes

SEND OK
> sendData: 3 2

OK
> 
Recv 2 bytes

SEND OK
> sendData: 3 24

OK
> 
Recv 24 bytes

SEND OK
> sendData: 3 2

OK
> 
Recv 2 bytes

SEND OK
> sendData: 3 16

OK
> 
Recv 16 bytes

SEND OK
> sendData: 3 3

OK
> 
Recv 3 bytes

SEND OK
> sendData: 3 2

OK
> 
Recv 2 bytes

SEND OK
> sendData: 3 2

OK
> 
Recv 2 bytes

SEND OK
> sendData: 3 106

OK
> 
Recv 106 bytes

SEND OK
> sendData: 3 2

OK
> 
Recv 2 bytes

+IPD,3,192,207.XXX.YYY.243,8086:HTTP/1.1 204 No Content
Content-Type: application/json
Request-Id: df5f8296-2e89-11e7-86a3-000000000000
X-Influxdb-Version: 1.2.2
Date: Mon, 01 May 2017 16:18:55 GMT
Connection: close

3,CLOSED
SEND FAIL
[WiFiEsp] >>> TIMEOUT >>>
[WiFiEsp] Data packet send error (2)
[WiFiEsp] Failed to write to socket 3
[WiFiEsp] Disconnecting  3
> stopClient 3
----------------------------------------------
>> AT+CIPCLOSE=3
UNLINK

ERROR
---------------------------------------------- > 1
dgelles commented 7 years ago

How do you enable debug?

joaqrus commented 7 years ago

You need to go to the the following library file: WiFiEsp/src/utility/debug.h

You can find it in Github in the following URL: https://github.com/bportaluri/WiFiEsp/blob/master/src/utility/debug.h

Inside the debug.h file, you can find the following C define named ESPLOGLEVEL:

// Change _ESPLOGLEVEL_ to set tracing and logging verbosity
// 0: DISABLED: no logging
// 1: ERROR: errors
// 2: WARN: errors and warnings
// 3: INFO: errors, warnings and informational (default)
// 4: DEBUG: errors, warnings, informational and debug

#define _ESPLOGLEVEL_ 3

Just change it to "4", and then the library will provide all the communications through the UART, including the raw AT Commands, as you saw in my description

sravan7 commented 7 years ago

@merlin2539 @joaqrus @dgelles @SukkoPera @GrahamCobb how can i use this WiFiEsp to connect CoAP client in arduino-uno. Is it working for CoAP also. Can you help me please.