Closed sebastienvg closed 9 years ago
Can you verify that the room defined on line 8 of toggle.js matches a room name that you have defined in the TCP app?
There is much improvement in the area of error reporting that could be made still. One such could be reporting that no such room was found with the given name.
From looking at: https://github.com/kevincoleman/connectedbytcp/commit/9211073e9d1808cf11ea7fb5e5d9084063118562 and https://gist.github.com/kevincoleman/5932dc9edaed0a021c98 it appears that the confusion is coming from the fact that "Office" is a device in the room "Bedroom".
@kevincoleman Please feel free to add feature requests as issues here in the GItHub. I will add:
Possible features would be:
Farther out features could be:
Yep! That was from an older version. It was mixed up for a bit, and both the Office and the bedroom lights were in the same room. Now I have two rooms, each with a light named after it (Office -> Office and Bedroom -> Bedroom) rid’s are 0 and 2, which are what I used to test via browser-initiated http requests.
@kevincoleman
Can you post a new version of your formatted and unformatted result from the GWRBatch > RoomGetCarousel command?
Gladly! Will do once I get home.
Actually, here—I happened to have it up on my server from yesterday, unformatted.
I just updated the previous gist.
@kevincoleman
Haven't been able to track down any issue yet. I supersceded your What happens if you replace lines 8 through 20 of toggle.js with:
roomName = "Office";
console.log("System Object:");
console.log(system);
rid = Test.GetRIDByName(roomName)
console.log("RID: " + rid);
console.log("Room Object:");
console.log(system[1]);
room = system[1];
state = 0;
var i = 0;
var sum = 0;
var devices = room["device"];
if (typeof(devices["did"]) !== 'undefined'){
i = i+1;
if(devices["state"] != "0"){
state = 1;
sum = sum + parseInt(devices["level"]);
}
}else{
devices.forEach(function(device) {
i = i+1;
if(device["state"] != "0"){
state = 1;
sum = sum + parseInt(device["level"]);
}
});
}
if(i == 0){
sum = 0;
i = 1;
state = 0;
}
level = sum / i;
console.log("State: " + state);
console.log("Level: " + level);
if(state == "1"){
// Should Turn the Light On
Test.TurnOffRoom(rid, function(error){
Test.GWEnd();
});
}else{
Test.TurnOnRoom(rid, function(error){
Test.GWEnd();
});
}
Note: that is assuming that you haven't changed much with your system. I hard coded it to look at the second room element [1] in the system object to get this. If your system has changed we will have to alter it accordingly.
For me (I overrided my returned data string with yours) and it gives:
System Object: [ { rid: '0', name: 'Bedroom', desc: {}, known: '1', type: '0', color: '000000', colorid: '0', img: 'images/black.png', power: '0', poweravg: '0', energy: '0', device: { did: '216390408111808475', known: '1', lock: '0', state: '0', level: '0', node: '238', port: '0', nodetype: '16386', name: 'Bedroom', desc: 'LED', colorid: '0', imgs: 'images/lighting/TCP/TCP-A19.png', imgm: 'images/lighting/TCP/TCP-A19.png', imgb: 'images/lighting/TCP/TCP-A19.png', imgs_s: 'images/lighting/TCP/TCP-A19.png', imgm_s: 'images/lighting/TCP/TCP-A19.png', imgb_s: 'images/lighting/TCP/TCP-A19.png', type: 'multilevel', rangemin: '0', rangemax: '99', power: '0', poweravg: '0', energy: '0', score: '0', productid: '1', prodbrand: 'TCP', prodmodel: 'LED A19 11W', prodtype: 'LED', prodtypeid: '78', classid: '2', class: {}, subclassid: '1', subclass: {}, other: [Object] } }, { rid: '2', name: 'Office', desc: {}, known: '1', type: '0', color: '004fd9', colorid: '2', img: 'images/blue.png', power: '0', poweravg: '0', energy: '0', device: { did: '216390408111096950', known: '1', lock: '0', state: '1', level: '50', node: '238', port: '0', nodetype: '16386', name: 'Office', desc: 'LED', colorid: '2', imgs: 'images/lighting/TCP/TCP-A19.png', imgm: 'images/lighting/TCP/TCP-A19.png', imgb: 'images/lighting/TCP/TCP-A19.png', imgs_s: 'images/lighting/TCP/TCP-A19.png', imgm_s: 'images/lighting/TCP/TCP-A19.png', imgb_s: 'images/lighting/TCP/TCP-A19.png', type: 'multilevel', rangemin: '0', rangemax: '99', power: '0', poweravg: '0', energy: '0', score: '0', productid: '1', prodbrand: 'TCP', prodmodel: 'LED A19 11W', prodtype: 'LED', prodtypeid: '78', classid: '2', class: {}, subclassid: '1', subclass: {}, other: [Object] } } ]
RID: 2
Room Object: { rid: '2', name: 'Office', desc: {}, known: '1', type: '0', color: '004fd9', colorid: '2', img: 'images/blue.png', power: '0', poweravg: '0', energy: '0', device: { did: '216390408111096950', known: '1', lock: '0', state: '1', level: '50', node: '238', port: '0', nodetype: '16386', name: 'Office', desc: 'LED', colorid: '2', imgs: 'images/lighting/TCP/TCP-A19.png', imgm: 'images/lighting/TCP/TCP-A19.png', imgb: 'images/lighting/TCP/TCP-A19.png', imgs_s: 'images/lighting/TCP/TCP-A19.png', imgm_s: 'images/lighting/TCP/TCP-A19.png', imgb_s: 'images/lighting/TCP/TCP-A19.png', type: 'multilevel', rangemin: '0', rangemax: '99', power: '0', poweravg: '0', energy: '0', score: '0', productid: '1', prodbrand: 'TCP', prodmodel: 'LED A19 11W', prodtype: 'LED', prodtypeid: '78', classid: '2', class: {}, subclassid: '1', subclass: {}, other: { rcgroup: {}, manufacturer: 'TCP', capability: 'productinfo,identify,meter_power,switch_binary,switch_multi level', bulbpower: '11' } } }
State: 1 Level: 50
Which all looks ok and controls my room which has rid 2. Give this a run and if you have to, put more console.logs in to see where it is failing.
Hi Stockmopar,
I just tried to play around with your nodejs implementation of ConnectedByTCP but no luck. I tried on OSX with node 0.10.21 and I try on a raspbian with node 0.10.24 and I get the same error with both setup while trying for example:
node toggle.js
it returns
``RoomGetCarousel 1 200 0 Hallway 1 0 000000 0 img/room/black.png0 0 0 216778325263293716 1 0 0 1 189 0 16386 Entrance Ceiling LED 0 multilevel 0 1 0 0 0 0 1 TCP LED A19 11W LED 78 2 1 TCP 11 216778325265935197 1 0 0 0 189 0 16386 Hallway's Table LED 0 multilevel 0 99 0 0 0 0 1 TCP LED A19 11W LED 78 2 1 TCP productinfo,identify,meter_power,switch_binary,switch_multilevel 11 1 Office 1 0 00bd1f 1 img/room/green.png0 0 0 216778325265872249 1 0 0 96 189 0 16386 Dev Bulb Office LED 1 multilevel 0 99 0 0 0 0 1 TCP LED A19 11W LED 78 2 1 TCP productinfo,identify,meter_power,switch_binary,switch_multilevel 11 5 Master Bedroom 1 0 845fcf 5 img/room/purple.png0 0 0 216778325262651093 1 0 0 1 189 0 16386 Seb's Night Table LED 5 multilevel 0 1 0 0 0 0 1 TCP LED A19 11W LED 78 2 1 TCP 11 216778325266869307 1 0 0 100 189 0 16386 Inka's Night Table LED 5 multilevel 0 99 0 0 0 0 1 TCP LED A19 11W LED 78 2 1 TCP productinfo,identify,meter_power,switch_binary,switch_multilevel 11 8 Living Room 1 0 ff59b7 8 img/room/pink.png0 0 0 360214466155555284 1 0 0 0 0 0 61440 Ambiance 8 multilevel 0 99 0 0 0 0 1 Light Fixture 159 2 1 productinfo,identify,meter_power,switch_binary,switch_multilevel 11
{ gwrcmd: { gcmd: 'RoomGetCarousel', gdata: { gip: [Object] } } }
ReferenceError: results is not defined at /root/connectedbytcp/index.js:37:14 at module.exports (/root/connectedbytcp/node_modules/libxml-to-js/lib/libxml-to-js.js:187:3) at Request._callback (/root/connectedbytcp/index.js:34:3) at Request.self.callback (/root/connectedbytcp/node_modules/request/request.js:373:22) at Request.EventEmitter.emit (events.js:98:17) at Request. (/root/connectedbytcp/node_modules/request/request.js:1318:14)
at Request.EventEmitter.emit (events.js:117:20)
at IncomingMessage. (/root/connectedbytcp/node_modules/request/request.js:1266:12)
at IncomingMessage.EventEmitter.emit (events.js:117:20)
at _stream_readable.js:920:16``
I can't figure what I am doing wrong! Can you help?