This is running on an ESP 12E.
It is pretty straightforward code, but for some reason it stops sending "ping" after several hundred times. Anyone know why it would fail specifically after 300-500 times?
Also, can the 12E reset itself? Like from a GPIO1 pin to RST, driving it low?
#include <ESP8266WiFi.h>
#include <WiFiUdp.h>
const char* ssid = "JMR";
const char* password = "crystal2965";
WiFiUDP Udp;
unsigned int localUdpPort = 8888; // local port to listen on
char receivedChars[255]; // buffer for incoming packets
char replyPacket[] = "Hi there! Got the message :-)"; // a reply string to send back
boolean newData;
int numChars = 255;
void setup()
{
Serial.begin(115200);
Serial.println();
Serial.printf("Connecting to %s ", ssid);
IPAddress ip(192, 168, 1, 137);
IPAddress gw(192, 168, 1, 254);
IPAddress dns(192, 168, 1, 254);
IPAddress sn(255, 255, 255, 0);
WiFi.config(ip, gw, sn, dns);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED)
{
delay(500);
Serial.print(".");
}
Serial.println(" connected");
Udp.begin(localUdpPort);
Serial.printf("Now listening at IP %s, UDP port %d\n", WiFi.localIP().toString().c_str(), localUdpPort);
}
void recvWithEndMarker() {
static byte ndx = 0;
char endMarker = '\n';
char rc;
while (Serial.available() > 0 && newData == false) {
rc = Serial.read();
if (rc != endMarker) {
receivedChars[ndx] = rc;
ndx++;
if (ndx >= numChars) {
ndx = numChars - 1;
}
}
else {
receivedChars[ndx] = '\0'; // terminate the string
ndx = 0;
newData = true;
}
}
}
void showNewData() {
if (newData == true) {
sendUDP();
Serial.print("This just in ... ");
Serial.println(receivedChars);
newData = false;
}
}
void sendUDP() {
Udp.beginPacket("192.168.1.139", 8888);
Udp.write(receivedChars);
Udp.endPacket();
}
void pingOut() {
Udp.beginPacket("192.168.1.139", 8888);
Udp.write("ping");
Udp.endPacket();
}
void loop() {
recvWithEndMarker();
showNewData();
sendUDP();
pingOut();
delay(500);
}