I may not be doing this the best way, but this was my first attempt. What I’m seeing is random times where the scripts die because of malformed index or no data in the wxresult cache file. Here’s what I see:
Error reading JSON data from file ‘/scripts/wxresult’: Expecting value: line 1 column 1 (char 0)
KeyError: Requested key not found in API response
and then of course, I see the watchdog attempt to restart:
UV Watch Restarted - 2023-02-07_09:00:04
Wind watch restarted - 2023-02-07_09:00:05
Lightning Watch Restarted - 2023-02-07_09:00:05
This happens randomly and at different times. Is there a better way? ultimately, I’m just trying to generate a simple email to a distro to alert neighbors of hazardous conditions. I would appreciate any help from someone who may know something I don’t.
Eric, thanks for the reply. I put a link to the code repo for this watchdog in the post. I tried to keep it KISS as possible (for sanity). If you wouldn’t mind reviewing it, I’d be grateful. Perhaps you (or someone) may know a way to improve it, or a much more reliable way to do what I’m doing entirely.
I saw there is a websocket interface available as an alternative to the API, but I just don’t understand it yet. The way I wrote it now, when there is json data returned to the “wxresult” cache file, things work flawlessly. It’s been a hard thing to diagnose as it is random and unpredictable. I’ve seen in my log anywhere from minutes to hours where the watchdog attempts to read data and fails. and then days when things are just peachy. My API call cadance is only every 2 minutes, and I dump the json to a cache file “wxresult” so that this (and other) scripts can consume the data without each having to do separate API calls. Is a 2 minute cadance too frequent?
This may not be much use to you but as no one else has replied…
I assume that there is an error in that data.
If it lasted 2 minutes and you call the API every 2 minutes then I guess it may have occurred once.
If I was creating your code I would not use that file when it’s status_message is DATA_ERROR and either call it again for that 2 min value or wait until the next 2 minutes.
If it became a constant issue then I would consider after a time period of many DATA_ERROR’s of alerting me.
I use a different method to use data from the API and I do not recall having a problem with Data_Error.
I looked in the documentation and could not find a detailed description so that is why I simply think that it is alerting you that there is an error in that data.
Sorry it seems like I am simply repeating what it said.
edit Went looking for an example of how to deal with it.
My python code doing similar tasks is many thousands of lines of code and no way simple so I just tried to find the section that deals with what you are encountering and this shows a part of my checks: