Hi,
this post describes how to check on a Raspberry Pi if a mobile phone (Apple or Android) is online and send EIB Telegram depending of the device is available or not to the EIB bus.
You need an running eibd to send packets via IP to the EIB/KNX Bus.
If your eibd runs on a different host install eibd also the host where the script should runs. The daemon must not start (update-rc.d eibd defaults respectivily systemd enable eibd are not needed) because only the groupwrite command is requiered which sends packets over network to the already running eibd.
First of all you cannot check a mobile phone via ping because it does not answer tp icmp packets. You have to check if it response to ARP resolution packets. arping can do such checks.
Note: arping can only check hosts which are in the same IP Subnet, because it works at OSI layer 2.
root@debdev # sudo su root@debdev # apt-get -y install arping
Create a working folder for the script
root@debdev # mkdir /opt/checkhosts
and create the script checkhosts.sh in it:
#!/bin/bash
EIBD_HOST="192.168.100.240"
declare -A CHECKHOSTS
CHECKHOSTS=( ["192.168.100.24"]='5/3/1' ["192.168.100.34"]='5/3/0' )
for CURRENT_HOST in "${!CHECKHOSTS[@]}"; do
echo Checking Host $CURRENT_HOST
/opt/arping/arping -c 1 -C 1 $CURRENT_HOST
if [ $? -eq 0 ]; then
/usr/local/bin/groupwrite ip:$EIBD_HOST ${CHECKHOSTS[$CURRENT_HOST]} 1
elif [ $? -eq 1 ]; then
/usr/local/bin/groupwrite ip:$EIBD_HOST ${CHECKHOSTS[$CURRENT_HOST]} 0
fi
done
make it executable
root@debdev # chmod +x /opt/checkhosts/checkhosts.sh
Adjust the variables:
- EIBD_HOST => IP Address where your eibd is running at
- CHECKHOSTS => Hashtable of your hosts to check. Format: [“IPAddress”]=’EIBGroupAddress’
Finally create a cron job to check frequently (I think root permissions are requiered because arping uses libpcap to trace network traffic)
root@debdev # crontab -e
*/1 * * * * /opt/checkhosts/checkhosts.sh
Michael