Platform information: Raspberry Pi 3 Model B Rev 1.2
OS: openHABian
openHAB version: openHAB 2.5.1-2
I am running my openHAB on a RaspberryPi 3 and everything is fine so far. Now I’ve got a second RaspberryPi in my network. This RaspberryPi is on another floor of our house and it’s connected with a data cable to our water-tank in the garden. In the water-tank I’ve installed the ultrasonig modul HC-SR04. I am able to get the distance to the water-surface of the water-tank with the connected RaspberryPi via a Pyhton script.
My question is now, how can I get the measure result from the one RaspberryPi with the ultrasonic sensor to the other RaspberryPi with the openHAB?
You can write a script on the pi3 that used an ssh connection to the second py. In this script:
Connect to the second pi via ssh. You need to have ssh keys exchanged from the user openhab and the second pi (sudo -u openhab ssh-keygen)
Run the script on the second pi and echo the output in the script
You can extract the output via the exec binding.
I am doing the exact same thing to monitor system information for my second pi. Let me show you an example:
All following scripts/files are on the OpenHAB Server
cpu_1min.sh
ssh helper ‘uptime’ > .${0##/}
if [[ "$(cat .${0##/})" == “Connection” ]] 2>/dev/null || [[ “$(cat .${0##/})" == “host” ]] 2>/dev/null || [[ "$(cat .${0##/})” == “not known” ]] 2>/dev/null; then
exit
fi
cpu_load_all=$(cat .${0##*/} | sed -n -e 's/.average: //p’ )
rm .${0##/}
cpu_load_1m=$(echo $cpu_load_all | sed ‘s/ /\n/g’ | sed -n 1p | sed ‘s/.$//’ | sed ‘s/,/./’ )
echo $cpu_load_1m
exit
String RPI2Helper_CPUAuslastung_1min “CPU Auslastung in der letzten Minute” (Gruppe_RPi2Helper_CPU) {channel=“exec:command:Command_RPI2Helper_Cpuload_1min:output”}
Thanks! I think this will become useful in the future. @formicula1979 I would use the method of @Mark_Webster. I think it’s a lot more simple and straight to the point. I might switch to this solution too.
The full documentation for the REST API can be installed from the UIs tab in PaperUI. It’s also interactive so you can issue commands and updates and modify Things a stuff straight from the docs (useful for testing) and it shows you the equivalent curl command.