stockmopar / connectedbytcp

Connected by TCP Lights API
http://home.stockmopar.com
30 stars 14 forks source link

Is it still supposed to work? #1

Closed sebastienvg closed 9 years ago

sebastienvg commented 9 years ago

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

``RoomGetCarousel12000Hallway100000000img/room/black.png0002167783252632937161001189016386Entrance Ceiling LED0multilevel0100001TCPLED A19 11WLED7821TCP112167783252659351971000189016386Hallway's TableLED0multilevel09900001TCPLED A19 11WLED7821TCPproductinfo,identify,meter_power,switch_binary,switch_multilevel111Office1000bd1f1img/room/green.png00021677832526587224910096189016386Dev Bulb Office LED1multilevel09900001TCPLED A19 11WLED7821TCPproductinfo,identify,meter_power,switch_binary,switch_multilevel115Master Bedroom10845fcf5img/room/purple.png0002167783252626510931001189016386Seb's Night Table LED5multilevel0100001TCPLED A19 11WLED7821TCP11216778325266869307100100189016386Inka's Night Table LED5multilevel09900001TCPLED A19 11WLED7821TCPproductinfo,identify,meter_power,switch_binary,switch_multilevel118Living Room10ff59b78img/room/pink.png00036021446615555528410000061440Ambiance8multilevel09900001Light Fixture15921productinfo,identify,meter_power,switch_binary,switch_multilevel11 { 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?

stockmopar commented 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.

stockmopar commented 9 years ago

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".

stockmopar commented 9 years ago

@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:

kevincoleman commented 9 years ago

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.

stockmopar commented 9 years ago

@kevincoleman

Can you post a new version of your formatted and unformatted result from the GWRBatch > RoomGetCarousel command?

kevincoleman commented 9 years ago

Gladly! Will do once I get home.

kevincoleman commented 9 years ago

Actually, here—I happened to have it up on my server from yesterday, unformatted.

I just updated the previous gist.

stockmopar commented 9 years ago

@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.