Post topics, source code that relate to the Arduino Platform

User avatar
By kinematik
#65482 My project has an Arduino Zero board (Atmel Cortex ARM M0+ Plus) as the main MCU that comunicates succesfully to a ESP-12 module, using the Standard hardware UART (115200bps).

This the firmware that my ESP8266 module is using:
Code: Select allAT version:1.1.0.0(May 11 2016 18:09:56)
SDK version:1.5.4(baaeaebb)
Ai-Thinker Technology Co. Ltd.


I am using the bportaluri/WIFIEsp library to communicate with the ESP module using stardar AT Commands. I am posting information to an influxDB server, and it is working, although I can see the SEND FAIL message coming back to the main MCU, and also after some time the main MCU freezes.

This is the relevant part of my code:
In Setup:
Code: Select all#include "WiFiEsp.h"              // ESP8266 WiFi Library
#include "WiFiEspUdp.h"           // ESP8266 Wifi UDP Library (NTP Server)

WiFiEspClient WiFiClient;       // Wifi Client
WiFiEspServer WiFiServer(80);   // Wifi Server
WiFiEspUDP Udp;                 // UDP instance -> send / receive packets over UDP

Serial1.begin(115200);              // UART (Serial1, pins 0,1) -> ESP8266
delay(50);

WiFi.init(&UART);                             // Wifi Module Serial Init

while ( WiFistatus != WL_CONNECTED) {         // AP Connection: attempt to connect to WiFi network
   
 // Connect to WPA/WPA2 network
    WiFistatus = WiFi.begin(ssid, wifiPass);
}


In Loop:
Code: Select all    // (1) Incoming messages from ESP8266
    while (UART.available()) {              // PUART <- ESP8266
          char c = UART.read();
         SerialUSB.print(c);
    }
 
    // (2) POST to INFLUXDB SERVER
    //    measurement[,tag_key1=tag_value1...] field_key=field_value[,field_key2=field_value2] [timestamp]
    if ( (millis() - WIFITime) >= COM_WIFI_INTERVAL )  {
 
         WIFITime = millis();

         // Building POST Body (Payload): InfluxDB:Measurement + tags
         char payload[128] = "";

         sprintf(payload, "%s,HwID=%s,CustID=%s,Zone=%s,Loc=%s V=%03d.%01d,IA=%03d.%01d,PFA=%01d.%02d,WA=%05d,VAR=%05d,VA=%05d", \
                          DataMeasurement, TagHwID, TagCustomerID, TagZone, TagLoc,                         \
                          (int)Meter.getVRMS(), abs((int)(Meter.getVRMS()*10)%10),                          \
                          (int)Meter.getIRMSA(), abs((int)(Meter.getIRMSA()*10)%10),                        \
                          (int)Meter.getPowerFactorA(), abs((int)(Meter.getPowerFactorA()*10)%10),          \
                          (int)Meter.getActiveA(), (int)(Meter.getReactiveA()), (int)(Meter.getApparentA()) );

         // Server POST Function
         POSTData(payload);
    }


Finally the POST Function:
Code: Select allvoid POSTData(char* Body) {

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

       // 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.println("Accept: */*");
       WiFiClient.println("User-Agent: Arduino/1.1");
       WiFiClient.println("Connection: close");
       WiFiClient.println("Content-Type: text/plain");
       WiFiClient.print("Content-Length: ");
             WiFiClient.println(strlen(Body)-1);
       WiFiClient.println();
       WiFiClient.println(Body);                       // -> Body

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

    } else {
     
       WiFiClient.stop();
    }
}


Everything is clear and itorks for 10 minutes, however this is the result in the Serial Monitor when I enable thedebug option:
Code: Select all[WiFiEsp] Initializing ESP module
> wifiDriverInit
----------------------------------------------
>> AT
AT


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

> reset
----------------------------------------------
>> AT+RST
AT+RST


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

----------------------------------------------
>> ATE0
ATE0


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

----------------------------------------------
>> AT+CWMODE=1

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

----------------------------------------------
>> AT+CIPMUX=1

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

----------------------------------------------
>> AT+CIPDINFO=1

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

----------------------------------------------
>> AT+CWAUTOCONN=0

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

----------------------------------------------
>> AT+CWDHCP=1,1

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

> getFwVersion
----------------------------------------------
>> AT+GMR
AT version:1.1.0.0(May 11 2016 18:09:56)
SDK version:1.5.4(baaeaebb)
Ai-Thinker Technology Co. Ltd.
Jun 13 2016 11:29:20
OK
---------------------------------------------- > 1.5.4

[WiFiEsp] Initilization successful - 1.5.4
> getConnectionStatus
----------------------------------------------
>> AT+CIPSTATUS
STATUS:5

OK
---------------------------------------------- > 5

> getMacAddress
----------------------------------------------
>> AT+CIFSR
+CIFSR:STAIP,"0.0.0.0"
+CIFSR:STAMAC,"a0:20:a6:01:0b:30"

OK
---------------------------------------------- > a0:20:a6:01:0b:30
>> AT+CWLAP
+CWLAP:(,"MOVISTAR_C97C",,"34:57:60:9b:c9:7d",1,5,0)
+CWLAP:(,"WLAN_8EC8",,"f8:3f:59:d3:f3:e9",3,1,0)

OK
---------------------------------------------- > 2
> wifiConnect
----------------------------------------------
>> AT+CWJAP_CUR="WLAN_8EC8","MYWAPPASSWORD"
WIFI CONNECTED
WIFI GOT IP

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

[WiFiEsp] Connected to WLAN_8EC8
18701 (SETUP)   Connection to the network SSID: > getCurrentSSID
----------------------------------------------
>> AT+CWJAP?
+CWJAP:"WLAN_8EC8","f8:3f:59:d3:f3:e9",3,-73

OK
---------------------------------------------- > WLAN_8EC8

WLAN_8EC8
> getIpAddress
----------------------------------------------
>> AT+CIFSR
+CIFSR:STAIP,"192.168.1.41"
+CIFSR:STAMAC,"a0:20:a6:01:0b:30"

OK
---------------------------------------------- > 192.168.1.41   

      IP Address: 192.168.1.41
> getCurrentRSSI
----------------------------------------------
>> AT+CWJAP?
+CWJAP:"WLAN_8EC8","f8:3f:59:d3:f3:e9",3,-73

OK
---------------------------------------------- > 73

      Signal strength (RSSI):-73 dBm
[WiFiEsp] Connecting to www.voliot.tech
> startClient www.XXXXXX.tech 8086
----------------------------------------------
>> AT+CIPSTART=3,"TCP","www.XXXXXX.tech",8086
3,CONNECT

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

19174 (5.2)   Connected to server: www.XXXXXX.tech
POST /write?db=Test HTTP/1.1

Host: www.XXXXXX.tech
Authorization: Basic XXXXXXXXXXX
Accept: */*
User-Agent: Arduino/1.1
Connection: close
Content-Type: text/plain
Content-Length: 105

testv1,HwID=17060A01,CustID=X170,Zone=SE,Loc=Floor2 V=242.3,IA=000.0,PFA=0.00,WA=00000,VAR=-0001,VA=00020
> 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 37

OK
>
Recv 37 bytes

SEND OK
> sendData: 3 2

OK
>
Recv 2 bytes

SEND OK
> sendData: 3 11

OK
>
Recv 11 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.ZZZ,8086:HTTP/1.1 204 No Content
Content-Type: application/json
Request-Id: 04b6510f-2f62-11e7-8b49-000000000000
X-Influxdb-Version: 1.2.2
Date: Tue, 02 May 2017 18:06:09 GMT
Connection: close

3,CLOSED
[b][color=#000080][size=150][size=200]SEND FAIL
[WiFiEsp] >>> TIMEOUT >>>
[WiFiEsp] Data packet send error (2)
[WiFiEsp] Failed to write to socket 3[/size][/size][/color][/b]



Any help?, what is happening?, do you recommend me some other Arduino library to communicate using the standard AT commandS?