stas-demydiuk / ewpe-smart-mqtt

MQTT bridge for EWPE Smart powered devices
MIT License
64 stars 26 forks source link

Code failing when two Airco's are present #6

Closed JongsmaSimon closed 4 years ago

JongsmaSimon commented 5 years ago

When a have only 1 airco (type Hunter Cooper) online the code works ok. But when the second (I have two in my home) is also online, the code fails (i put some prints in to see the keys used):

pi@raspberrypi:~/nodejs/ewpe-smart-mqtt $ npm start

ewpe-smart-mqtt@1.0.0 start /home/pi/nodejs/ewpe-smart-mqtt node index.js

2019-11-15T19:57:03.257Z [info]: "Server is listening on 0.0.0.0:48159" decrypt key: a3K8Bx%2r8Y7#xDh 2019-11-15T19:57:03.313Z [info]: "New device found: 1e775dd7 (f4911e775dd7), binding..." 2019-11-15T19:57:03.315Z [info]: "Going to call encrypt with key: a3K8Bx%2r8Y7#xDh" encrypt key: a3K8Bx%2r8Y7#xDh decrypt key: a3K8Bx%2r8Y7#xDh 2019-11-15T19:57:03.348Z [info]: "New device found: 1e775d28 (f4911e775d28), binding..." 2019-11-15T19:57:03.349Z [info]: "Going to call encrypt with key: a3K8Bx%2r8Y7#xDh" encrypt key: a3K8Bx%2r8Y7#xDh decrypt key: a3K8Bx%2r8Y7#xDh 2019-11-15T19:57:03.353Z [info]: "New device found: 1e775d28 (f4911e775d28), binding..." 2019-11-15T19:57:03.354Z [info]: "Going to call encrypt with key: a3K8Bx%2r8Y7#xDh" encrypt key: a3K8Bx%2r8Y7#xDh 2019-11-15T19:57:03.356Z [info]: "Going to call decrypt with key: a3K8Bx%2r8Y7#xDh" decrypt key: a3K8Bx%2r8Y7#xDh decrypt key: a3K8Bx%2r8Y7#xDh 2019-11-15T19:57:03.365Z [info]: "Going to call decrypt with key: a3K8Bx%2r8Y7#xDh" decrypt key: a3K8Bx%2r8Y7#xDh 2019-11-15T19:57:03.367Z [info]: "key: 7Ab0De3Gh6Jk9Mn2 registered for deviceId: f4911e775dd7" 2019-11-15T19:57:03.369Z [info]: "New device bound: 1e775dd7 (192.168.178.48:7000)" 2019-11-15T19:57:03.374Z [info]: "MQTT message received: ewpe-smart/f4911e775dd7 {\"cid\":\"f4911e775dd7\",\"bc\":\"000000000000000000000000000000\",\"brand\":\"gree\",\"catalog\":\"gree\",\"mac\":\"f4911e775dd7\",\"mid\":\"10001\",\"model\":\"gree\",\"name\":\"1e775dd7\",\"series\":\"gree\",\"vender\":\"1\",\"ver\":\"V1.2.1\",\"lock\":0,\"address\":\"192.168.178.48\",\"port\":7000,\"key\":\"7Ab0De3Gh6Jk9Mn2\"}" decrypt key: a3K8Bx%2r8Y7#xDh 2019-11-15T19:57:03.398Z [info]: "Going to call decrypt with key: a3K8Bx%2r8Y7#xDh" decrypt key: a3K8Bx%2r8Y7#xDh 2019-11-15T19:57:03.400Z [info]: "Going to call decrypt with key: a3K8Bx%2r8Y7#xDh" decrypt key: a3K8Bx%2r8Y7#xDh 2019-11-15T19:57:03.402Z [info]: "key: 7Ef0Hi3Kl6No9Qr2 registered for deviceId: f4911e775d28" 2019-11-15T19:57:03.403Z [info]: "New device bound: 1e775d28 (192.168.178.47:7000)" 2019-11-15T19:57:03.403Z [info]: "key: 7Ef0Hi3Kl6No9Qr2 registered for deviceId: f4911e775d28" 2019-11-15T19:57:03.404Z [info]: "New device bound: 1e775d28 (192.168.178.47:7000)" 2019-11-15T19:57:03.407Z [info]: "MQTT message received: ewpe-smart/f4911e775d28 {\"cid\":\"f4911e775d28\",\"bc\":\"000000000000000000000000000000\",\"brand\":\"gree\",\"catalog\":\"gree\",\"mac\":\"f4911e775d28\",\"mid\":\"10001\",\"model\":\"gree\",\"name\":\"1e775d28\",\"series\":\"gree\",\"vender\":\"1\",\"ver\":\"V1.2.1\",\"lock\":0,\"address\":\"192.168.178.47\",\"port\":7000,\"key\":\"7Ef0Hi3Kl6No9Qr2\"}" decrypt key: 7Ef0Hi3Kl6No9Qr2

internal/crypto/cipher.js:183 const ret = this[kHandle].final(); ^

Error: error:06065064:digital envelope routines:EVP_DecryptFinal_ex:bad decrypt at Decipheriv.final (internal/crypto/cipher.js:183:29) at decrypt (/home/pi/nodejs/ewpe-smart-mqtt/app/encryptor.js:17:48) at Connection.handleResponse (/home/pi/nodejs/ewpe-smart-mqtt/app/connection.js:108:26) at Socket.emit (events.js:210:5) at UDP.onMessage [as onmessage] (dgram.js:853:8) { library: 'digital envelope routines', function: 'EVP_DecryptFinal_ex', reason: 'bad decrypt', code: 'ERR_OSSL_EVP_BAD_DECRYPT'

Could it be that the code tries to decrypt with the key of the other airco?

stas-demydiuk commented 4 years ago

Could it be that the code tries to decrypt with the key of the other airco? It shouldn't be the case as I have 3 devices online at the same time and don't see such issue

I see each message in your log 2 times, it is a little strange. Are you sure you have only 1 instance of application running?

JongsmaSimon commented 4 years ago

Yes analyzed correctly. A second instance was running indeed. Now it works better. Thx! Next issue: both my airco's appear now in Domoticz with 11 idx entries each. Only problem is the actual values are not transmitted (all stay on defaults "Off" or "0.0"). What could be the cause?

SimonJ0ngsma commented 4 years ago

After a second restart of Domoticz it suddenly (automagically) started working. thanks for the help.

JongsmaSimon commented 4 years ago

After a restart of Domoticz all is well..