Hi, I have this code to receive UDP packets sent from my phone to the ESP8266:
#include <ESP8266WiFi.h>
#include <WiFiUdp.h>
#include <WiFiClient.h>
WiFiServer server(80);
//UDP
WiFiUDP Udp;
#define SERVER_PORT 80
char packetBuffer[] = ""; //buffer to hold incoming packet
int PACKET_MAX_SIZE = 24;
int packetSize;
void receiveUDP() {
packetSize = Udp.parsePacket();
if (packetSize) {
Serial.print("Packetsize: ");
Serial.println(packetSize);
// read the packet into packetBufffer
Udp.read(packetBuffer, PACKET_MAX_SIZE);
Serial.println(packetBuffer);
for (int i = 0; i < PACKET_MAX_SIZE; i++) {
packetBuffer[i] = 0;
}
}
}
void openAP() {
WiFi.softAP("NodeMCU");
delay(1000);
Serial.print("IP: ");
Serial.println(WiFi.softAPIP());
}
void setup() {
Serial.begin(115200);
WiFi.mode(WIFI_AP);
//Open Access Point
openAP();
Udp.begin(80);
//server.begin();
}
void loop() {
receiveUDP();
}
Now, when I send packets that are until 3 bytes long, everthing works ok. When I receive packets that are 4 bytes long, I start to receive these weird characters in the end of the packets. When I receive packets that are 5+ bytes long, the ESP8266 crashes and send the following error:
Packetsize: 1
1
Packetsize: 2
12
Packetsize: 3
123
Packetsize: 4
1234Єþ?
Packetsize: 5
12345„þ?
Packetsize: 5
Exception (9):
epc1=0x402018ec epc2=0x00000000 epc3=0x00000000 excvaddr=0x3ffe8465 depc=0x00000000
ctx: cont
sp: 3ffef930 end: 3ffefb20 offset: 01a0
>>>stack>>>
3ffefad0: 3ffee950 3ffeeabc 3ffee948 402018e4
3ffefae0: 00000000 00000000 00000016 3ffeeaf0
3ffefaf0: 3fffdc20 00000000 3ffeeae8 40201920
3ffefb00: 00000000 00000000 00000000 40202d9d
3ffefb10: 00000000 00000000 3ffeeb00 40100114
<<<stack<<<
ets Jan 8 2013,rst cause:2, boot mode:(3,6)
load 0x4010f000, len 1264, room 16
tail 0
chksum 0x42
csum 0x42
~ld
IP do Access Point: 192.168.4.1
Any one has got a clue on why the issue on 5 bytes UDP packets?