Re: UDP Multicast Server example (now working OK)
Posted:
Mon Apr 20, 2015 5:00 am
by Gslomin
Truthfully I pulled it online somewhere, it's easier to start with a known working example rather than try to debug a tool you're trying to use to debug.
http://ntrg.cs.tcd.ie/undergrad/4ba2/mu ... ample.htmlIt was very clear that the updated UDP files were needed. I made sure to grab those, as well as build from source at the time 3 days ago. Something that was committed between now and then seems to have alleviated the issue.
Re: UDP Multicast Server example (now working OK)
Posted:
Mon Apr 20, 2015 6:53 am
by gerardwr
Gslomin wrote:Truthfully I pulled it online somewhere, it's easier to start with a known working example rather than try to debug a tool you're trying to use to debug.
http://ntrg.cs.tcd.ie/undergrad/4ba2/mu ... ample.html
Thanks for the link, compiled the code on my Mac using `gcc` with the following remarks:
- sender.c has some warnings, works, but just 'Hello W' is sent instead of 'Hello World'. Had to change the following line, maybe due to another character code definition, now the complete "Hello World" is sent.
Code: Select all// if (sendto(fd,message,sizeof(message),0,(struct sockaddr *) &addr,
if (sendto(fd,message,4*sizeof(message),0,(struct sockaddr *) &addr,
- listener.c has some warnings and 1 error in line 75 ( 'puts(message)' )
Replaced line 75, now the error is gone and the executable runs.
Code: Select all puts(msgbuf);
memset(msgbuf, 0, sizeof(msgbuf));
Re: UDP Multicast Server example (now working OK)
Posted:
Sat Jun 27, 2015 4:29 pm
by andre
Hi gerardwr,
The issues is cuased by sizeof, it should be strlen as:
Code: Select all if( sendto(fd,message,strlen(message),0,(struct sockaddr *) &addr, sizeof(addr)) < 0 ) {
Re: UDP Multicast Server example (now working OK)
Posted:
Fri Apr 08, 2016 9:01 am
by picstart
Multicast Arduino 1.6.5 will crash after few seconds in the loop using the sample code in this thread.
It does accept a UDP multicast and does reply within the time before it crashes. It works until it crashes.
Exception (0):
epc1=0x40106fa6 epc2=0x00000000 epc3=0x00000000 excvaddr=0x00000000 depc=0x00000000
ctx: sys
sp: 3ffffda0 end: 3fffffb0 offset: 01a0
>>>stack>>>
3fffff40: 402087ad 3fff4800 0000001c 40231969
3fffff50: 3fff0000 3fff47d8 3ffeb280 4020916c
3fffff60: 3fff4800 3fff4470 3ffed43c 00000018
3fffff70: 3fff4470 00000014 4020f4f2 3fff4800
3fffff80: 3fff4470 3fffdc80 3fff4500 00000050
3fffff90: 4020fe1f 3fff4800 00000000 3fffdcc0
3fffffa0: 40000f49 3fffdab0 3fffdab0 40000f49
<<<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
What I observed.
My esp8266 gets a unique dynamic ip address and will accept packets that are routed to it.
If the multi cast expression is invoked it will also accept the multicast packet provided the router will route it.
The multicast packet has the broadcasters ip and my esp8266 will reply to that specific ip and in turn the broadcaster can
now for the first time see my esp8266's unique ip plus my esp8266's chip id is also sent.
This is as expected except for the crash above
[code]
#include <ESP8266WiFi.h>
#include <WiFiUDP.h>
int status = WL_IDLE_STATUS;
const char* ssid = "sssid"; // your network SSID (name)
const char* pass = "pswd"; // your network password
unsigned int localPort = 12345; // local port to listen for UDP packets
byte packetBuffer[512]; //buffer to hold incoming and outgoing packets
//////////////////////////////////////////////////////////////////////
// A UDP instance to let us send and receive packets over UDP
//////////////////////////////////////////////////////////////////////
WiFiUDP Udp;
// Multicast declarations
IPAddress ipMulti(239, 0, 0, 57);
unsigned int portMulti = 12345; // 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 = Udp.parsePacket();
if ( noBytes )
{
//////// dk notes
/////// UDP packet can be a multicast packet or a specific to this device's own IP
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
//////////////////////////////////////////////////////////////////////
Udp.read(packetBuffer,noBytes); // read the packet into the buffer
// display the packet contents in HEX
for (int i=1;i<=noBytes;i++){
Serial.print(packetBuffer[i-1],HEX);
if (i % 32 == 0){
Serial.println();
}
else Serial.print(' ');
} // end for
Serial.println();
//////////////////////////////////////////////////////////////////////
// send a reply, to the IP address and port that sent us the packet we received
// the receipient will get a packet with this device's specific IP and port
//////////////////////////////////////////////////////////////////////
Udp.beginPacket(Udp.remoteIP(), Udp.remotePort());
Udp.write("My ChipId:");
Udp.write(ESP.getChipId());
Udp.endPacket();
} // end if
delay(20);
}
void printWifiStatus() {
// print the SSID of the network you're attached to:
Serial.print("SSID: ");
Serial.println(WiFi.SSID());
// print your WiFi shield's IP address:
IPAddress ip = WiFi.localIP();
Serial.print("IP Address: ");
Serial.println(ip);
}
[/code]