Voila j'aimerai détecter ma présence quand je suis a la maison ou pas. J'ai un RPI 3 donc avec le bluetooth intégrer, avec la commande 'bluetoothctl' puis 'scan on' j'arrive a détecter mon NUT mini. J'ai trouvai un scripte shell :
Code : Tout sélectionner
#!/bin/bash
BLUETOOTHADDRCLEM="EA:91:0F:D0:E2:57"
BLUETOOTHNAMECLEM="nut"
SLEEPTIME=10 # Check interval in s
COUNTPRESENTCLEM=0
COUNTABSENTCLEM=0
while true
do
DEVICECLEM=`hcitool name $BLUETOOTHADDRCLEM`
if [[ $DEVICECLEM = $BLUETOOTHNAMECLEM ]]
then
COUNTPRESENTCLEM=$((COUNTPRESENTCLEM+1))
else
COUNTABSENTCLEM=$((COUNTABSENTCLEM+1))
fi
if [[ "$COUNTPRESENTCLEM" = 1 ]] # 1 confirmation is OK to be sure Clement is here
then
# Do something here
COUNTABSENTCLEM=0
echo "$(date) - Present"
fi
if [[ "$COUNTABSENTCLEM" = 2 ]] # We need 3 confirmations to be sure Clement is really away
then
# Do something here
COUNTPRESENTCLEM=0
echo "$(date) - Absent"
fi
echo "$(date) - confirmation presence: $COUNTPRESENTCLEM"
echo "$(date) - confirmation absence: $COUNTABSENTCLEM"
sleep $SLEEPTIME
done