diff --git a/hardware/wemo/README.md b/hardware/wemo/README.md index 57e4a44f..3f5fe7f1 100644 --- a/hardware/wemo/README.md +++ b/hardware/wemo/README.md @@ -1,4 +1,4 @@ -# node-red-contrib-nodes-wemo +# node-red-node-wemo A set of Node-RED nodes for working with Belkin WeMo devices. diff --git a/hardware/wemo/lib/wemo.js b/hardware/wemo/lib/wemo.js index d3822fed..757a8f85 100644 --- a/hardware/wemo/lib/wemo.js +++ b/hardware/wemo/lib/wemo.js @@ -79,119 +79,129 @@ WeMoNG.prototype.start = function start() { var location = url.parse(headers.LOCATION); var port = location.port; request.get(location.href, function(err, res, xml) { - xml2js.parseString(xml, function(err, json) { - var device = { ip: location.hostname, port: location.port }; - for (var key in json.root.device[0]) { - device[key] = json.root.device[0][key][0]; - } - if (device.deviceType == "urn:Belkin:device:bridge:1") { - //console.log( device.ip + ' -' + device.deviceType); - var ip = device.ip; - var port = device.port; - var udn = device.UDN; - var postoptions = { - host: ip, - port: port, - path: getenddevs.path, - method: 'POST', - headers: { - 'SOAPACTION': getenddevs.action, - 'Content-Type': 'text/xml; charset="utf-8"', - 'Accept': '' + if (!err) { + xml2js.parseString(xml, function(err, json) { + if (!err) { + var device = { ip: location.hostname, port: location.port }; + for (var key in json.root.device[0]) { + device[key] = json.root.device[0][key][0]; } - }; + if (device.deviceType == "urn:Belkin:device:bridge:1") { + //console.log( device.ip + ' -' + device.deviceType); + var ip = device.ip; + var port = device.port; + var udn = device.UDN; + var postoptions = { + host: ip, + port: port, + path: getenddevs.path, + method: 'POST', + headers: { + 'SOAPACTION': getenddevs.action, + 'Content-Type': 'text/xml; charset="utf-8"', + 'Accept': '' + } + }; - var post_request = http.request(postoptions, function(res) { - var data = ""; - res.setEncoding('utf8'); - res.on('data', function(chunk) { - data += chunk; - }); + var post_request = http.request(postoptions, function(res) { + var data = ""; + res.setEncoding('utf8'); + res.on('data', function(chunk) { + data += chunk; + }); - res.on('end',function() { - xml2js.parseString(data, function(err, result) { - if(!err) { - var list = result["s:Envelope"]["s:Body"][0]["u:GetEndDevicesResponse"][0].DeviceLists[0]; - xml2js.parseString(list, function(err, result2) { - if (!err) { - var devinfo = result2.DeviceLists.DeviceList[0].DeviceInfos[0].DeviceInfo; - for (var i=0; i