Re: bash on startup avec gpio
Posté : dim. 15 janv. 2017 09:29
Pour info, nous n'avons plus besoin d'être root depuis un an pour le contrôle des GPIO
Les forums français du Raspberry Pi
http://forums.framboise314.fr/
Lorsque les fonctions sont séparées du script de base il est plus lisible lorsque le script est long. C'est une habitude qui ici ne serait effectivement pas nécessaire... mais tant qu'à faire, autant garder les bonnes habitudesGhislain a écrit :Moi ce qui me choc c'est la façon d'écrire ton script (je ne suis pas un pro non plus :d), pourquoi ne pas simplement mettre la partie "Attente Porte" dans la boucle ?
Autre truc tu mets la variable en "Porte fermé" au début du script mais... si la porte est déjà ouverte au lancement ?
Ton script fonctionne en lançant toi même la commande ?
Code : Tout sélectionner
mosquitto_pub -h mon.host.ext -i testPublish -t porte -m "Porte de la buanderie fermée $(date '+%H:%M:%S %d.%m.%Y')"
Super, Merci pour l'info!!!dyox a écrit :Pour info, nous n'avons plus besoin d'être root depuis un an pour le contrôle des GPIO
Le release notes de Raspiansissad a écrit : Aurais-tu une référence pour ces changements? Y a-t-il d'autre nouvelles de ce genre?
Code : Tout sélectionner
#!/bin/bash
setup ()
{
/usr/local/bin/gpio mode 29 in
porte="fermee"
}
AttentePorte ()
{
while [ 1 ]; do
if [ `/usr/local/bin/gpio read 29` = 1 ] && [ "$porte" == "fermee" ]; then
mosquitto_pub -h mon.hoste.ext -i testPublish -t porte -m "Porte de la buanderie ouverte $(date '+%H:%M:%S %d.%m.%Y')"
wget -O - -q -t 1 http://api.pushingbox.com/pushingbox?devid=XXXXXXXXXXXXXX
porte="ouverte"
fi
if [ `/usr/local/bin/gpio read 29` = 0 ] && [ "$porte" == "ouverte" ]; then
mosquitto_pub -h mon.hoste.ext -i testPublish -t porte -m "Porte de la buanderie fermée $(date '+%H:%M:%S %d.%m.%Y')"
porte="fermee"
fi
sleep 0.1
done
}
setup
while true; do
AttentePorte
done
Ghislain a écrit :As tu bien mis les chemins complet dans ton script ?
Code : Tout sélectionner
@reboot /path/script.sh &
Code : Tout sélectionner
#!/bin/bash
sleep 30
testval=0
while [ $testval -eq 0 ]
do
testval=`ping -q adressipdemonrouteur -c1 | grep -c rtt`
done
while read msg;
do
if [[ "$msg" =~ "buanderie ouverte" ]]; then
aplay /path/beep24.wav
fi
if [[ "$msg" =~ "entree ouverte" ]]; then
aplay /path/doorbell_x.wav
fi
echo $msg;
done < <(mosquitto_sub -h mon.host.ext -t topic -q 1)
Code : Tout sélectionner
crontab -e
Code : Tout sélectionner
# Edit this file to introduce tasks to be run by cron.
#
# Each task to run has to be defined through a single line
# indicating with different fields when the task will be run
# and what command to run for the task
#
# To define the time you can provide concrete values for
# minute (m), hour (h), day of month (dom), month (mon),
# and day of week (dow) or use '*' in these fields (for 'any').#
# Notice that tasks will be started based on the cron's system
# daemon's notion of time and timezones.
#
# Output of the crontab jobs (including errors) is sent through
# email to the user the crontab file belongs to (unless redirected).
#
# For example, you can run a backup of all your user accounts
# at 5 a.m every week with:
# 0 5 * * 1 tar -zcf /var/backups/home.tgz /home/
#
# For more information see the manual pages of crontab(5) and cron(8)
#
# m h dom mon dow command
@reboot /path/sonnette.sh &
Code : Tout sélectionner
#!/bin/bash
setup ()
{
/usr/local/bin/gpio mode 29 in
porte="fermee"
}
AttentePorte ()
{
while [ 1 ]; do
if [ `/usr/local/bin/gpio read 29` = 1 ] && [ "$porte" == "fermee" ]; then
mosquitto_pub -h my.host.ext -i testPublish -t porte -m "Porte de la buanderie ouverte $(date '+%H:%M:%S %d.%m.%Y')"
wget -O - -q -t 1 http://api.pushingbox.com/pushingbox?devid=vXXXXXXXXXXXXXX
porte="ouverte"
fi
if [ `/usr/local/bin/gpio read 29` = 0 ] && [ "$porte" == "ouverte" ]; then
mosquitto_pub -h my.host.ext -i testPublish -t porte -m "Porte de la buanderie fermée $(date '+%H:%M:%S %d.%m.%Y')"
porte="fermee"
fi
sleep 0.1
done
}
setup
while true; do
AttentePorte
done