Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Multicast UDP support and MDNS class #47

Merged
merged 5 commits into from
Mar 16, 2016

Conversation

sandeepmistry
Copy link
Contributor

Port of beginMulti API added to Ethernet library in arduino/Arduino#1531.

Tested with the following sketch (we can add as example if needed):

#include <WiFi101.h>
#include <WiFiUdp.h>

char ssid[] = "yourNetwork";     //  your network SSID (name)
char pass[] = "password";  // your network password

IPAddress multicastIP(239, 0, 0, 57);
int multicastPort = 12345;

// A UDP instance to let us send and receive packets over UDP
WiFiUDP udp;

void setup() {
  //Initialize serial and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }

  // check for the presence of the shield:
  if (WiFi.status() == WL_NO_SHIELD) {
    Serial.println("WiFi shield not present");
    // don't continue:
    while (true);
  }

  Serial.print("Attempting to connect to WPA SSID: ");
  Serial.println(ssid);

  while (WiFi.begin(ssid, pass) != WL_CONNECTED) {
    Serial.println("Connection failed, retrying");
  }

  Serial.println("You're connected to the network");

  Serial.println("Waiting for multicast data");
  udp.beginMulti(multicastIP, multicastPort);
}

void loop() {
  if (udp.parsePacket()) {
    IPAddress remoteIP = udp.remoteIP();
    int remotePort = udp.remotePort();

    Serial.print("Received packet from: ");
    Serial.print(remoteIP);
    Serial.print(":");
    Serial.print(remotePort);

    Serial.print(" with data: ");

    while (udp.available()) {
      int b = udp.read();

      if (b < 16) {
        Serial.print("0");
      }
      Serial.print(b, HEX);
    }

    Serial.println();
  }

  delay(10);
}

and Node.js script:

var dgram = require('dgram');

var multicastIP = '239.0.0.57';
var multicastPort = 12345;

var client = dgram.createSocket('udp4');

var counter = 0;

setInterval(function() {
  var data = new Buffer(4);
  data.writeUInt32BE(counter);

  console.log('sending data', data.toString('hex'));
  client.send(data, 0, data.length, multicastPort, multicastIP);

  counter++;
}, 5000);

@sandeepmistry sandeepmistry added the type: enhancement Proposed improvement label Mar 11, 2016
@sandeepmistry sandeepmistry changed the title Added Multicast UDP support Added Multicast UDP support and MDNS class Mar 14, 2016
@sandeepmistry
Copy link
Contributor Author

I've updated to also add MDNS functionality.

agdl added a commit that referenced this pull request Mar 16, 2016
Added Multicast UDP support and MDNS class
@agdl agdl merged commit ca447f9 into arduino-libraries:master Mar 16, 2016
@sandeepmistry sandeepmistry deleted the multicast-udp branch July 11, 2016 21:05
@SurfingDude
Copy link

Tested with the following sketch (we can add as example if needed):

Did this ever end up as an example or is it not relevant anymore?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement Proposed improvement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants