Receiving multicast UDP packets
Posted: Mon Apr 25, 2016 10:51 am
The transmitter reads a GPS and puts a muticast packet into the air with the lat and long
after the receiver get several packets ( it varies ) it will crash and reset
I have the latest core 2.2.0 I suspect the core may have an issue.
Can anyone confirm that a UDP multicast receive is working for them
[code]#include <ESP8266WiFi.h>
#include <WiFiUdp.h>
int status = WL_IDLE_STATUS;
const char* ssid = "ssid"; // your network SSID (name)
const char* pass = "password"; // your network password
unsigned int localPort = 5001; // local port to listen for UDP packets
char packetBuffer[64]; //buffer to hold incoming and outgoing packets
WiFiUDP Udp;
// Multicast declarations
IPAddress ipMulti(239, 0, 0, 57);
unsigned int portMulti =5001; // local port to listen on
void setup()
{
// Open serial communications and wait for port to open:
Serial.begin(115200);
// setting up Station AP
WiFi.begin(ssid, pass);
// Wait for connect to AP
Serial.print("[Connecting]");
Serial.print(ssid);
int tries=0;
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
tries++;
if (tries > 30){
break;
}
}
Serial.println();
printWifiStatus();
Serial.println("Connected to wifi");
Serial.print("Udp Multicast listener started at : ");
Serial.print(ipMulti);
Serial.print(":");
Serial.println(portMulti);
Udp.beginMulticast(WiFi.localIP(), ipMulti, portMulti);
}
void loop()
{
int noBytes ,message_size;
noBytes=0;
message_size=0;
noBytes= Udp.parsePacket(); //// returns the size of the packet
if ( noBytes>0 && noBytes<64)
{
Serial.print(millis() / 1000);
Serial.print(":Packet of ");
Serial.print(noBytes);
Serial.print(" received from ");
Serial.print(Udp.remoteIP());
Serial.print(":");
Serial.println(Udp.remotePort());
//////////////////////////////////////////////////////////////////////
// We've received a packet, read the data from it
//////////////////////////////////////////////////////////////////////
message_size=Udp.read(packetBuffer,64); // read the packet into the buffer
if (message_size>0)
{
packetBuffer[message_size]=0; //// null terminate
Serial.println(packetBuffer);
}
} // end if
delay(20);
}[/code]
Serial Monitor output
30:Packet of 44 received from xx.xx.0.105:4097
From: xx.xx.0.105:lat= 29.9051:lon= -92.0781
Crashes here with this error
Exception (0):
epc1=0x40106752 epc2=0x00000000 epc3=0x00000000 excvaddr=0x00000000 depc=0x00000000
ctx: sys
sp: 3ffffd80 end: 3fffffb0 offset: 01a0
>>>stack>>>
3fffff20: 40221c53 005e0001 4020ba44 3ffec4c0
3fffff30: 3ffefcbc 00000001 40221c92 4020ba5d
3fffff40: 40221aa1 3fff023c 3ffec4c0 3ffe9950
3fffff50: 3ffe0000 3ffefcbc 3ffee810 40222490
3fffff60: 3fff023c 3fff00bc 3ffe9978 3ffec4c0
3fffff70: 3fff00bc 00000014 4022179e 3fff023c
3fffff80: 3fff00bc 3fffdc80 3fff012c 3fffdcb0
3fffff90: 40219133 3fff023c 00000000 40202983
3fffffa0: 40000f49 3fffdab0 3fffdab0 40000f49
<<<stack<<<
ets Jan 8 2013,rst cause:2, boot mode:(1,6)
after the receiver get several packets ( it varies ) it will crash and reset
I have the latest core 2.2.0 I suspect the core may have an issue.
Can anyone confirm that a UDP multicast receive is working for them
[code]#include <ESP8266WiFi.h>
#include <WiFiUdp.h>
int status = WL_IDLE_STATUS;
const char* ssid = "ssid"; // your network SSID (name)
const char* pass = "password"; // your network password
unsigned int localPort = 5001; // local port to listen for UDP packets
char packetBuffer[64]; //buffer to hold incoming and outgoing packets
WiFiUDP Udp;
// Multicast declarations
IPAddress ipMulti(239, 0, 0, 57);
unsigned int portMulti =5001; // local port to listen on
void setup()
{
// Open serial communications and wait for port to open:
Serial.begin(115200);
// setting up Station AP
WiFi.begin(ssid, pass);
// Wait for connect to AP
Serial.print("[Connecting]");
Serial.print(ssid);
int tries=0;
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
tries++;
if (tries > 30){
break;
}
}
Serial.println();
printWifiStatus();
Serial.println("Connected to wifi");
Serial.print("Udp Multicast listener started at : ");
Serial.print(ipMulti);
Serial.print(":");
Serial.println(portMulti);
Udp.beginMulticast(WiFi.localIP(), ipMulti, portMulti);
}
void loop()
{
int noBytes ,message_size;
noBytes=0;
message_size=0;
noBytes= Udp.parsePacket(); //// returns the size of the packet
if ( noBytes>0 && noBytes<64)
{
Serial.print(millis() / 1000);
Serial.print(":Packet of ");
Serial.print(noBytes);
Serial.print(" received from ");
Serial.print(Udp.remoteIP());
Serial.print(":");
Serial.println(Udp.remotePort());
//////////////////////////////////////////////////////////////////////
// We've received a packet, read the data from it
//////////////////////////////////////////////////////////////////////
message_size=Udp.read(packetBuffer,64); // read the packet into the buffer
if (message_size>0)
{
packetBuffer[message_size]=0; //// null terminate
Serial.println(packetBuffer);
}
} // end if
delay(20);
}[/code]
Serial Monitor output
30:Packet of 44 received from xx.xx.0.105:4097
From: xx.xx.0.105:lat= 29.9051:lon= -92.0781
Crashes here with this error
Exception (0):
epc1=0x40106752 epc2=0x00000000 epc3=0x00000000 excvaddr=0x00000000 depc=0x00000000
ctx: sys
sp: 3ffffd80 end: 3fffffb0 offset: 01a0
>>>stack>>>
3fffff20: 40221c53 005e0001 4020ba44 3ffec4c0
3fffff30: 3ffefcbc 00000001 40221c92 4020ba5d
3fffff40: 40221aa1 3fff023c 3ffec4c0 3ffe9950
3fffff50: 3ffe0000 3ffefcbc 3ffee810 40222490
3fffff60: 3fff023c 3fff00bc 3ffe9978 3ffec4c0
3fffff70: 3fff00bc 00000014 4022179e 3fff023c
3fffff80: 3fff00bc 3fffdc80 3fff012c 3fffdcb0
3fffff90: 40219133 3fff023c 00000000 40202983
3fffffa0: 40000f49 3fffdab0 3fffdab0 40000f49
<<<stack<<<
ets Jan 8 2013,rst cause:2, boot mode:(1,6)