Created
November 16, 2015 22:00
-
-
Save cyrildiagne/497057a1ba47df5bd901 to your computer and use it in GitHub Desktop.
Belkin Wemo toggle using Node.js
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
var value = process.argv[2]; | |
if (typeof value == "undefined") { | |
console.log('usage : node toggleWemo [0:1]'); | |
process.exit(1); | |
} | |
var http = require('http-debug').http; | |
http.debug = 2; | |
var wemoIP = '172.20.10.2'; | |
var wemoPort = '49153'; | |
var wemoPath = '/upnp/control/basicevent1'; | |
var data = '<?xml version="1.0" encoding="utf-8"?>' | |
+ '<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>'+ value +'</BinaryState>' | |
+ ' </u:SetBinaryState>' | |
+ ' </s:Body>' | |
+ '</s:Envelope>' | |
var options = { | |
host: wemoIP, | |
path: wemoPath, | |
port: wemoPort, | |
method: 'POST', | |
headers: { | |
'Accept': ' ', | |
'Content-type': 'text/xml; charset="utf-8"', | |
'SOAPACTION': '"urn:Belkin:service:basicevent:1#SetBinaryState"' | |
} | |
}; | |
callback = function(response) { | |
var str = '' | |
response.on('data', function (chunk) { | |
str += chunk; | |
}); | |
response.on('end', function () { | |
console.log(str); | |
}); | |
} | |
var req = http.request(options, callback); | |
req.write(data); | |
req.end(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment