Raspberry/Munin : Plugin pour Awox pour suivre la consommation.

461 x served & 165 x viewed

La première étape est de voir si le Bluetooth est bien lancé au démarrage :

$ dmesg | grep -i blue
[   11.903994] Bluetooth: Core ver 2.22
[   11.904056] Bluetooth: HCI device and connection manager initialized
[   11.904073] Bluetooth: HCI socket layer initialized
[   11.904080] Bluetooth: L2CAP socket layer initialized
[   11.904098] Bluetooth: SCO socket layer initialized
[   11.913494] Bluetooth: HCI UART driver ver 2.3
[   11.913506] Bluetooth: HCI UART protocol H4 registered
[   11.913509] Bluetooth: HCI UART protocol Three-wire (H5) registered
[   11.913652] Bluetooth: HCI UART protocol Broadcom registered
[   12.098214] Bluetooth: BNEP (Ethernet Emulation) ver 1.3
[   12.098223] Bluetooth: BNEP filters: protocol multicast
[   12.098245] Bluetooth: BNEP socket layer initialized

$ sudo systemctl status bluetooth*
● bluetooth.target - Bluetooth
   Loaded: loaded (/lib/systemd/system/bluetooth.target; static; vendor preset: enabled)
   Active: active since Tue 2018-10-09 16:17:10 UTC; 2 days ago
     Docs: man:systemd.special(7)

Warning: Journal has been rotated since unit was started. Log output is incomplete or unavailable.

● bluetooth.service - Bluetooth service
   Loaded: loaded (/lib/systemd/system/bluetooth.service; enabled; vendor preset: enabled)
   Active: active (running) since Tue 2018-10-09 16:17:10 UTC; 2 days ago
     Docs: man:bluetoothd(8)
 Main PID: 812 (bluetoothd)
   Status: "Running"
   CGroup: /system.slice/bluetooth.service
           └─812 /usr/lib/bluetooth/bluetoothd

Warning: Journal has been rotated since unit was started. Log output is incomplete or unavailable.

A noter pour que cela fonctionne bien j’ai du ajouter le service hciuart :

$ sudo systemctl enable hciuart
$ sudo systemctl start hciuart
$ systemctl status hciuart.service
● hciuart.service - Configure Bluetooth Modems connected by UART
   Loaded: loaded (/lib/systemd/system/hciuart.service; enabled; vendor preset: enabled)
   Active: active (running) since Tue 2018-10-09 16:17:10 UTC; 2 days ago
 Main PID: 803 (hciattach)
   CGroup: /system.slice/hciuart.service
           └─803 /usr/bin/hciattach /dev/serial1 bcm43xx 3000000 flow - b8:27:eb:23:8b:15

Warning: Journal has been rotated since unit was started. Log output is incomplete or unavailable.

Je vais me servir du projet suivant : https://github.com/sourceperl/smartplugctl ( Little utility for control Awox BLE smartPlug SMP-B16-FR : http://www.awox.com/wp-content/uploads/2016/07/User_Guide_SMP-B16.pdf ) .
Voici donc la liste des commandes pour faire un plugin pour Munin afin de mieux suivre la consommation :

$ sudo apt-get install -y python-pip libglib2.0-dev
$ sudo pip install bluepy
$ sudo apt-get install -y python-setuptools
Reading package lists... Done
Building dependency tree       
Reading state information... Done
python-setuptools is already the newest version (33.1.1-1).
python-setuptools set to manually installed.
0 upgraded, 0 newly installed, 0 to remove and 44 not upgraded.
$ git clone https://github.com/sourceperl/smartplugctl.git
$ cd smartplugctl
$ sudo python setup.py install

Une fois l’installation faite, on fait un SCAN afin d’avoir la référence du AWOX :

$ sudo smartplugscan

Pour faire un scan, on peut aussi faire :

$ sudo hcitool lescan --duplicates

Ou encore

$ sudo bluetoothctl 
[NEW] Controller B8:27:EB:23:8B:15 RASP3 [default]
[bluetooth]# power on
Changing power on succeeded
[bluetooth]# agent on
Agent registered
[bluetooth]# default-agent
Default agent request successful
[bluetooth]# scan on
Discovery started

A noter aussi que pour supprimer l’erreur : « Failed to obtain handles for « Service Changed » characteristic »

$ sudo systemctl status bluetooth.service
● bluetooth.service - Bluetooth service
   Loaded: loaded (/lib/systemd/system/bluetooth.service; enabled; vendor preset: enabled)
   Active: active (running) since Thu 2018-10-11 20:07:44 UTC; 4s ago
     Docs: man:bluetoothd(8)
 Main PID: 1079 (bluetoothd)
   Status: "Running"
   CGroup: /system.slice/bluetooth.service
           └─1079 /usr/lib/bluetooth/bluetoothd

Oct 11 20:07:43 RASP3 systemd[1]: Starting Bluetooth service...
Oct 11 20:07:44 RASP3 bluetoothd[1079]: Bluetooth daemon 5.43
Oct 11 20:07:44 RASP3 systemd[1]: Started Bluetooth service.
Oct 11 20:07:44 RASP3 bluetoothd[1079]: Starting SDP server
Oct 11 20:07:44 RASP3 bluetoothd[1079]: Bluetooth management interface 1.14 initialized
Oct 11 20:07:44 RASP3 bluetoothd[1079]: Failed to obtain handles for "Service Changed" characteristic
Oct 11 20:07:44 RASP3 bluetoothd[1079]: Sap driver initialization failed.
Oct 11 20:07:44 RASP3 bluetoothd[1079]: sap-server: Operation not permitted (1)

Il faut faire:

 sudo sed -i 's|^ExecStart=/usr/lib/bluetooth/bluetoothd$|ExecStart=/usr/lib/bluetooth/bluetoothd --noplugin=sap|' /lib/systemd/system/bluetooth.service

A noter aussi qu’il faut faire ceci :

$ sudo adduser pi bluetooth
$ newgrp bluetooth

Cela permet aussi de débloquer certains problèmes de droits, ..

La fin de l’article a été supprimé, car AWOX n’est pas de bonne qualité ….

Laisser un commentaire

Votre adresse e-mail ne sera pas publiée. Les champs obligatoires sont indiqués avec *

Time limit is exhausted. Please reload CAPTCHA.