Skip to content

Instantly share code, notes, and snippets.

@benwis
Created November 13, 2014 02:49
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save benwis/ebc4cdce2902478f86a5 to your computer and use it in GitHub Desktop.
Save benwis/ebc4cdce2902478f86a5 to your computer and use it in GitHub Desktop.
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 ssdpport = 1900;
IPAddress ip( 239, 255, 255, 250 );
// An UDP instance to let us send and receive packets over UDP
UDP Udp;
void setup() {
// start the UDP
Udp.begin(localPort);
// Print your device IP Address via serial
Serial.begin(9600);
Serial.println(WiFi.localIP());
WiFi.on();
// WiFi.setCredentials(SSID, PASSWORD);
// WiFi.setCredentials("DIRECT-thQ1:DSC-QX10", "1D7WJZ7U");
WiFi.setCredentials("indiana", "jones");
}
void loop() {
//Initiates communication with the Wi-Fi Chip
Spark.process();
Serial.println("Loop running");
if (WiFi.listening() == true){
Serial.println("Connecting");
}
WiFi.connect();
//NOTIFY * HTTP/1.0\r\n"
// "Host: %i.%i.%i.%i:%i\r\n"
// "Cache-Control: max-age=900\r\n"
// "Location: http://%i.%i.%i.%i:%i/device.xml\r\n"
// "NT: upnp:rootdevice\r\n"
// "USN: uuid:%s::upnp:rootdevice\r\n"
// "NTS: ssdp :alive\r\n"
// "Server: "APPNAME"/"APPVERSION" UPnP/1.0 %s\r\n\r\n",
if (WiFi.ready() == true)
{
Serial.println("Connection Established");
Serial.println(WiFi.localIP());
//Module to send SSDP packet
message = "M-SEARCH * HTTP/1.1\r\n "
"HOST: 239.255.255.250:1900\r\n "
"MAN: ssdp:discover\r\n "
"MX: 3\r\n "
"ST:ssdp:all\r\n\r\n ";
//Sends SSDP Packet to multicast address
Udp.beginPacket(ip, ssdpport);
Udp.write(message);
Udp.endPacket();
if (Udp.parsePacket() > 0) {
// Read first char of data received
char c = Udp.read();
Serial.println(c);
Udp.flush();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment