Your new topic does not fit any of the above??? Check first. Then post here. Thanks.

Moderator: igrr

User avatar
By cimd
#40842 H, I have the following code to receive UDP packets from my smartphone:
Code: Select all#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();

}


No, when I send packets that are until 3 bytes long, the packets are received OK. When I send packets that are 4 bytes long, I start to receive this weird characters in the end of the packet. And when I receive packets that are 5+ bytes long, the ESP8266 crashes and returns the following error in the serial:
Code: Select allPacketsize: 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


I've heard of issues related to power supply, but I've tested it with several devices and they all return the same behaviour, so I'm assuming this is something related to the code. Any clues?
User avatar
By mrburnette
#41117 While not specific to your use with a smartphone, I'm running a GPS and ESP8266 for months now: transmitting the full RMC sentence over UDP... and the unit has never locked-up being powered from an old notebook brick (heck, it is up in the attic and suffers wide temperature shifts.) Receivers are a few ESP8266's around the house with OLED displays that give GMT and date.

Here


Ray