Hey there. I'm trying to use this UDP library (http://bitbucket.org/bjoern/arduino_osc/src/tip/libraries/Ethernet/) to send a uPnP M-SEARCH message.
This is what I have so far:
#include <Ethernet.h>
#include <UdpRaw.h>
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0x47, 0x67 }; //MAC address to use
byte ip[] = { 192, 168, 1, 92 }; // Arduino's IP address
byte gw[] = { 192, 168, 1, 1 }; // Gateway IP address
/* uPnP */
byte targetIp[] = { 239, 255, 255, 250};
int targetPort = 1900;
#define MAX_SIZE 256 // maximum packet size (running MEGA)
byte packetBuffer[MAX_SIZE]; //buffer to hold incoming packet
int packetSize; // holds received packet size
byte remoteIp[4]; // holds recieved packet's originating IP
unsigned int remotePort; // holds received packet's originating port
void setup() {
Ethernet.begin(mac,ip,gw);
Serial.begin(115200);
UdpRaw.begin(1900);
delay(1000);
sendevent();
}
void loop() {
// if there's data available, read a packet
if(UdpRaw.available()) {
packetSize = UdpRaw.readPacket(packetBuffer,MAX_SIZE,remoteIp,(uint16_t *)&remotePort);
Serial.print("Received packet of size ");
Serial.println(abs(packetSize));
Serial.print("From IP ");
for(int i=0; i<3; i++) {
Serial.print(remoteIp[i],DEC);
Serial.print(".");
}
Serial.print(remoteIp[3],DEC);
Serial.print(" Port ");
Serial.println(remotePort);
if(packetSize < 0) {
// if return value <0 the packet was truncated to fit into our buffer
Serial.print("ERROR: Packet was truncated from ");
Serial.print(packetSize*-1);
Serial.print(" to ");
Serial.print(MAX_SIZE);
Serial.println(" bytes.");
}
Serial.println("Contents:");
for(int i=0; i<min(MAX_SIZE,abs(packetSize)); i++) {
Serial.print(packetBuffer[i],BYTE);
}
Serial.println("");
}
}
void sendevent(){
Serial.println("send");
UdpRaw.sendPacket("M-SEARCH * HTTP/1.1\r\nHOST: 239.255.255.250:1900\r\nMAN: \"ssdp:discover\"\r\nMX: 5\r\nST: upnp:rootdevice\r\n\r\n",targetIp,targetPort);
}
I can listen to global events, however, I cannot seem to send any out so I can responses to the adruino's IP (sniffing using wireshark to all 239.255.255.250 traffic from my arduino's IP)... any ideas where this could be failing? This should be pretty simple but it's been sucking a lot of my time.
Also, sending the UDP message to a computer and sniffing it does come through... just not via the Multicast IP... does Multicast require something special in the setup of the library?
P.S. This example only sends 1 event per reset.
Danny