Using the new Arduino IDE for ESP8266 and found bugs, report them here

Moderator: igrr

User avatar
By jeroenst2
#57687 I'm trying to get SSDP to work correct on an ESP8266 but while doing a lot of research I found out that multicast receiving on the ESP8266 fails after a while.

When the ESP8266 is just started it receives the multicast traffic ok, but after a few seconds nothing is received anymore. But when sending a packet with unicast to the ESP8266 then it is received and displayed on the serial console.

Here is the default example code I found and use to test multicast (btw the ssid and key are stored in eeprom so not defined in the example below):

Code: Select all/*
 * 31 mar 2015
 * This sketch display UDP packets coming from an UDP client.
 * On a Mac the NC command can be used to send UDP. (nc -u 192.168.1.101 2390).
 *
 * Configuration : Enter the ssid and password of your Wifi AP. Enter the port number your server is listening on.
 *
  13 apr 2015. Partly working. Packets are received and displayed, but the confirmation packet is not received by the client.
  Tested with Mac as cleint using netcat (nc -u 192.168.1.101 2390)

 */

#include <ESP8266WiFi.h>
#include <WiFiUDP.h>

int status = WL_IDLE_STATUS;

unsigned int localPort = 2390;      // 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, 255, 255, 250);
unsigned int portMulti = 1900;      // 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();
 
  // 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();



  Serial.println("Connected to wifi");
  Serial.print("Udp Multicast server started at : ");
  Serial.print(ipMulti);
  Serial.print(":");
  Serial.println(portMulti);
  Udp.beginMulticast(WiFi.localIP(),  ipMulti, portMulti);
}

void loop()
{
  int noBytes = Udp.parsePacket();
  if ( noBytes ) {
    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
    Udp.beginPacket(Udp.remoteIP(), Udp.remotePort());
    Udp.write("UDP packet received");
    Udp.endPacket();   
  } // end if



}


Here are the linux commands for sending the multicast traffic (although there is already SSDP traffic in this setup to receive):
Code: Select allecho "MULTICASTTEST" | netcat -4u -w1 239.255.255.250 1900


And I use this linux command for sending unicast traffic to the esp8266:
Code: Select allecho 'UNICASTTEST' | netcat -4u -w1 172.20.0.155 1900
User avatar
By Barnabybear
#57753 Hi, that unfortunatly is due to router and access points not forwarding multicast packets. You can sort of get round it by sending a short resopnce each time a multicast packet is recieved, it doesn't matter that no one is looking for the responce it just keeps a path open through your router.
User avatar
By jeroenst2
#57755 When usign wireshark on the computer via the same wireless access point, multicast traffic from hosts is received properly.

So I don't think it's the network that is stopping the multicast traffic.

Or am I wrong?
User avatar
By jeroenst2
#57783 I tested the above workaround by transmitting a multicast packet every 10 seconds from the esp8266.

The multicast packet is send out and received by the computer. But the ESP8266 still doesn't receive multicast traffic from other devices.