mirror of
https://github.com/node-red/node-red-nodes.git
synced 2023-10-10 13:36:58 +02:00
Added more error checking in the discovery section (#214)
* Replacing the original wemo node with the wemo-ng node * Added install instructions * Fix name of wemo out node * Fix some jshint errors More jshint fixes fix jshint last jshint fix Fix last jshint error * Adds proper url length detection * fix up the extra line added in the merge * Fix some jshint errors More jshint fixes fix jshint last jshint fix Fix last jshint error load of tiny listing fixes, undef, unused, etc fix slight wrinkle in new Wemo node Fix wemo package name for npm. Add contribution.md to node-red-nodes to make it more obvious. correct spelling in readme.md revert .jshintrc Added subtree and walker nodes. (#200) Thanks @mikakaraila - very useful. slight edits to snmp to pass jslint-ing Bump underlying serial port nam version correct BBB callback response to check exists To Fix #198 * Adds proper url length detection fix up the extra line added in the merge * Added some more error checking in discovery * Adds proper url length detection* fix up the extra line added in the merge * Adds proper url length detection * fix up the extra line added in the merge Add line output mode for Daemon node to address #202 Email rework (#195) * Rework of Node-RED email nodes tidy up email listing - no code changes add latest email node dips and update email node libs - bump version update package version for nodes tests add a few tests geohash, smooth, base64, msgpack correct path of source file Thanks @Ltrlg Fix typo in node-red-node-smooth (#205) node-red-node-physical-web: Added msg.advertising = true/false to enable/disable advertising (#204) * Added msg.advertising = true/false to enable/disable advertising * Fixed comparison with bool Don't use get_compass as it breaks get_orientation add envelope to email node options as part of node-red#875 Physical-web: Added status (found, updated and lost) as msg.topic (#206) Added msg.advertising = true/false to enable/disable advertising Added status (lost, updated, found) as msg.topic, if not already set Added checkbox to allow duplicates or not. * Re-added optional topic to avoid breaking compatibility * Cleaner topic slection add a v0.3 serial port to help with node5/6 let PI try to enable sensorTag access on install Add cc and bcc options to email node to close #209 updates to email node to better handle different mail types. Still not great - but does the basics… To close Better email node parsing (again) Fix indent fixed formating * Fix heading in README.md Fix node name in README.md
This commit is contained in:
parent
49692b3255
commit
46cc9bb906
@ -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.
|
A set of Node-RED nodes for working with Belkin WeMo devices.
|
||||||
|
|
||||||
|
@ -79,119 +79,129 @@ WeMoNG.prototype.start = function start() {
|
|||||||
var location = url.parse(headers.LOCATION);
|
var location = url.parse(headers.LOCATION);
|
||||||
var port = location.port;
|
var port = location.port;
|
||||||
request.get(location.href, function(err, res, xml) {
|
request.get(location.href, function(err, res, xml) {
|
||||||
xml2js.parseString(xml, function(err, json) {
|
if (!err) {
|
||||||
var device = { ip: location.hostname, port: location.port };
|
xml2js.parseString(xml, function(err, json) {
|
||||||
for (var key in json.root.device[0]) {
|
if (!err) {
|
||||||
device[key] = json.root.device[0][key][0];
|
var device = { ip: location.hostname, port: location.port };
|
||||||
}
|
for (var key in json.root.device[0]) {
|
||||||
if (device.deviceType == "urn:Belkin:device:bridge:1") {
|
device[key] = json.root.device[0][key][0];
|
||||||
//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 (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 post_request = http.request(postoptions, function(res) {
|
||||||
var data = "";
|
var data = "";
|
||||||
res.setEncoding('utf8');
|
res.setEncoding('utf8');
|
||||||
res.on('data', function(chunk) {
|
res.on('data', function(chunk) {
|
||||||
data += chunk;
|
data += chunk;
|
||||||
});
|
});
|
||||||
|
|
||||||
res.on('end',function() {
|
res.on('end',function() {
|
||||||
xml2js.parseString(data, function(err, result) {
|
xml2js.parseString(data, function(err, result) {
|
||||||
if(!err) {
|
if(!err) {
|
||||||
var list = result["s:Envelope"]["s:Body"][0]["u:GetEndDevicesResponse"][0].DeviceLists[0];
|
var list = result["s:Envelope"]["s:Body"][0]["u:GetEndDevicesResponse"][0].DeviceLists[0];
|
||||||
xml2js.parseString(list, function(err, result2) {
|
xml2js.parseString(list, function(err, result2) {
|
||||||
if (!err) {
|
if (!err) {
|
||||||
var devinfo = result2.DeviceLists.DeviceList[0].DeviceInfos[0].DeviceInfo;
|
var devinfo = result2.DeviceLists.DeviceList[0].DeviceInfos[0].DeviceInfo;
|
||||||
for (var i=0; i<devinfo.length; i++) {
|
for (var i=0; i<devinfo.length; i++) {
|
||||||
var light = {
|
var light = {
|
||||||
"ip": ip,
|
"ip": ip,
|
||||||
"port": port,
|
"port": port,
|
||||||
"udn": device.UDN,
|
"udn": device.UDN,
|
||||||
"name": devinfo[i].FriendlyName[0],
|
"name": devinfo[i].FriendlyName[0],
|
||||||
"id": devinfo[i].DeviceID[0],
|
"id": devinfo[i].DeviceID[0],
|
||||||
"capabilities": devinfo[i].CapabilityIDs[0],
|
"capabilities": devinfo[i].CapabilityIDs[0],
|
||||||
"state": devinfo[i].CurrentState[0],
|
"state": devinfo[i].CurrentState[0],
|
||||||
"type": "light",
|
"type": "light",
|
||||||
"device": device
|
"device": device
|
||||||
};
|
};
|
||||||
var key = device.serialNumber + "-" + light.id;
|
var key = device.serialNumber + "-" + light.id;
|
||||||
if (!_wemo.devices[key]){
|
if (!_wemo.devices[key]){
|
||||||
_wemo.devices[key] = light;
|
_wemo.devices[key] = light;
|
||||||
_wemo.emit('discovered', key);
|
_wemo.emit('discovered', key);
|
||||||
} else {
|
} else {
|
||||||
_wemo.devices[key] = light;
|
_wemo.devices[key] = light;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
var groupinfo = result2.DeviceLists.DeviceList[0].GroupInfos;
|
|
||||||
if (groupinfo) {
|
|
||||||
for(var i=0; i<groupinfo.length; i++) {
|
|
||||||
var group = {
|
|
||||||
"ip": ip,
|
|
||||||
"port": port,
|
|
||||||
"udn": device.UDN,
|
|
||||||
"name": groupinfo[i].GroupInfo[0].GroupName[0],
|
|
||||||
"id": groupinfo[i].GroupInfo[0].GroupID[0],
|
|
||||||
"capabilities": groupinfo[i].GroupInfo[0].GroupCapabilityIDs[0],
|
|
||||||
"state": groupinfo[i].GroupInfo[0].GroupCapabilityValues[0],
|
|
||||||
"type": "light group",
|
|
||||||
"lights": [],
|
|
||||||
"device": device
|
|
||||||
}
|
}
|
||||||
for(var j=0; j<groupinfo[i].GroupInfo[0].DeviceInfos[0].DeviceInfo.length; j++) {
|
var groupinfo = result2.DeviceLists.DeviceList[0].GroupInfos;
|
||||||
group.lights.push(groupinfo[i].GroupInfo[0].DeviceInfos[0].DeviceInfo[j].DeviceID[0]);
|
if (groupinfo) {
|
||||||
|
for(var i=0; i<groupinfo.length; i++) {
|
||||||
|
var group = {
|
||||||
|
"ip": ip,
|
||||||
|
"port": port,
|
||||||
|
"udn": device.UDN,
|
||||||
|
"name": groupinfo[i].GroupInfo[0].GroupName[0],
|
||||||
|
"id": groupinfo[i].GroupInfo[0].GroupID[0],
|
||||||
|
"capabilities": groupinfo[i].GroupInfo[0].GroupCapabilityIDs[0],
|
||||||
|
"state": groupinfo[i].GroupInfo[0].GroupCapabilityValues[0],
|
||||||
|
"type": "light group",
|
||||||
|
"lights": [],
|
||||||
|
"device": device
|
||||||
|
}
|
||||||
|
for(var j=0; j<groupinfo[i].GroupInfo[0].DeviceInfos[0].DeviceInfo.length; j++) {
|
||||||
|
group.lights.push(groupinfo[i].GroupInfo[0].DeviceInfos[0].DeviceInfo[j].DeviceID[0]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var key = device.serialNumber + "-" + group.id;
|
||||||
|
if (!_wemo.devices[key]) {
|
||||||
|
_wemo.devices[key] = group;
|
||||||
|
_wemo.emit('discovered', key);
|
||||||
|
} else {
|
||||||
|
_wemo.devices[key] = group;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var key = device.serialNumber + "-" + group.id;
|
});
|
||||||
if (!_wemo.devices[key]) {
|
|
||||||
_wemo.devices[key] = group;
|
|
||||||
_wemo.emit('discovered', key);
|
|
||||||
} else {
|
|
||||||
_wemo.devices[key] = group;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
});
|
||||||
});
|
});
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
post_request.write(util.format(getenddevs.body, udn));
|
post_request.write(util.format(getenddevs.body, udn));
|
||||||
post_request.end();
|
post_request.end();
|
||||||
|
|
||||||
} else if (device.deviceType.indexOf('urn:Belkin:device') != -1) {
|
} else if (device.deviceType.indexOf('urn:Belkin:device') != -1) {
|
||||||
//socket
|
//socket
|
||||||
var socket = {
|
var socket = {
|
||||||
"ip": location.hostname,
|
"ip": location.hostname,
|
||||||
"port": location.port,
|
"port": location.port,
|
||||||
"name": device.friendlyName,
|
"name": device.friendlyName,
|
||||||
"type": "socket",
|
"type": "socket",
|
||||||
"device": device
|
"device": device
|
||||||
};
|
};
|
||||||
if (!_wemo.devices[device.serialNumber]) {
|
if (!_wemo.devices[device.serialNumber]) {
|
||||||
_wemo.devices[device.serialNumber] = socket;
|
_wemo.devices[device.serialNumber] = socket;
|
||||||
_wemo.emit('discovered',device.serialNumber);
|
_wemo.emit('discovered',device.serialNumber);
|
||||||
|
} else {
|
||||||
|
_wemo.devices[device.serialNumber] = socket;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
//other stuff
|
||||||
|
//console.log( device.ip + ' -' + device.deviceType);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
_wemo.devices[device.serialNumber] = socket;
|
console.error("failed to parse respose from " + location.href);
|
||||||
|
console.error(err);
|
||||||
}
|
}
|
||||||
} else {
|
});
|
||||||
//other stuff
|
} else {
|
||||||
//console.log( device.ip + ' -' + device.deviceType);
|
console.error("Failed to GET info from " + location.href);
|
||||||
}
|
console.error(err);
|
||||||
});
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
_wemo._client.search(urn);
|
_wemo._client.search(urn);
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "node-red-node-wemo",
|
"name": "node-red-node-wemo",
|
||||||
"version": "0.1.4",
|
"version": "0.1.5",
|
||||||
"description": "Input and Output nodes for Belkin WeMo devices",
|
"description": "Input and Output nodes for Belkin WeMo devices",
|
||||||
"repository": "https://github.com/node-red/node-red-nodes/tree/master/hardware",
|
"repository": "https://github.com/node-red/node-red-nodes/tree/master/hardware",
|
||||||
"main": "WeMoNG.js",
|
"main": "WeMoNG.js",
|
||||||
|
Loading…
Reference in New Issue
Block a user