Created
November 13, 2014 19:30
-
-
Save anonymous/19b5aa7b5105e06f0be7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SYSTEM_MODE(MANUAL); | |
//Disables connection to Spark Cloud without additional API query | |
// UDP Port used for two way communication | |
unsigned int localPort = 1900; | |
const char *message = "A"; | |
#define MAX_SIZE 1024 | |
char buffer[MAX_SIZE]; | |
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("why", "noUDP", 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)) { | |
Serial.println("UDP has begun"); | |
once = 1; | |
} | |
Udp.begin(localPort); | |
Serial.println(WiFi.localIP()); | |
//Module to send SSDP packet | |
if (Udp.parsePacket() > 0) { | |
// Read first char of data received | |
Udp.read(buffer, MAX_SIZE); | |
Serial.println(buffer); | |
} | |
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("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.endPacket(); | |
Udp.stop(); | |
// delay(100); //Needed to prevent the Core from self destructing | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment