Skip to content

Instantly share code, notes, and snippets.

Created November 13, 2014 06:03
Show Gist options
  • Save anonymous/fe9cde11e8ce40af7277 to your computer and use it in GitHub Desktop.
Save anonymous/fe9cde11e8ce40af7277 to your computer and use it in GitHub Desktop.
test code for ssdp and spark core, not sending packets
SYSTEM_MODE(MANUAL);
//Disables connection to Spark Cloud without additional API query
// UDP Port used for two way communication
unsigned int localPort = 8888;
const char *message = "A";
unsigned int once = 0;
unsigned int ssdpport = 1900;
IPAddress ip( 239, 255, 255, 250 );
// An UDP instance to let us send and receive packets over UDP
UDP Udp;
void setup() {
Serial.begin(9600);
WiFi.on();
// Connects to a network with a specified authentication procedure.
// Options are WPA2, WPA, or WEP.
WiFi.clearCredentials();
WiFi.setCredentials("life", "findsaway", WPA);
WiFi.connect();
}
void loop() {
Spark.process();
if (WiFi.ready() == true)
{
if ((ip[0] != 0 ||ip[1] != 0 || ip[2] != 0 || ip[3] != 0) && (once == 0)) {
Udp.begin(localPort);
Serial.println("UDP has begun");
once = 1;
}
Serial.println(WiFi.localIP());
//Module to send SSDP packet
message = "M-SEARCH * HTTP/1.1\r\nHOST: 239.255.255.250:1900\r\nMAN: \"ssdp:discover\"\r\nMX: 5\r\nST: ssdp:all\r\n\r\n";
// Udp.flush();
//Sends SSDP Packet to multicast address
Udp.beginPacket(ip, ssdpport);
Udp.write(message);
Udp.endPacket();
delay(1000); //Needed to prevent the Core from self destructing
if (Udp.parsePacket() > 0) {
// Read first char of data received
char c = Udp.read();
Serial.println(c);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment