PatchworkBoy / homebridge-edomoticz

Domoticz Homebridge-Plugin
Other
118 stars 44 forks source link

SyntaxError: Unexpected token C in JSON at position 0 #148

Closed fennec622 closed 4 years ago

fennec622 commented 6 years ago

Hi

Since sometimes i have a error, with a wrong mqtt message

I don't know what type of mqtt message because since error no message

Mar 28 00:06:04 Serveur_Ubuntu domoticz[1540]: 2018-03-28 00:06:04.330 (rfxcom) Temp (Temp emy) Mar 28 00:06:04 Serveur_Ubuntu domoticz[1540]: 2018-03-28 00:06:04.731 (rfxcom) Temp + Humidity (Temp ext Devant) Mar 28 00:06:05 Serveur_Ubuntu domoticz[1540]: 2018-03-28 00:06:05.093 (rfxcom) Temp (Unknown) Mar 28 00:06:08 Serveur_Ubuntu domoticz[1540]: 2018-03-28 00:06:08.143 (rfxcom) Temp + Humidity (Temp SDB) Mar 28 00:06:12 Serveur_Ubuntu homebridge[8616]: undefined:1 Mar 28 00:06:12 Serveur_Ubuntu homebridge[8616]: Connection Lost Mar 28 00:06:12 Serveur_Ubuntu homebridge[8616]: ^ Mar 28 00:06:12 Serveur_Ubuntu homebridge[8616]: SyntaxError: Unexpected token C in JSON at position 0 Mar 28 00:06:12 Serveur_Ubuntu homebridge[8616]: at JSON.parse (<anonymous>) Mar 28 00:06:12 Serveur_Ubuntu homebridge[8616]: at MqttClient.<anonymous> (/usr/local/lib/node_modules/homebridge-edomoticz/lib/mqtt.js:57:24) Mar 28 00:06:12 Serveur_Ubuntu homebridge[8616]: at emitThree (events.js:116:13) Mar 28 00:06:12 Serveur_Ubuntu homebridge[8616]: at MqttClient.emit (events.js:197:7) Mar 28 00:06:12 Serveur_Ubuntu homebridge[8616]: at MqttClient._handlePublish (/usr/local/lib/node_modules/homebridge-edomoticz/node_modules/mqtt/lib/client.js:940:12) Mar 28 00:06:12 Serveur_Ubuntu homebridge[8616]: at MqttClient._handlePacket (/usr/local/lib/node_modules/homebridge-edomoticz/node_modules/mqtt/lib/client.js:305:12) Mar 28 00:06:12 Serveur_Ubuntu homebridge[8616]: at work (/usr/local/lib/node_modules/homebridge-edomoticz/node_modules/mqtt/lib/client.js:261:12) Mar 28 00:06:12 Serveur_Ubuntu homebridge[8616]: at Writable.writable._write (/usr/local/lib/node_modules/homebridge-edomoticz/node_modules/mqtt/lib/client.js:271:5) Mar 28 00:06:12 Serveur_Ubuntu homebridge[8616]: at doWrite (/usr/local/lib/node_modules/homebridge-edomoticz/node_modules/readable-stream/lib/_stream_writable.js:418:64) Mar 28 00:06:12 Serveur_Ubuntu homebridge[8616]: at writeOrBuffer (/usr/local/lib/node_modules/homebridge-edomoticz/node_modules/readable-stream/lib/_stream_writable.js:407:5) Mar 28 00:06:12 Serveur_Ubuntu systemd[1]: homebridge.service: Main process exited, code=exited, status=1/FAILURE Mar 28 00:06:12 Serveur_Ubuntu systemd[1]: homebridge.service: Unit entered failed state. Mar 28 00:06:12 Serveur_Ubuntu systemd[1]: homebridge.service: Failed with result 'exit-code'.

Is it possible to add catch when mqtt message is not good

try { var message = JSON.parse(buffer.toString()); } catch(e) { var message = {} }

thanks

PatchworkBoy commented 6 years ago

Replace lib/mqtt.js with https://gist.github.com/PatchworkBoy/530b9e5128904d9edac3c028fd261cab

(See https://github.com/PatchworkBoy/homebridge-edomoticz/issues/129)

fennec622 commented 6 years ago

OK great

Is it possible to add modify the git with new file for update

Thanks a lot