dimanche 19 mai 2019

Rendre l'antenne BLEA autonome pour Jeedom

Mise en place de systemd sur antenne BLEA pour jeedom. (Raspberry Pi Zero W)

 Mon antenne blea:


Avec la configuration suivante, cela permet d'une part de démarrer le deamon blea automatiquement, mais en plus, systemd surveille le process et le redémarre si celui ci tombe, ce qui arrive fréquemment avec ce plugin, certainement lié à l'instabilité du bluetooth.

Dans /etc/systemd/system, ajouter le fichier blearpistart.service

[Unit]
Description=BlEA service
After=hciuart.service

[Service]
Type=simple
PIDFile=/tmp/blead.pid
ExecStart=/home/pi/blearpistart start
Restart=always
RestartSec=3

[Install]
WantedBy=multi-user.target
Le fichier blearpistart est un script bash que j'ai positionné dans /home/pi:

#! /bin/sh

# If you want a command to always run, put it here
touch /tmp/blea
chmod 666 /tmp/blea

# Carry out specific functions when asked to by the system
case "$1" in
  start)
    echo "Starting BLEA"
    # run application you want to start
    /usr/bin/python /home/pi/blead/resources/blead/blead.py --loglevel error --device hci0 --socketport 55008 --sockethost "" --callback http://192.168.1.5/plugins/blea/core/php/jeeBlea.php --apikey xxxxxxxxxxxxxxxxxxxxxx --daemonname "antennaBLEA1" >> /tmp/blea 2>&1
    ;;
  stop)
    echo "Stopping BLEA"
    # kill application you want to stop
    sudo kill `ps -ef | grep blea | grep -v grep | awk '{print $2}'`
    ;;
  *)
    echo "Usage: blearpistart {start|stop}"
    exit 1
    ;;
esac

exit 0
La commande python est récupérable en vérifiant les process qui tournent:

pi@antennaBLEA1:/etc/systemd/system $ ps -ef | grep blead.py
root      7778  7775 23 20:02 ?        00:00:15 /usr/bin/python /home/pi/blead/resources/blead/blead.py --loglevel error --device hci0 --socketport 55008 --sockethost  --callback http://192.168.1.5/plugins/blea/core/php/jeeBlea.php --apikey xxxxxxxxxxxxxxxxxxxxxxx --daemonname antennaBLEA1
pi        8243 19986  0 20:03 pts/0    00:00:00 grep --color=auto blead.py
Activer systemd pour le service blearpistart.service

sudo systemctl enable blearpistart.service
systemctl start blearpistart.service
systemctl status blearpistart.service