Hi all!
I'm trying to control a Belkin Wemo with a CC3000 shield on an UNO.
I've gotten pretty far but at the moment the Belkin answers only gibberish. Any thoughts on that? Below is the code.
Thank you!!
Belkin's reply:
HTTP/1.1 500 Internal Server Error
CONTENT-LENGTH: 407
CONTENT-TYPE: text/xml; charset="utf-8"
DATE: Sun, 05 Jun 2016 20:44:47 GMT
EXT:
SERVER: Unspecified, UPnP/1.0, Unspecified
X-User-Agent: redsonic
And the code:
#define BLYNK_PRINT Serial // Comment this out to disable prints and save space
// These are the interrupt and control pins for СС3000
#define ADAFRUIT_CC3000_IRQ 3
#define ADAFRUIT_CC3000_VBAT 5
#define ADAFRUIT_CC3000_CS 10
#include <SPI.h>
#include <Adafruit_CC3000.h>
#include <BlynkSimpleCC3000.h>
#include <ccspi.h>
#include <string.h>
#include "utility/debug.h"
// BLYNK.
char auth[] = "48816a31cab446e782f35139e1668482";
//WEMO
const char* host = "10.0.1.133";
const int port = 49153;
int wemo_status = 0;
String wemo_on="<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\" s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\"><s:Body><u:SetBinaryState xmlns:u=\"urn:Belkin:service:basicevent:1\"><BinaryState>1</BinaryState></u:SetBinaryState></s:Body></s:Envelope>";
String wemo_off="<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\" s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\"><s:Body><u:SetBinaryState xmlns:u=\"urn:Belkin:service:basicevent:1\"><BinaryState>0</BinaryState></u:SetBinaryState></s:Body></s:Envelope>";
uint32_t ip=cc3000.IP2U32(10,0,1,133);
void setup()
{
Serial.begin(9600);
Blynk.begin(auth, "KK", "PASSWORD", WLAN_SEC_WPA2);
}
void loop()
{
Blynk.run();
if (wemo_status == 0) {
wemo_status = 1;
Serial.println("Turning WeMo On...");
}
else {
wemo_status = 0;
Serial.println("Turning WeMo Off...");
}
Serial.println();
wemo_control(wemo_status);
delay(5000);
}
void wemo_control(int cmd) {
Serial.print("Connecting to ");
Serial.println(host);
// Use WiFiClient class to create TCP connections
if (!cc3000.connectTCP(ip, 49153)) {
Serial.println("Connection failed");
return;
}
Adafruit_CC3000_Client wemoc = cc3000.connectTCP(ip, 49153);
// This will send the request to the server
wemoc.println("POST /upnp/control/basicevent1 HTTP/1.1");
wemoc.println("Host: " + String(host) + ":" + String(port));
wemoc.println("User-Agent: ESP8266/1.0");
wemoc.println("Connection: close");
wemoc.println("Content-type: text/xml; charset=\"utf-8\"");
wemoc.print("Content-Length: ");
if (cmd == 1) {
wemoc.println(wemo_on.length()); // both wemo_on and wemo_off are the same length, just in case it changes in the future
}
else {
wemoc.println(wemo_off.length());
}
wemoc.println("SOAPACTION: \"urn:Belkin:service:basicevent:1#SetBinaryState\"");
wemoc.println();
if (cmd == 1) {
wemoc.println(wemo_on);
}
else {
wemoc.println(wemo_off);
}
delay(10);
// Read all the lines of the reply from server and print them to Serial
while(wemoc.available()){
String line = wemoc.readStringUntil('\r');
Serial.print(line);
}
Serial.println();
Serial.println("Closing connection");
}