HealsCodes / node-red-contrib-homegear-mqtt

Interact with Homegear connected devices via mqtt
MIT License
8 stars 3 forks source link

peer id is passed as string to getAllValues #1

Closed hfedcba closed 8 years ago

hfedcba commented 8 years ago

At least in my test, peer id is passed as string to getAllValues causing Homegear to return a RPC error. This causes Node-RED to crash:

4 Jan 15:40:50 - [info] Started flows
4 Jan 15:40:50 - [info] [mqtt-broker:f53bf761.d78508] Connected to broker: Node-RED@mqtt://192.168.0.103:1884
4 Jan 15:40:50 - [info] [homegear-mqtt in:Remote] received initial parameter values
4 Jan 15:40:50 - [info] [homegear-mqtt in:Remote] {"error":{"code":-1,"message":"Type error."},"id":6941,"method":"getAllValues"}
4 Jan 15:40:50 - [red] Uncaught Exception:
4 Jan 15:40:50 - TypeError: Cannot read property '0' of undefined
    at /home/PREETZ/sathya/.node-red/node_modules/node-red-contrib-homegear-mqtt/homegear-mqtt.js:80:19
    at MqttClient.sub.handler (/usr/local/lib/node_modules/node-red/nodes/core/io/10-mqtt.js:222:25)
    at MqttClient.emit (events.js:129:20)
    at MqttClient._handlePublish (/usr/local/lib/node_modules/node-red/node_modules/mqtt/lib/client.js:748:12)
    at MqttClient._handlePacket (/usr/local/lib/node_modules/node-red/node_modules/mqtt/lib/client.js:261:12)
    at process (/usr/local/lib/node_modules/node-red/node_modules/mqtt/lib/client.js:219:12)
    at Writable.writable._write (/usr/local/lib/node_modules/node-red/node_modules/mqtt/lib/client.js:229:5)
    at doWrite (/usr/local/lib/node_modules/node-red/node_modules/mqtt/node_modules/readable-stream/lib/_stream_writable.js:237:10)
    at writeOrBuffer (/usr/local/lib/node_modules/node-red/node_modules/mqtt/node_modules/readable-stream/lib/_stream_writable.js:227:5)
    at Writable.write (/usr/local/lib/node_modules/node-red/node_modules/mqtt/node_modules/readable-stream/lib/_stream_writable.js:194:11)

I solved this by adding parseInt to line 106 in homegear-mqtt.js:

                        node.brokerConn.publish({
                                topic: 'homegear/' + node.homegearId + '/rpc',
                                qos: 2,
                                retain: false,
                                payload: {
                                        method: 'getAllValues',
                                        params: [ parseInt(node.peerId) ],
                                        id: node.rpcId
                                }
                        });

Cheers,

Sathya

HealsCodes commented 8 years ago

Yes, I can confirm it's passed as string - strangely at least in my tests (e.g. controlling the heating in my home) it worked as expected..

What you're seeing in the backtrace however is another problem.. The error is generated - as by your report - because peerId should be an integer. However the crash happens as a result of an invalid access to the parsed response (going to fix that too..).