Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: Cannot read property 'room_id' of undefined #12

Closed
troelssiggaard opened this issue Oct 27, 2016 · 7 comments
Closed

TypeError: Cannot read property 'room_id' of undefined #12

troelssiggaard opened this issue Oct 27, 2016 · 7 comments

Comments

@troelssiggaard
Copy link

troelssiggaard commented Oct 27, 2016

After several hours of debugging I haven't found a solution to the problem:
"TypeError: Cannot read property 'room_id' of undefined" when setTemperature() is called in the maxcube.js file.

It seems like the deviceCache is not working, or that some information is not stored.
The error is due to thethis.deviceCache[rf_address].room_id object doesn't contain any data, found in line 134 of maxcube.js.

I've been trying to use the code both stand alone and with the Node-RED binding (node-red-contrib-maxcube), but neither works. The only code that works is the "maxcube-cli", which sets temperature without errors.

The full error:

TypeError: Cannot read property 'room_id' of undefined
    at MaxCube.setTemperature (/Users/ts/maxcube-test/node_modules/maxcube/maxcube.js:168:110)
    at MaxCube.<anonymous> (/Users/ts/maxcube-test/index.js:17:13)
    at emitNone (events.js:67:13)
    at MaxCube.emit (events.js:166:7)
    at MaxCubeLowLevel.<anonymous> (/Users/ts/maxcube-test/node_modules/maxcube/maxcube.js:38:10)
    at emitNone (events.js:67:13)
    at MaxCubeLowLevel.emit (events.js:166:7)
    at Socket.<anonymous> (/Users/ts/maxcube-test/node_modules/maxcube/maxcube-lowlevel.js:55:14)
    at Socket.g (events.js:260:16)
    at emitNone (events.js:72:20)
    at Socket.emit (events.js:166:7)
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1048:10)
@ivesdebruycker
Copy link
Owner

maxcube-cli uses this repository as a dependency for all communication with the maxcube (as does node-red-contrib-maxcube), so it's strange that it does work with the cli.

Could you try executing maxCube.flushDeviceCache() prior to setting the temperature? What's the result of MaxCube.getDevices() after flushDeviceCache function is finished?

Perhaps the duty cycle is full (due to extended testing) and the device states aren't correctly retrieved.

@troelssiggaard
Copy link
Author

troelssiggaard commented Nov 2, 2016

So, long story short, I got it working with Node-RED and then updated and it broke again.

I got it working by first making sure I sent real JSON (my bad) and not an escaped string and then I added:
node.maxCube.getConnection().then(function () { REST_OF_THE_CODE });
in the node.on('input', function ( ... which resolves the "Cannot read room_id" problem.

Then it stopped working when I was fiddling with retrieving device data, before I saw you had made the same effort in your updated maxcube-node.
Then I started from scratch, installing your new maxcube and node-red-contrib-maxcube v0.0.4 - got the same "room_id" error, added the getConnection() as described above and the error disappeared, but it's like it halts when sending the values to the thermostat, I do not get any messages in the node.log about either "Temperature set" nor "Error setting temperature".
Can this be due to "duty cycle"?

I'm pretty lost right now, and have run out of things to try to get it to work. I did try your maxCube.flushDeviceCache() but it didn't resolve anything.

@ivesdebruycker
Copy link
Owner

Could you patch you code with following diff? It should print errors while setting the temperature, and print duty cycle info when status of devices is collected.

diff --git a/maxcube.js b/maxcube.js
index 33aca86..c27fdac 100755
--- a/maxcube.js
+++ b/maxcube.js
@@ -28,6 +28,8 @@ module.exports = function(RED) {
         } else {
           node.log('Error setting temperature');
         }
+      }).catch(function(e) {
+        node.warn(e);
       });
     });
   }
@@ -54,6 +56,7 @@ module.exports = function(RED) {
     });

     node.on('input', function(msg) {
+      node.log(JSON.stringify(node.maxCube.getCommStatus()));
       node.maxCube.getDeviceStatus().then(function (payload) {
         // send devices statuses as separate messages
         node.send([payload.map(function function_name(deviceStatus) { return { rf_address: deviceStatus.rf_address, payload: deviceStatus }; })]);

In regards to duty cycle:

The duty cycle describes a statutory limit of the airtime of devices in the
868 MHz range. The objective of this scheme is to the function of all in
the 868 MHz range to ensure working devices. In the frequency range used by
us, the maximum transmission time of each unit 868 MHz is 1% of one hour
(so 36 seconds in an hour). The devices may be used in achieving the
1%-limit no longer send, until the time limit is over.

It only affects communication between the Max Cube and the connected devices (thermostats etc.). You can see its current value in the cli with commands 'status' or 'comm' (remember to quit node-red, because only one connection to the Max Cube is allowed..).
If you repeatedly change temperatures, it's possible to exceed the maximum allowed.

@jwildeboer
Copy link

jwildeboer commented Nov 30, 2016

I also get the "TypeError: Cannot read property 'room_id' of undefined" on my install (Node Red 0.15.2 on a Raspberry Pi 2 under Fedora 24, newest nodered-contrib-maxcube). I will install the cli tool next to see if I can get some more details.

@asantaga
Copy link

asantaga commented Nov 30, 2016

I wonder if this is related to issue13 .
I can try this later but I solved/workaround'd the issue by having a small delay between the connect promise completing and querying the rooms, I'll try setting the temperature later today

@ivesdebruycker
Copy link
Owner

@troelssiggaard, could you check if b33969d fixes this issue?

@asantaga
Copy link

asantaga commented Dec 1, 2016

Confirmed fixed :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants