Apache Karaf client in openHAB, and the "Session has been closed" error
Don't you love it when things suddenly stop working?
In my openHAB installation I have a check which verifies that the weather data is up to date. Otherwise it restarts the openhab2 service. And this check stopped working ... Leaving the kitchen display not updated for a longer time. The same display where I expect the entire installation to "just work", and don't create so many different problems. Seems to be a hard problem to have an openHAB installation without any trouble ...
The check for up-to-date weather data is a simple "openhab client" call reading the timestamp of the weather data. That was the implementation:
#!/bin/bash # load environment variables for openhab2 . /etc/profile.d/openhab2.sh currentts=`/usr/share/openhab2/runtime/bin/client -l 0 "smarthome:status homeCurrentTS" | grep -v "Logging in as openhab"`
That worked fine for a long time, until recently when the cron job was failing. Because the Raspberry has no MTA installed, I couldn't figure out what was going on. One Postfix installation later I was able to see the emails sent by cron:
Session has been closed Can't extract timestamp!
The first line is from the failing job, the second line my script which is aborting at this point. Yay for proper error handling.
More debugging showed that the Apache Karaf client in openHAB doesn't like me anymore. The "client" logs in, but before processing the command, it is logged out again. On top of that: it only fails in the cron job, if I run the script on the command line, it still works fine. Can't really reproduce the issue.
The help for the "client" shows that the remaining parameters after the options are the command which is send to Karaf. That no longer seems to work in recent versions (openHAB 2.5). However this still works:
#!/bin/bash # load environment variables for openhab2 . /etc/profile.d/openhab2.sh currentts=`echo "smarthome:status homeCurrentTS" | /usr/share/openhab2/runtime/bin/client -l 0 -b`
For unknown reasons when piping the command into the client, and adding the "-b" parameter, the client can read data from Apache Karaf. Even in my cron job. Let's see for how long ...
Display comments as Linear | Threaded