#!/bin/bash # Créé par : LMQT (forum Jeedom) # Script pour : # interroger un module Bluetooth BLE, # récupérer l'information de batterie, # la formater correctement, # puis l'envoyer vers une URL, en l'occurence un virtuel de Jeedom. # Infos diverses sur les services GATT : https://www.bluetooth.com/specifications/gatt/services/ # ##### CHOIX DE L'ADAPTATEUR BLUETOOTH ##### # Sans précision "-i", interroge sur l'adaptateur par défaut (en principe hci0). # Ajouter l'option "-i hci0" ou "-i hci1" pour forcer un adaptateur BT précis. # ##### REQUETE DU NIVEAU DE BATTERIE ##### # La valeur de niveau de batterie s'interroge avec "--char-read --handle 0x001b" # ou avec "--char-read --uuid 0x2a19". # Le format de retour est différent, mais les deux renvoient la batterie en fin de ligne. # ##### CONVERSION HEXADECIMALE VERS DECIMALE # Pour convertir une valeur (ici 4b) de hexa (= base 16) en décimale, on utilise la commande # "echo $((16#4b))" ou celle-ci "printf "%d" $((16#FF))". # Nota : pour affichage écran, ajouter "\n" (retour ligne) : "printf "%d\n" $((16#FF))". function f_requete { v_retour=$(gatttool -t public -b $v_mac --char-read --uuid 0x2a19) v_erreur=$? if [ $v_erreur -eq 0 ]; then v_retour=$(echo $v_retour|awk '{print $4}') v_batt_dec=$((16#$v_retour)) echo "[&h"$v_retour"]" $v_batt_dec"%" wget -b -q -t 3 $v_jeedom$v_batt_dec else echo "Impossible de joindre le module G-Tag" $v_mac fi } echo " ___________" echo "_____/ G-Tag XXX \______________________________________" unset v_erreur; unset v_retour; v_mac="AA:BB:CC:DD:EE:FF" v_jeedom="http://xxx.xxx.xxx.xxx/core/api/jeeApi.php?apikey=XXXXXXXXXXXXXXXXXX&type=virtual&id=XXXX&value=" f_requete