Open cytan299 opened 9 months ago
I have a similar issue. [edit] This is the same environment as previously but now running plugin V1.2.2 I get the same type of error, here
[25/01/2024, 12:46:06] [Our Weather] ERROR: invalid json response body at https://rt.ambientweather.net/v1/devices?applicationKey=xxxxx&apiKey=xxxxx reason: Unexpected token '<', "<!DOCTYPE "... is not valid JSON
[25/01/2024, 12:46:06] TypeError: Cannot read properties of undefined (reading 'filter')
at TemperatureAccessory.updateData (/var/lib/homebridge/node_modules/homebridge-ambient-weather-sensors/src/temperatureAccessory.ts:52:28)
at processTicksAndRejections (node:internal/process/task_queues:95:5)
[25/01/2024, 12:46:06] Got SIGTERM, shutting down Homebridge...
[25/01/2024, 12:46:28] [Our Weather] Initializing AmbientWeatherSensors platform...
[25/01/2024, 12:46:28] [Our Weather] Loading accessory from cache: 48:3F:DA:xx:xx:xx-tempinf
[25/01/2024, 12:46:28] [Our Weather] Loading accessory from cache: 48:3F:DA:xx:xx:xx-humidityin
[25/01/2024, 12:46:28] [Our Weather] Loading accessory from cache: 48:3F:DA:xx:xx:xx-tempf
[25/01/2024, 12:46:28] [Our Weather] Loading accessory from cache: 48:3F:DA:xx:xx:xx-humidity
[25/01/2024, 12:46:28] [Our Weather] Loading accessory from cache: 48:3F:DA:xx:xx:xx-solarradiation
[25/01/2024, 12:48:09] [Our Weather] ERROR: invalid json response body at https://rt.ambientweather.net/v1/devices?applicationKey=xxxxx&apiKey=xxxxx reason: Unexpected token '<', "<!DOCTYPE "... is not valid JSON
[25/01/2024, 12:48:09] [Our Weather] ERROR: Cannot read properties of undefined (reading 'map')
This time it's different, this time at 12:46:06 a SIGTERM was triggered and restarted Homebridge, you can see it reloaded from cache after it restarted. The other plugins are still working and connected - and this plugin is still connected to HomeKit, but it's now only reporting the last cached data and not retrying the API call. Happy to open a different issue if needed.
I think this has to do with the AWN API. I have seen it return HTML instead of json from time to time. Probably need to check the response to ensure it has an Application: JSON
header before proceeding.
happy to provide more info if you need it
First, thank you so much for creating this plugin. I have 7 old AW F007TH sensors. With your plugin and a WS-100 gateway, I can now make the temperature and humidity data available in homeKit, without a need for the complex setup of rtl-sdr.
I also encountered a similar issue.
[1/30/2024, 5:45:02 PM] [AmbientWeatherSensors] ERROR: invalid json response body at https://rt.ambientweather.net/v1/devices?applicationKey=***&apiKey=**** reason: Unexpected token < in JSON at position 0 TypeError: Cannot read properties of undefined (reading 'filter') at HumidityAccessory.updateData (/var/lib/homebridge/node_modules/homebridge-ambient-weather-sensors/src/humidityAccessory.ts:49:28) at processTicksAndRejections (node:internal/process/task_queues:95:5)
The cause seems to be AWN API returning HTML occasionally instead of JSON, and the response.json() in node-fetch does not handle this gracefully. The response.json() is used by platform.ts at line 119:
const data = await response.json();
The following stackflow thread provides a potential solution using JSON.parse(), which will throw an error: https://stackoverflow.com/questions/56178321/invalid-json-response-body-error-with-express-node-fetch-using-formdata
Hopefully the above link is useful.
Describe The Bug:
After a few hours of running, the sensors stop reporting because the plugin is unable to read the JSON data. See the line from the log below.
A restart of the plugin fixes the problem for a while.
To Reproduce:
Just wait for a few hours after reboot.
Expected behavior:
This problem has happened ever since I've used this plugin. Also once in a while, after rebooting, the plugin fails to read the JSON file properly as well.
Logs:
Plugin Config:
Screenshots:
Environment: