#!/bin/bash # FIX for web interface chmod 777 /opt/banc/config.ini chmod 777 /opt/banc/releves -R # UP HAT MBUS if [ -f "/tmp/star-menu-first-launch" ]; then /usr/bin/gpio write 25 1 fi #### Initialisation des variables #### #+ Mode normal RESETCOLOR="$(tput sgr0)" # "Surligné" (bold) SURLIGNE=$(tput smso) # "Non-Surligné" (offbold) NONSURLIGNE=$(tput rmso) # Couleurs (gras) #+ Rouge ROUGE="$(tput bold ; tput setaf 1)" #+ Vert VERT="$(tput bold ; tput setaf 2)" #+ Jaune JAUNE="$(tput bold ; tput setaf 3)" #+ Bleu BLEU="$(tput bold ; tput setaf 4)" #+ Cyan CYAN="$(tput bold ; tput setaf 6)" function cleanup { pkill -P $$ } trap cleanup EXIT function autoaquisition { pkill -P $$ cd /opt/banc clear python3 aquisition.py } trap autoaquisition TERM function autolaunchaquisition() { sleep 1800 #~ sleep 6 if [ -f "/tmp/star-menu-first-launch" ]; then # Envoyer le signal pour lancer l'aquisition auto sur le programme primaire kill -TERM $$ fi } while [ 1 ]; do clear echo echo " ${JAUNE}AFPMA" echo -n ${RESETCOLOR} echo " Banc ECS" echo if [ -f "/tmp/star-menu-first-launch" ]; then echo -n ${ROUGE} echo "(Sans actio : lancement automatique de l'aquisition à +30min du démarrage)" echo -n ${RESETCOLOR} autolaunchaquisition & echo fi echo "Que voulez vous faire ?" echo " 1 - Lancer une aquisition de donnée" echo " 2 - Afficher la date et l'heure" echo " 3 - Changer la date et l'heure" echo " 4 - Tester un relevé sur le compteur d'énergie" echo " 5 - Allumer le HAT" echo " 6 - Eteindre le HAT" echo " 9 - Lancer l'invité de commande (bash) " read -p "Enter votre choix : " menu rm /tmp/star-menu-first-launch 2>/dev/null if [[ "$menu" == "" ]] ; then continue elif ! [[ "$menu" =~ ^[1-6]$ ]] && ! [[ "$menu" == "9" ]] ; then echo "*** Erreur : Choix invalide *** " sleep 2 continue fi pkill -P $$ if [ "$menu" == "1" ]; then clear cd /opt/banc python3 aquisition.py elif [ "$menu" == "2" ]; then clear echo date echo echo "Retour dans 10s" sleep 10 elif [ "$menu" == "3" ]; then clear echo echo "Entrée la date au format 'YYYY-MM-DD HH:MM:SS' " echo " * YYYY = année - MM = mois - DD = jour" echo " * HH = heure : MM = minute : SS = seconde" echo echo "Exemple pour la date le 12 janvier 2023 à 12:02" echo "Indiquez : 2023-01-12 12:02:00" echo read -p "Enter la date : " dateset timedatectl set-time "${dateset}" elif [ "$menu" == "4" ]; then clear echo "Attente des données..." echo -n ${BLEU} echo /usr/bin/python3 /opt/banc/mbus-serial-request-data.py /dev/ttyAMA0 &> /opt/banc/releves/test-releve.txt cat /opt/banc/releves/test-releve.txt echo echo -n ${RESETCOLOR} echo "Retrouvé le test de relevé dans 'Télécharger les relevés' > test-releve.txt" echo "Retour dans 30s" sleep 30 elif [ "$menu" == "5" ]; then clear echo "Allumage du HAT (la LED rouge doit s'allumer)" echo -n ${BLEU} gpio write 25 1 echo -n ${RESETCOLOR} echo "Retour dans 10s" sleep 10 elif [ "$menu" == "6" ]; then clear echo "Extinction du HAT (la LED rouge doit s'éteindre)" echo -n ${BLEU} gpio write 25 0 echo -n ${RESETCOLOR} echo "Retour dans 10s" sleep 10 elif [ "$menu" == "9" ]; then clear /bin/bash else echo "Erreur choix inconnu" sleep 2 fi done