As mentioned in my previous openHAB blog post: it seems to be too much to ask to have a reliable and working display in the kitchen.
Another problem I found is that the weather data occasionally does not update. Everything seems to work, no errors in the log, just no updated data. Of course this results in outdated weather info in the kitchen, and the threat that “someone” will buy a regular weather station and render my 7" Raspberry display useless.
After fighting with logs and debugging and not finding any real clue, I decided to tackle this problem from another angle, and regularly check if the weather data is up to date.
One of the information I get from the data source (Open Weather Map) is the timestamp of the last update:
|
|
Now “all” I have to do is read that timestamp, and then compare it with the current time. The first implementation I had running worked for a while, until it did no longer. There is a longer blog post here.
In order to read the current timestamp from openHAB, I’m using the commandline client in /usr/share/openhab2/runtime/bin/client
. This requires providing the proper environment so the client can login into Karaf and read the data:
|
|
After this step, I may or may not have the current timestamp. Verification is required:
|
|
It’s quite possible that the client can not read any data, that is catched by the first check. And if openHAB is currently starting or restarting, it will return NULL
(the string). In both cases I log an error and exit. Probably should investigate how often that happens, but so far that does not seem to be a problem.
After passing both checks, I should have a valid timestamp in $currentts
. That is converted into the Unix time (seconds since 1970) to make it easier to calculate differences. And the current time (in seconds) is required as well:
|
|
$time_diff
has the difference between the timestamp from the database and the current time. There is a small race condition if the weather time is in the future, or the system time lags behind.
Finally let’s check if the time is too old, and trigger a service restart:
|
|
Last but not least, something must install this script on the openHAB Raspberry, and run this check once in a while. A cron job, installed by Ansible:
|
|