Table of Contents
Utilisation du PWM
Apparemment seul la pin n°1 pourrait être utilisée comme PWM hardware. le soft gpio pourrait émuler le PWM en software mais ça doit être testé.
#activée en pwm gpio mode 1 pwm
#séquence & séquence inversée 0 ⇒ 1023 SEQ=`seq 0 10 1023` SEQR=`seq 0 10 1023 | tac`
for STEP in `echo $SEQ`; do
gpio pwm 1 $STEP
sleep 0.01
done
sleep 1
for STEP in `echo $SEQR`; do
gpio pwm 1 $STEP
sleep 0.01
done
Script général utilisant les 2 autres scripts
#init all pins used into this script gpio mode 5 output gpio mode 6 output gpio mode 7 output
gpio mode 1 output
#while true, never stop while [ 1 ] do
gpio write 6 1;
nbTunnels=`./monitorTunnel.sh`;
rNbTunnels=$?;
nbUsers=`./monitorServer.sh`;
rNbUsers=$?
if [ "$rNbTunnels" -ne "0" ] || [ "$rNbUsers" -ne "0" ]; then
nbUsers=0;
nbTunnels=0;
gpio write 7 1;
gpio write 5 1;
sleep 0.5;
gpio write 7 0;
gpio write 5 0;
fi
gpio write 6 0;
#Ten times before a status' recheck
for i in $(seq 1 10)
do
# if at least a user is connected
if [ "$nbUsers" -gt "0" ]; then
# 1 fast flashing led (0.3 sec) for 1 user
for userId in $(seq 1 $nbUsers)
do
gpio write 7 1;
sleep 0.3;
gpio write 7 0;
sleep 0.3;
done
fi
# if no user found flash another led to tell 'hoho I'm still working'
if [ "$nbUsers" -le "0" ]; then
gpio write 5 1;
fi
if [ "$nbTunnels" -gt "0" ]; then
gpio write 1 1;
fi
sleep 0.1;
if [ "$nbUsers" -le "0" ]; then
gpio write 5 0;
fi
if [ "$nbTunnels" -gt "0" ]; then
gpio write 1 0;
fi
# wait 1 seconds (to make a clear distinction between data and 'waiting')
sleep 1;
done
done
Monitorage de serveur minecraft
#url to get informations on server (json format) URL='http://mc.helpcomputer.org:8123/up/world/john/'
#build status url (add a unix timestamp at the end) status=$URL`date +%s`;
wget=`wget –quiet –output-document=- “$status”`; rWget=$?;
if [ $rWget -ne 0 ]; then
exit $rWget;
fi
#wget it over stdout and grep only interesting items (nb connected on server) nbUsers=`echo “$wget” | grep –only-matching '“currentcount”:[0-9]*' | cut -d':' -f2`;
echo $nbUsers; exit 0;
Monitorage de tunnel
#search pids of auto ssh running instance PID_LIST=`pidof autossh`; #get all 'busy' connections NETSTAT=`netstat –tcp –program 2> /dev/null`; #should run as the same user or into root
NB_TUNNELS=0; for PID_PARENT in $PID_LIST do
#get the pid of the cild (in this case the ssh process)
PID=`pgrep -P $PID_PARENT`;
rPID=$?;
if [ $rPID -eq 0 ]; then
#get the number of established found into call
LINE=`echo "$NETSTAT" | grep $PID | grep 'ESTABLISHED' --count`;
#add this number to nb tunnels
NB_TUNNELS=$(($NB_TUNNELS + $LINE));
fi
done
echo $NB_TUNNELS; exit 0;
Contrôle en bash et via wiring pi des ports GPIO (vieille version cfr ci dessus)
En gros le script permet de faire un call wget sur un serveur et d'allumer 3 leds différentes selon le nombre d'utilisateurs connectés au serveur minecraft.
Et voici le schéma associé (fait en SVG) et utilisant des transistors de façon à utiliser un ampérage minimal auprès du raspberry :
- seulement 0.18 mA sont utilisés sur chaque port GPIO allumé
- pour envoyer +- 17 mA sur la LED (via l'alimentation 5v disponible sur le haut du schéma)
#!/bin/sh
#url to get informations on server (json format) URL='http://mc.helpcomputer.org:8123/up/world/john/'
#init all pins used into this script gpio mode 2 output gpio mode 3 output gpio mode 4 output
#while true, never stop while [ 1 ] do
#build status url (add a unix timestamp at the end)
status=$URL`date +%s`;
gpio write 2 1;
#wget it over stdout and grep only interesting items (nb connected on server)
nbUsers=`wget --quiet --output-document=- "$status" | grep --only-matching '"currentcount":[0-9]*' | cut -d':' -f2`;
gpio write 2 0;
#Ten times before a status' recheck
for i in $(seq 1 10)
do
# if at least a user is connected
if [ $nbUsers -ne 0 ]
then
# 1 fast flashing led (0.3 sec) for 1 user
for userId in $(seq 1 $nbUsers)
do
gpio write 3 1;
sleep 0.3;
gpio write 3 0;
sleep 0.3;
done
else
# if no user found flash another led to tell 'hoho I'm still working'
gpio write 4 1;
sleep 0.1;
gpio write 4 0;
fi
# wait 3 seconds (to make a clear distinction between data and 'waiting')
sleep 3;
done
done
