ESP8266 communication interruption issue
Posted: Mon Sep 17, 2018 11:23 pm
Hi,
I am using ESP8266 WiFi module as an Access point to acquire measurements from field device RTL8195 Module (Ameba). The measurements are received as string and displayed in serial monitor of ESP8266 as shown below:
A01 13.75 37889 61.29 24578 7.074 5.00 -13.75
A01 is the identifier of the field device.
After a few hours of operation the ESP8266 either the AP dies or sleeps and start receiving
A01 0 0 0 0 0 0 0 (communication broken), until I press the RESET button on the ESP8266 to get the measurements like before.
My code on the ESP8266 is shown here:
The code on the field device is attached. Can anyone please help resolve this issue.
I am using ESP8266 WiFi module as an Access point to acquire measurements from field device RTL8195 Module (Ameba). The measurements are received as string and displayed in serial monitor of ESP8266 as shown below:
A01 13.75 37889 61.29 24578 7.074 5.00 -13.75
A01 is the identifier of the field device.
After a few hours of operation the ESP8266 either the AP dies or sleeps and start receiving
A01 0 0 0 0 0 0 0 (communication broken), until I press the RESET button on the ESP8266 to get the measurements like before.
My code on the ESP8266 is shown here:
Code: Select all
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <WiFiUdp.h>
#include <TimeLib.h>
//These are the avariables you can change for your project. For example, change the SSID (network ID), change the ports on both machines.
//The most useful one is the LOOP_DELAY which changes how quicly it refreshes. set to 100ms be default.
char ssid[] = "espAP"; // your network SSID (name)
char password[] = "mPass@54321"; //Set the AP's password
unsigned int localPort = 2390; // local port to listen on
#define LOOP_DELAY 10 //how fast we check for new data
#define ARRAYSIZE 255 //size of message array (255bytes)
#define BAUD_RATE 115200 //serial comunication speed
//global variables
IPAddress ip(192, 168, 4, 1);
IPAddress gateway(192, 168, 4, 1);
IPAddress subnet(255, 255, 255, 0);
IPAddress remoteIp;
int remoteUDPPort;
char packetBuffer[ARRAYSIZE]; //buffer to hold incoming packet
int arraySize = ARRAYSIZE;
char inData[ARRAYSIZE]; // Allocate some space for the string
char inChar; // Where to store the character read
byte aindex = 0; // Index into array; where to store the character
boolean dataToSend = false;
WiFiUDP Udp;
void setup()
{
Serial.begin(BAUD_RATE);
/* You can remove the password parameter if you want the AP to be open. */
WiFi.softAP(ssid, password); //Start AP
// IPAddress myIP = WiFi.softAPIP(); if ever in doubt on this devices IP address you can get it here. Should be 192.168.4.1
Udp.begin(localPort);
WiFi.setSleepMode(WIFI_NONE_SLEEP);
}
void loop() {
while(Serial.available() > 0) //check for something to read from serial port
{
if(aindex < (arraySize-1)) // One less than the size of the array
{
inChar = Serial.read(); // Read a character
inData[aindex] = inChar; // Store it
aindex++; // Increment where to write next
inData[aindex] = '\0'; // Null terminate the string
}
dataToSend = true;
}
//check for incoming data via UDP
int packetSize = Udp.parsePacket();
if (packetSize)
{
remoteIp = Udp.remoteIP();
remoteUDPPort = Udp.remotePort();
int len = Udp.read(packetBuffer, 255); //read in the packet
if (len > 0)
{
packetBuffer[len] = 0;
}
Serial.println(packetBuffer);
}
// send UDP Data - this sends data to the last device it receives data from. For a one to one link this is fine. If there are multiple clients then this may need to be adjusted to store and send to all clients.
if(dataToSend)
{
if(Udp.beginPacket(remoteIp, remoteUDPPort))
{
Udp.write(inData);
Udp.endPacket();
//Serial.println(inData); //Uncomment this line for a local echo of the data sent
}
else
{
Serial.println("No connection");
}
dataToSend = false; //set the flag to false, ie only send when you need to.
for (aindex=0; aindex < arraySize; aindex++) //wipe the array
{
inData[aindex] = '\0'; // Null terminate the string
}
aindex = 0; //reset the index
}
}
The code on the field device is attached. Can anyone please help resolve this issue.