Achronite / mqtt-energenie-ener314rt

MQTT interface for Energenie ENER314-RT add-on board for the Raspberry Pi, designed for use by Home Assistant.
MIT License
13 stars 5 forks source link

Error in publishDiscovery JSON parse in "SyntaxError: Unexpected token ] in JSON at position 2418" /app.js:706:28 #50

Closed genestealer closed 1 year ago

genestealer commented 1 year ago

Note

NOTE: May be due to node-red-contrib-energenie-ener314rt nodered.service also running and trying to talk over SPI. Have been unable to recreate error and have now disabled the nodered.service

Error

Error: SyntaxError: Unexpected token ] in JSON at position 2418 in the publishDiscovery function of app.js

Seen: On boot, during discovery.

Line device_defaults = JSON.parse(data); in app.js

image

Oct 04 14:22:45 raspberrypi node[18697]: undefined:28
Oct 04 14:22:45 raspberrypi node[18697]:     ]
Oct 04 14:22:45 raspberrypi node[18697]:     ^
Oct 04 14:22:45 raspberrypi node[18697]: SyntaxError: Unexpected token ] in JSON at position 2418
Oct 04 14:22:45 raspberrypi node[18697]:     at JSON.parse (<anonymous>)
Oct 04 14:22:45 raspberrypi node[18697]:     at /home/pi/mqtt-energenie-ener314rt/app.js:706:28
Oct 04 14:22:45 raspberrypi node[18697]:     at FSReqCallback.readFileAfterClose [as oncomplete] (node:internal/fs/read_file_context:68:3)
Oct 04 14:22:45 raspberrypi systemd[1]: mqtt-energenie-ener314rt.service: Main process exited, code=exited, status=1/FAILURE
Oct 04 14:22:45 raspberrypi node[18708]: mqtt-energenie info energenie signal "SIGTERM", closing adaptor and monitoring thread...
Oct 04 14:22:55 raspberrypi node[18708]: mqtt-energenie info energenie done - "SIGTERM", exit(3)
Oct 04 14:22:55 raspberrypi systemd[1]: mqtt-energenie-ener314rt.service: Failed with result 'exit-code'.

Full log

pi@raspberrypi:~/mqtt-energenie-ener314rt $ journalctl -u mqtt-energenie-ener314rt.service --since "1 hour ago"
-- Journal begins at Tue 2023-09-12 14:07:53 BST, ends at Wed 2023-10-04 14:34:07 BST. --
Oct 04 14:12:44 raspberrypi systemd[1]: Started Energenie ener314rt MQTT client.
Oct 04 14:12:44 raspberrypi node[18697]: mqtt-energenie-ener314rt version 0.5.1: starting
Oct 04 14:12:44 raspberrypi node[18697]: mqtt-ener314rt info MQTT connecting to broker mqtt://192.168.10.21
Oct 04 14:12:45 raspberrypi node[18697]: mqtt-ener314rt info monitor starting monitoring of FSK devices...
Oct 04 14:12:45 raspberrypi node[18697]: mqtt-ener314rt http MQTT setting availability topic energenie/availability/state to 'online'
Oct 04 14:12:45 raspberrypi node[18697]: mqtt-ener314rt info discovery discovery enabled at topic prefix 'homeassistant/'
Oct 04 14:12:45 raspberrypi node[18697]: mqtt-ener314rt info MQTT subscribed to energenie/+/+/+/command
Oct 04 14:12:45 raspberrypi node[18708]: mqtt-energenie info energenie child process started
Oct 04 14:12:45 raspberrypi node[18708]: ener314rt: Hardware driver enabled on /dev/spidev0.1
Oct 04 14:12:45 raspberrypi node[18708]: mqtt-energenie info energenie ENER314-RT initialised succesfully
Oct 04 14:12:45 raspberrypi node[18708]: mqtt-energenie info energenie monitoring thread started
Oct 04 14:13:45 raspberrypi node[18697]: mqtt-ener314rt info auto calling discovery
Oct 04 14:13:55 raspberrypi node[18697]: mqtt-ener314rt http monitor received: {"cmd":"discovery","scan":false,"numDevices":0,"devices":[]}
Oct 04 14:13:55 raspberrypi node[18697]: mqtt-ener314rt info discovery found 0 devices
Oct 04 14:14:14 raspberrypi node[18697]: mqtt-ener314rt http monitor received: {"deviceId":1215,"mfrId":4,"productId":1,"timestamp":1696425254,"REAL_POWER":203,"REACTIVE_POWER":-1,"VOLTAGE":242,"FREQUENCY":49.800781,"cmd":"monitor"}
Oct 04 14:15:43 raspberrypi node[18697]: mqtt-ener314rt http monitor received: {"deviceId":1215,"mfrId":4,"productId":1,"timestamp":1696425343,"REAL_POWER":200,"REACTIVE_POWER":-1,"VOLTAGE":240,"FREQUENCY":49.851562,"cmd":"monitor"}
Oct 04 14:17:45 raspberrypi node[18697]: mqtt-ener314rt http monitor received: {"deviceId":6187,"mfrId":4,"productId":2,"timestamp":1696425465,"REAL_POWER":0,"REACTIVE_POWER":0,"VOLTAGE":245,"FREQUENCY":50.050781,"SWITCH_STATE":1,"cmd":"monitor"}
Oct 04 14:21:06 raspberrypi node[18697]: mqtt-ener314rt http monitor received: {"deviceId":5251,"mfrId":4,"productId":3,"timestamp":1696425666,"TEMPERATURE":20.5,"command":0,"retries":0,"cmd":"monitor"}
Oct 04 14:22:45 raspberrypi node[18697]: mqtt-ener314rt info auto calling discovery
Oct 04 14:22:45 raspberrypi node[18697]: mqtt-ener314rt http monitor received: {"cmd":"discovery","scan":false,"numDevices":3,"devices":[{"mfrId":4,"productId":1,"deviceId":1215,"control":0,"product":"Monitor Plug","joined":0},{"mfrId":4,"productId":2,"deviceId":6187,"control":1,"product":"Adapter Plus","joined":0},{"mfrId":4,"productId":3,"deviceId":5251,"control":2,"product":"Radiator Valve","joined":0}]}
Oct 04 14:22:45 raspberrypi node[18697]: mqtt-ener314rt info discovery found 3 devices
Oct 04 14:22:45 raspberrypi node[18697]: mqtt-ener314rt info discovery discovered: {"mfrId":4,"productId":1,"deviceId":1215,"control":0,"product":"Monitor Plug","joined":0}
Oct 04 14:22:45 raspberrypi node[18697]: mqtt-ener314rt info discovery discovered: {"mfrId":4,"productId":2,"deviceId":6187,"control":1,"product":"Adapter Plus","joined":0}
Oct 04 14:22:45 raspberrypi node[18697]: mqtt-ener314rt info discovery discovered: {"mfrId":4,"productId":3,"deviceId":5251,"control":2,"product":"Radiator Valve","joined":0}
Oct 04 14:22:45 raspberrypi node[18697]: undefined:28
Oct 04 14:22:45 raspberrypi node[18697]:     ]
Oct 04 14:22:45 raspberrypi node[18697]:     ^
Oct 04 14:22:45 raspberrypi node[18697]: SyntaxError: Unexpected token ] in JSON at position 2418
Oct 04 14:22:45 raspberrypi node[18697]:     at JSON.parse (<anonymous>)
Oct 04 14:22:45 raspberrypi node[18697]:     at /home/pi/mqtt-energenie-ener314rt/app.js:706:28
Oct 04 14:22:45 raspberrypi node[18697]:     at FSReqCallback.readFileAfterClose [as oncomplete] (node:internal/fs/read_file_context:68:3)
Oct 04 14:22:45 raspberrypi systemd[1]: mqtt-energenie-ener314rt.service: Main process exited, code=exited, status=1/FAILURE
Oct 04 14:22:45 raspberrypi node[18708]: mqtt-energenie info energenie signal "SIGTERM", closing adaptor and monitoring thread...
Oct 04 14:22:55 raspberrypi node[18708]: mqtt-energenie info energenie done - "SIGTERM", exit(3)
Oct 04 14:22:55 raspberrypi systemd[1]: mqtt-energenie-ener314rt.service: Failed with result 'exit-code'.
Oct 04 14:22:55 raspberrypi systemd[1]: mqtt-energenie-ener314rt.service: Failed with result 'exit-code'.
Oct 04 14:22:55 raspberrypi systemd[1]: mqtt-energenie-ener314rt.service: Consumed 2.055s CPU time.
Oct 04 14:22:55 raspberrypi systemd[1]: mqtt-energenie-ener314rt.service: Scheduled restart job, restart counter is at 1.
Oct 04 14:22:55 raspberrypi systemd[1]: Stopped Energenie ener314rt MQTT client.
Oct 04 14:22:55 raspberrypi systemd[1]: mqtt-energenie-ener314rt.service: Consumed 2.055s CPU time.
Oct 04 14:22:55 raspberrypi systemd[1]: Started Energenie ener314rt MQTT client.
Oct 04 14:22:55 raspberrypi node[20701]: mqtt-energenie-ener314rt version 0.5.1: starting
Oct 04 14:22:56 raspberrypi node[20701]: mqtt-ener314rt info MQTT connecting to broker mqtt://192.168.10.21
Oct 04 14:22:56 raspberrypi node[20701]: mqtt-ener314rt info monitor starting monitoring of FSK devices...
Oct 04 14:22:56 raspberrypi node[20701]: mqtt-ener314rt http MQTT setting availability topic energenie/availability/state to 'online'
Oct 04 14:22:56 raspberrypi node[20701]: mqtt-ener314rt info discovery discovery enabled at topic prefix 'homeassistant/'
Oct 04 14:22:56 raspberrypi node[20701]: mqtt-ener314rt info MQTT subscribed to energenie/+/+/+/command
Oct 04 14:22:56 raspberrypi node[20708]: mqtt-energenie info energenie child process started
Oct 04 14:22:56 raspberrypi node[20708]: ener314rt: Hardware driver enabled on /dev/spidev0.1
Oct 04 14:22:57 raspberrypi node[20708]: mqtt-energenie info energenie ENER314-RT initialised succesfully
Oct 04 14:22:57 raspberrypi node[20708]: mqtt-energenie info energenie monitoring thread started
Oct 04 14:23:51 raspberrypi node[20701]: mqtt-ener314rt http monitor received: {"deviceId":1215,"mfrId":4,"productId":1,"timestamp":1696425831,"REAL_POWER":191,"REACTIVE_POWER":-1,"VOLTAGE":245,"FREQUENCY":49.75,"cmd":"monitor"}
Oct 04 14:23:56 raspberrypi node[20701]: mqtt-ener314rt info auto calling discovery
Oct 04 14:23:56 raspberrypi node[20701]: mqtt-ener314rt http monitor received: {"cmd":"discovery","scan":false,"numDevices":1,"devices":[{"mfrId":4,"productId":1,"deviceId":1215,"control":0,"product":"Monitor Plug","joined":0}]}
Oct 04 14:23:56 raspberrypi node[20701]: mqtt-ener314rt info discovery found 1 devices
Oct 04 14:23:56 raspberrypi node[20701]: mqtt-ener314rt info discovery discovered: {"mfrId":4,"productId":1,"deviceId":1215,"control":0,"product":"Monitor Plug","joined":0}
Oct 04 14:27:36 raspberrypi node[20701]: mqtt-ener314rt http command {"cmd":"send","mode":"ook","repeat":50,"zone":"697441","switchNum":"2","switchState":true}
Oct 04 14:27:38 raspberrypi node[20701]: mqtt-ener314rt http monitor received: {"cmd":"send","mode":"ook","repeat":50,"zone":"697441","switchNum":"2","switchState":true,"state":true}
Oct 04 14:27:54 raspberrypi node[20701]: mqtt-ener314rt http monitor received: {"deviceId":6187,"mfrId":4,"productId":2,"timestamp":1696426074,"REAL_POWER":0,"REACTIVE_POWER":0,"VOLTAGE":246,"FREQUENCY":50,"SWITCH_STATE":1,"cmd":"monitor"}
Oct 04 14:28:04 raspberrypi node[20701]: mqtt-ener314rt http monitor received: {"deviceId":6187,"mfrId":4,"productId":2,"timestamp":1696426084,"REAL_POWER":0,"REACTIVE_POWER":0,"VOLTAGE":245,"FREQUENCY":49.949219,"SWITCH_STATE":1,"cmd":"monitor"}
Oct 04 14:28:05 raspberrypi node[20701]: mqtt-ener314rt http command {"cmd":"send","mode":"ook","repeat":50,"zone":"697441","switchNum":"2","switchState":true}
Oct 04 14:28:06 raspberrypi node[20701]: mqtt-ener314rt http monitor received: {"cmd":"send","mode":"ook","repeat":50,"zone":"697441","switchNum":"2","switchState":true,"state":true}
Oct 04 14:28:09 raspberrypi node[20701]: mqtt-ener314rt http command {"cmd":"send","mode":"ook","repeat":50,"zone":"697441","switchNum":"2","switchState":true}
Oct 04 14:28:11 raspberrypi node[20701]: mqtt-ener314rt http monitor received: {"cmd":"send","mode":"ook","repeat":50,"zone":"697441","switchNum":"2","switchState":true,"state":true}
Oct 04 14:28:24 raspberrypi node[20701]: mqtt-ener314rt http monitor received: {"deviceId":6187,"mfrId":4,"productId":2,"timestamp":1696426104,"REAL_POWER":0,"REACTIVE_POWER":0,"VOLTAGE":246,"FREQUENCY":49.949219,"SWITCH_STATE":1,"cmd":"monitor"}
Oct 04 14:29:59 raspberrypi node[20701]: mqtt-ener314rt http monitor received: {"deviceId":1215,"mfrId":4,"productId":1,"timestamp":1696426199,"REAL_POWER":303,"REACTIVE_POWER":-1,"VOLTAGE":244,"FREQUENCY":49.648438,"cmd":"monitor"}
Oct 04 14:32:56 raspberrypi node[20701]: mqtt-ener314rt info auto calling discovery
Oct 04 14:32:56 raspberrypi node[20701]: mqtt-ener314rt http monitor received: {"cmd":"discovery","scan":false,"numDevices":2,"devices":[{"mfrId":4,"productId":1,"deviceId":1215,"control":0,"product":"Monitor Plug","joined":0},{"mfrId":4,"productId":2,"deviceId":6187,"control":1,"product":"Adapter Plus","joined":0}]}
Oct 04 14:32:56 raspberrypi node[20701]: mqtt-ener314rt info discovery found 2 devices
Oct 04 14:32:56 raspberrypi node[20701]: mqtt-ener314rt info discovery discovered: {"mfrId":4,"productId":1,"deviceId":1215,"control":0,"product":"Monitor Plug","joined":0}
Oct 04 14:32:56 raspberrypi node[20701]: mqtt-ener314rt info discovery discovered: {"mfrId":4,"productId":2,"deviceId":6187,"control":1,"product":"Adapter Plus","joined":0}
Achronite commented 1 year ago

Please check your .json config files to see that they are valid and you havn't created invalid JSON as line 706 is when it parses the read in config data.

genestealer commented 1 year ago

Thank you. Used https://jsonlint.com/ Found trailing comma.

image

{"id": "battery","component":"sensor", "stat_t":"~@/state","config": {"dev_cla":"battery","unit_of_meas":"%"}},