So I have a fairly simple sketch, it listens on UDP port 7777 and Streams that data out over the Serial to an Arduino. The Arduino is 5V. But as I am only connecting the TX from the ESP-01 to the RX of the Arduino Hardware serial line, so should be fine.
Anyway, after a certain amount of time, 5 - 10 minutes or so. The ESP-01 stops Streaming data out over Serial. The blue comm LED no longer blinks. Restarting my UDP Streaming app doesn't help. The module can still be pinged, so it has not totally locked up. The module also sends a 'G' byte message back to the remote IP the packet came from. The app only sends packets if it is receiving 'G' bytes. But these messages also stop. Here is the code:
#include <ESP8266WiFi.h>
#include <WiFiUDP.h>
//how many clients should be able to telnet to this ESP8266
#define MAX_SRV_CLIENTS 1
const char* ssid = "...";
const char* password = "...";
WiFiUDP UDP;
WiFiClient serverClients[MAX_SRV_CLIENTS]; //Whoops. left over from the telnet example.
#define LED_COUNT 256
#define LED_SIZE 3
#define HANDSHAKE_SIZE 3
unsigned char gLEDS[LED_COUNT * LED_SIZE + HANDSHAKE_SIZE]; //Lead with a 3 0x01 start bytes
unsigned char defaultColour[3] = { 255, 167, 50 };
IPAddress lastAddress = IPAddress(192,168,2,120);
#define STREAM Serial
unsigned long time;
void resetLEDS()
{
for(unsigned int i = 3; i < LED_COUNT * LED_SIZE; i+=3)
{
gLEDS[i] = defaultColour[0];
gLEDS[i+1] = defaultColour[1];
gLEDS[i+2] = defaultColour[2];
}
}
void setup()
{
STREAM.begin(250000);
gLEDS[0] = 0x01;
gLEDS[1] = 0x01;
gLEDS[2] = 0x01;
WiFi.begin(ssid, password);
STREAM.print("\nConnecting to "); STREAM.println(ssid);
uint8_t i = 0;
while (WiFi.status() != WL_CONNECTED && i++ < 20) delay(500);
if(i == 21)
{
STREAM.print("Could not connect to"); STREAM.println(ssid);
while(1) delay(500);
}
UDP.begin(7777);
STREAM.print("Ready! IP: ");
STREAM.print(WiFi.localIP());
resetLEDS();
WriteLEDS();
time = millis();
}
void WriteLEDS()
{
STREAM.write(gLEDS, LED_COUNT * LED_SIZE + HANDSHAKE_SIZE);
//Wait to write all this out to serial
STREAM.flush();
}
void loop()
{
if (UDP.parsePacket() != 0)
{
lastAddress = UDP.remoteIP();
/*
STREAM.print("Recv Packet from: ");
STREAM.print(address);
STREAM.print("\n");
*/
int totalBytes = UDP.read(gLEDS + HANDSHAKE_SIZE, LED_COUNT * LED_SIZE);
WriteLEDS();
time = millis();
}
//Send a confirm, so we can get the next one
UDP.beginPacket(lastAddress, 7878);
UDP.write('G');
UDP.endPacket();
delay(10);
if ( millis() - time > 10000 )
{
time = millis();
resetLEDS();
WriteLEDS();
}
}
It is almost like the loop function is no longer being called. Or is permanently blocked on UDP.parsePacket() or UDP.read(). Anyway got any advice on what might be the cause of this?
Cheers