Bluetooth : Xiaomi température/humidité

lol a qui le dis-tu ?!
Désolé, mais j’étais en congés la semaine dernière, j’ai repris ce matin, donc ma dispo est limitée.

@Hamtaro

Tu as besoin de quelque chose ?

Pour les appareils Xiaomi Bluetooth ? Tu en as ? Si oui, on peut se synchro pour que tu me donnes les info nécessaires pour l’intégration.
Sinon je vais voir chez les concurrents s’ils intègrent déjà ces appareils.

Comme je le disais plus haut, j’ai 4 moniteurs de température et humidité.
Ils popent dans le matos bluetooth (avec deux identifiants chacuns, un sans carac et un avec juste la batterie) sauf 1 qui doit être hors de portée.

Ok pardon, j’ai du lire de travers. Super on va organiser ça alors :slight_smile:

On a une super analyse ici.

Je peux développer à l’aveugle, maintenant reste a voir comment tu peux tester ?

  • soit je te fais un petit programme seul pour valider que ça fonctionne
  • soit une version “beta” de cette nouvelle intégration

Mais on est pas dans du standard Bluetooth, plutôt dans du Xiaomi propriétaire.

Comme tu le souhaites mais je t’avouerais qu’un petit prog à exécuter serait plus simple pour moi.
J’ai rien d’installé sur mon Mac pour Gladys.

1 « J'aime »

Hey @Hamtaro,
première version de ce petit outils.
Pour info, il se utilise la base de code du service Bluetooth de Gladys (afin de conserver un maximum de compatibilité).

Il est bien sûr à compléter avec le temps.
J’attends tes retours.

2 « J'aime »

Pour info, le service reconnaît les montres connectées Amazfit.

Il fait quoi ce prog ?
Parce que je l’ai lancé sur le pi avec l’utilisateur pi.
J’ai installé toutes les dépendances et là le npm install mais avec ma connexion actuelle due au confinement et la saturation des antennes 4G Bouygues, ça rame dans la semoule…

Ca à l’air de faire une install complète de Gladys… Je pensais que ce serais un petit prog js pour récupérer les infos bluetooth.

PS : j’ai rien dit, le dl vient de finir et ça extrait ce qu’il veut.

> usb@1.6.3 install /home/pi/gladys-bluetooth-analyzer/gladys/server/services/bluetooth/node_modules/usb
> prebuild-install --verbose || node-gyp rebuild

prebuild-install info begin Prebuild-install version 5.3.5
prebuild-install info looking for cached prebuild @ /home/pi/.npm/_prebuilds/e00ec3-usb-v1.6.3-node-v64-linux-arm.tar.gz
prebuild-install http request GET https://github.com/tessel/node-usb/releases/download/v1.6.3/usb-v1.6.3-node-v64-linux-arm.tar.gz
prebuild-install http 404 https://github.com/tessel/node-usb/releases/download/v1.6.3/usb-v1.6.3-node-v64-linux-arm.tar.gz
prebuild-install WARN install No prebuilt binaries found (target=10.21.0 runtime=node arch=arm libc= platform=linux)
make : on entre dans le répertoire « /home/pi/gladys-bluetooth-analyzer/gladys/server/services/bluetooth/node_modules/usb/build »
  CC(target) Release/obj.target/libusb/libusb/libusb/core.o
  CC(target) Release/obj.target/libusb/libusb/libusb/descriptor.o
  CC(target) Release/obj.target/libusb/libusb/libusb/hotplug.o
  CC(target) Release/obj.target/libusb/libusb/libusb/io.o
  CC(target) Release/obj.target/libusb/libusb/libusb/strerror.o
  CC(target) Release/obj.target/libusb/libusb/libusb/sync.o
  CC(target) Release/obj.target/libusb/libusb/libusb/os/poll_posix.o
  CC(target) Release/obj.target/libusb/libusb/libusb/os/threads_posix.o
  CC(target) Release/obj.target/libusb/libusb/libusb/os/linux_usbfs.o
  CC(target) Release/obj.target/libusb/libusb/libusb/os/linux_udev.o
../libusb/libusb/os/linux_udev.c:40:10: fatal error: libudev.h: Aucun fichier ou dossier de ce type
 #include <libudev.h>
          ^~~~~~~~~~~
compilation terminated.
make: *** [libusb.target.mk:140: Release/obj.target/libusb/libusb/libusb/os/linux_udev.o] Error 1
make : on quitte le répertoire « /home/pi/gladys-bluetooth-analyzer/gladys/server/services/bluetooth/node_modules/usb/build »
gyp ERR! build error 
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack     at ChildProcess.onExit (/usr/share/node-gyp/lib/build.js:262:23)
gyp ERR! stack     at ChildProcess.emit (events.js:198:13)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:248:12)
gyp ERR! System Linux 5.4.72-v7+
gyp ERR! command "/usr/bin/node" "/usr/bin/node-gyp" "rebuild"
gyp ERR! cwd /home/pi/gladys-bluetooth-analyzer/gladys/server/services/bluetooth/node_modules/usb
gyp ERR! node -v v10.21.0
gyp ERR! node-gyp -v v3.8.0
gyp ERR! not ok 

> @abandonware/bluetooth-hci-socket@0.5.3-5 install /home/pi/gladys-bluetooth-analyzer/gladys/server/services/bluetooth/node_modules/@abandonware/bluetooth-hci-socket
> node-pre-gyp install --fallback-to-build

node-pre-gyp WARN Using request for node-pre-gyp https download 
node-pre-gyp WARN Tried to download(404): https://github.com/abandonware/node-bluetooth-hci-socket/releases/download/0.5.3-5/binding-0.5.3-5-node-v64-linux-arm.tar.gz 
node-pre-gyp WARN Pre-built binaries not found for @abandonware/bluetooth-hci-socket@0.5.3-5 and node@10.21.0 (node-v64 ABI, glibc) (falling back to source compile with node-gyp) 
make : on entre dans le répertoire « /home/pi/gladys-bluetooth-analyzer/gladys/server/services/bluetooth/node_modules/@abandonware/bluetooth-hci-socket/build »
  CXX(target) Release/obj.target/binding/src/BluetoothHciSocket.o
In file included from ../src/BluetoothHciSocket.cpp:8:
../../../nan/nan.h: In function ‘void Nan::AsyncQueueWorker(Nan::AsyncWorker*)’:
../../../nan/nan.h:2294:62: warning: cast between incompatible function types from ‘void (*)(uv_work_t*)’ {aka ‘void (*)(uv_work_s*)’} to ‘uv_after_work_cb’ {aka ‘void (*)(uv_work_s*, int)’} [-Wcast-function-type]
     , reinterpret_cast<uv_after_work_cb>(AsyncExecuteComplete)
                                                              ^
In file included from /usr/include/nodejs/src/node_buffer.h:25,
                 from ../src/BluetoothHciSocket.cpp:7:
../src/BluetoothHciSocket.cpp: At global scope:
/usr/include/nodejs/src/node.h:573:43: warning: cast between incompatible function types from ‘void (*)(Nan::ADDON_REGISTER_FUNCTION_ARGS_TYPE)’ {aka ‘void (*)(v8::Local<v8::Object>)’} to ‘node::addon_register_func’ {aka ‘void (*)(v8::Local<v8::Object>, v8::Local<v8::Value>, void*)’} [-Wcast-function-type]
       (node::addon_register_func) (regfunc),                          \
                                           ^
noble warning: adapter state unauthorized, please run as root or with sudo
               or see README for information on running without root/sudo:
               https://github.com/sandeepmistry/noble#running-on-linux
/home/pi/gladys-bluetooth-analyzer/index.js:23
    quit(colors.bold.red('Something went wrong'));
    ^

TypeError: quit is not a function
    at EventEmitter.gladys.event.once (/home/pi/gladys-bluetooth-analyzer/index.js:23:5)
    at Object.onceWrapper (events.js:286:20)
    at EventEmitter.emit (events.js:198:13)
    at BluetoothManager.broadcastStatus (/home/pi/gladys-bluetooth-analyzer/gladys/server/services/bluetooth/lib/events/bluetooth.broadcastStatus.js:11:21)
    at BluetoothManager.stateChange (/home/pi/gladys-bluetooth-analyzer/gladys/server/services/bluetooth/lib/events/bluetooth.stateChange.js:21:8)
    at Noble.emit (events.js:198:13)
    at Noble.onStateChange (/home/pi/gladys-bluetooth-analyzer/gladys/server/services/bluetooth/node_modules/@abandonware/noble/lib/noble.js:87:8)
    at NobleBindings.emit (events.js:198:13)
    at NobleBindings.onStateChange (/home/pi/gladys-bluetooth-analyzer/gladys/server/services/bluetooth/node_modules/@abandonware/noble/lib/hci-socket/bindings.js:121:8)
    at Hci.emit (events.js:203:15)
    at Hci.onSocketError (/home/pi/gladys-bluetooth-analyzer/gladys/server/services/bluetooth/node_modules/@abandonware/noble/lib/hci-socket/hci.js:549:10)
    at BluetoothHciSocket.emit (events.js:198:13)
    at Hci.setEventMask (/home/pi/gladys-bluetooth-analyzer/gladys/server/services/bluetooth/node_modules/@abandonware/noble/lib/hci-socket/hci.js:165:16)
    at Hci.pollIsDevUp (/home/pi/gladys-bluetooth-analyzer/gladys/server/services/bluetooth/node_modules/@abandonware/noble/lib/hci-socket/hci.js:119:12)
    at Hci.init (/home/pi/gladys-bluetooth-analyzer/gladys/server/services/bluetooth/node_modules/@abandonware/noble/lib/hci-socket/hci.js:103:10)
    at NobleBindings.init (/home/pi/gladys-bluetooth-analyzer/gladys/server/services/bluetooth/node_modules/@abandonware/noble/lib/hci-socket/bindings.js:78:13)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! gladys-bluetooth-analyzer@1.0.0 start: `node index.js`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the gladys-bluetooth-analyzer@1.0.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/pi/.npm/_logs/2020-11-16T11_21_34_668Z-debug.log
pi@gladys:~/gladys-bluetooth-analyzer $ 

logs :

0 info it worked if it ends with ok
1 warn npm npm does not support Node.js v10.21.0
2 warn npm You should probably upgrade to a newer version of node as we
3 warn npm can't make any promises that npm will work with this version.
4 warn npm Supported releases of Node.js are the latest release of 4, 6, 7, 8, 9.
5 warn npm You can find the latest version at https://nodejs.org/
6 verbose cli [ '/usr/bin/node', '/usr/bin/npm', 'start' ]
7 info using npm@5.8.0
8 info using node@v10.21.0
9 verbose run-script [ 'prestart', 'start', 'poststart' ]
10 info lifecycle gladys-bluetooth-analyzer@1.0.0~prestart: gladys-bluetooth-analyzer@1.0.0
11 info lifecycle gladys-bluetooth-analyzer@1.0.0~start: gladys-bluetooth-analyzer@1.0.0
12 verbose lifecycle gladys-bluetooth-analyzer@1.0.0~start: unsafe-perm in lifecycle true
13 verbose lifecycle gladys-bluetooth-analyzer@1.0.0~start: PATH: /usr/share/npm/node_modules/npm-lifecycle/node-gyp-bin:/home/pi/gladys-bluetooth-analyzer/node_modules/.bin:/usr/local/sbin:/usr/local/bi$
14 verbose lifecycle gladys-bluetooth-analyzer@1.0.0~start: CWD: /home/pi/gladys-bluetooth-analyzer
15 silly lifecycle gladys-bluetooth-analyzer@1.0.0~start: Args: [ '-c', 'node index.js' ]
16 silly lifecycle gladys-bluetooth-analyzer@1.0.0~start: Returned: code: 1  signal: null
17 info lifecycle gladys-bluetooth-analyzer@1.0.0~start: Failed to exec start script
18 verbose stack Error: gladys-bluetooth-analyzer@1.0.0 start: `node index.js`
18 verbose stack Exit status 1
18 verbose stack     at EventEmitter.<anonymous> (/usr/share/npm/node_modules/npm-lifecycle/index.js:283:16)
18 verbose stack     at EventEmitter.emit (events.js:198:13)
18 verbose stack     at ChildProcess.<anonymous> (/usr/share/npm/node_modules/npm-lifecycle/lib/spawn.js:55:14)
18 verbose stack     at ChildProcess.emit (events.js:198:13)
18 verbose stack     at maybeClose (internal/child_process.js:982:16)
18 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:259:5)
19 verbose pkgid gladys-bluetooth-analyzer@1.0.0
20 verbose cwd /home/pi/gladys-bluetooth-analyzer
21 verbose Linux 5.4.72-v7+
22 verbose argv "/usr/bin/node" "/usr/bin/npm" "start"
23 verbose node v10.21.0
24 verbose npm  v5.8.0
25 error code ELIFECYCLE
26 error errno 1
27 error gladys-bluetooth-analyzer@1.0.0 start: `node index.js`
27 error Exit status 1
28 error Failed at the gladys-bluetooth-analyzer@1.0.0 start script.
28 error This is probably not a problem with npm. There is likely additional logging output above.
29 verbose exit [ 1, true ]

2 « J'aime »

Lol ok bug première ligne… je retente ma chance…
Mais sinon il faut donner les droits Bluetooth à NPM, chose que je vais ajouter dans le readme.

Le programme va servir à verifier que le code proposé va bien récupérer les données de ton appareil Bluetooth.
Il copie une sous partie de Gladys car j’ai pas mal bossé sur le Bluetooth, et que maintenant que c’est fait, je recommence pas.

Je te dis quand c’est à jour.

Super, tu peux retenter stp ? Il arrive que le Bluetooth “galère” a se connecter à l’appareil. Et il faut s’assurer que l’appareil ne soit pas déjà connecté à un autre…
Tu peux voir qu’il a réussi à se connecter si dans les params du device tu as le manufacturer (ou le modèle).

oh ! Et ça fait quoi de beau ?
J’ai vu que ça déchiffrait les données envoyées en bluetooth mais apparemment, tu peux exécuter tes propres prog dessus ?

Du coup, ça devrait simplifier la récupération des données en bluetooth.

Par curiosité est-ce que ce service peut permettre de récup les infos de ce capteur Xiaomi ?

Je ne peux pas te le confirmer, je n’ai pas étudié la question, mais pour ne pas oublier, tu peux toujours creer une issue sur le github du petit programme.
Je te dirais bien d’essayer mais il a quelques manip pour activer le Bluetooth sous npm, je dois donc compléter la doc et fixer un premier bug.

En gros ce outils (me) servira a tester et valider qu’un périphérique Bluetooth rentre bien dans Gladys.

Ce n’est pas un super outils Bluetooth générique qui fait tout, on est vraiment au cas par cas.

1 « J'aime »

Ok ça marche, merci pour ces détails !

Ok j’ai mis à jour la libraire en rapport aux logs d’erreur.
Il faudra suivre les instructions selon l’OS du PC.
Une fois les instructions à jour, il faudra mettre à jour l’outils en local avec git pull (pour ceux qui ont déjà cloner l’outils).

Je vais tenter de l’améliorer au fur et à mesure.

✔ This tools is used to test your Bluetooth device with Gladys, do you want to continue? … yes
✔ Select the service you want to test › Xiaomi
✔ Next step is scanning for Bluetooth devices, continue? … yes
✔ Select device you want to analyse: › a4:c1:38:0c:c2:f9 - LYWSD03MMC
 -> Device:
    - Name: LYWSD03MMC
    - Model: LYWSD03MMC
    - 1 features
      - battery / integer
    - 2 params
      - loaded: true
      - manufacturer: miaomiaoce.com
✔ Continue with Xiaomi service on this device? … yes
Now executing Xiaomi steps...
✔ Select model you want to check: › LYWSD03MMC
{ Error: Bluetooth: no services found for a4c1380cc2f9
    at peripheral.discoverServices (/home/pi/gladys-bluetooth-analyzer/gladys/server/services/bluetooth/lib/utils/peripheral/bluetooth.discoverServices.js:27:16)
    at Peripheral.once.services (/home/pi/gladys-bluetooth-analyzer/gladys/server/services/bluetooth/node_modules/@abandonware/noble/lib/peripheral.js:81:7)
    at Object.onceWrapper (events.js:286:20)
    at Peripheral.emit (events.js:198:13)
    at Noble.onServicesDiscover (/home/pi/gladys-bluetooth-analyzer/gladys/server/services/bluetooth/node_modules/@abandonware/noble/lib/noble.js:309:16)
    at NobleBindings.emit (events.js:198:13)
    at NobleBindings.onServicesDiscovered (/home/pi/gladys-bluetooth-analyzer/gladys/server/services/bluetooth/node_modules/@abandonware/noble/lib/hci-socket/bindings.js:317:8)
    at Gatt.emit (events.js:198:13)
    at Object.callback (/home/pi/gladys-bluetooth-analyzer/gladys/server/services/bluetooth/node_modules/@abandonware/noble/lib/hci-socket/gatt.js:369:12)
    at Gatt.onAclStreamData (/home/pi/gladys-bluetooth-analyzer/gladys/server/services/bluetooth/node_modules/@abandonware/noble/lib/hci-socket/gatt.js:133:26)
    at AclStream.emit (events.js:203:15)
    at AclStream.push (/home/pi/gladys-bluetooth-analyzer/gladys/server/services/bluetooth/node_modules/@abandonware/noble/lib/hci-socket/acl-stream.js:33:10)
    at NobleBindings.onAclDataPkt (/home/pi/gladys-bluetooth-analyzer/gladys/server/services/bluetooth/node_modules/@abandonware/noble/lib/hci-socket/bindings.js:288:15)
    at Hci.emit (events.js:198:13)
    at Hci.onSocketData (/home/pi/gladys-bluetooth-analyzer/gladys/server/services/bluetooth/node_modules/@abandonware/noble/lib/hci-socket/hci.js:501:14)
    at BluetoothHciSocket.emit (events.js:198:13) message: 'Bluetooth: no services found for a4c1380cc2f9' }

Je réessaie avec d’autres.
Il m’en a détecté 3 au premier essai, puis 2 au second, sur 4 (1 est hors de portée je pense et 1 à la limite)

✔ This tools is used to test your Bluetooth device with Gladys, do you want to continue? … yes
✔ Select the service you want to test › Xiaomi
✔ Next step is scanning for Bluetooth devices, continue? … yes
✔ Select device you want to analyse: › a4:c1:38:6f:99:ab - LYWSD03MMC
 -> Device:
    - Name: LYWSD03MMC
    - Model: LYWSD03MMC
    - 1 features
      - battery / integer
    - 2 params
      - loaded: true
      - manufacturer: miaomiaoce.com
✔ Continue with Xiaomi service on this device? … yes
Now executing Xiaomi steps...
✔ Select model you want to check: › LYWSD03MMC
{ Error: Bluetooth: no services found for a4c1386f99ab
    at peripheral.discoverServices (/home/pi/gladys-bluetooth-analyzer/gladys/server/services/bluetooth/lib/utils/peripheral/bluetooth.discoverServices.js:27:16)
    at Peripheral.once.services (/home/pi/gladys-bluetooth-analyzer/gladys/server/services/bluetooth/node_modules/@abandonware/noble/lib/peripheral.js:81:7)
    at Object.onceWrapper (events.js:286:20)
    at Peripheral.emit (events.js:198:13)
    at Noble.onServicesDiscover (/home/pi/gladys-bluetooth-analyzer/gladys/server/services/bluetooth/node_modules/@abandonware/noble/lib/noble.js:309:16)
    at NobleBindings.emit (events.js:198:13)
    at NobleBindings.onServicesDiscovered (/home/pi/gladys-bluetooth-analyzer/gladys/server/services/bluetooth/node_modules/@abandonware/noble/lib/hci-socket/bindings.js:317:8)
    at Gatt.emit (events.js:198:13)
    at Object.callback (/home/pi/gladys-bluetooth-analyzer/gladys/server/services/bluetooth/node_modules/@abandonware/noble/lib/hci-socket/gatt.js:369:12)
    at Gatt.onAclStreamData (/home/pi/gladys-bluetooth-analyzer/gladys/server/services/bluetooth/node_modules/@abandonware/noble/lib/hci-socket/gatt.js:133:26)
    at AclStream.emit (events.js:203:15)
    at AclStream.push (/home/pi/gladys-bluetooth-analyzer/gladys/server/services/bluetooth/node_modules/@abandonware/noble/lib/hci-socket/acl-stream.js:33:10)
    at NobleBindings.onAclDataPkt (/home/pi/gladys-bluetooth-analyzer/gladys/server/services/bluetooth/node_modules/@abandonware/noble/lib/hci-socket/bindings.js:288:15)
    at Hci.emit (events.js:198:13)
    at Hci.onSocketData (/home/pi/gladys-bluetooth-analyzer/gladys/server/services/bluetooth/node_modules/@abandonware/noble/lib/hci-socket/hci.js:501:14)
    at BluetoothHciSocket.emit (events.js:198:13) message: 'Bluetooth: no services found for a4c1386f99ab' }

Même réponse sur un autre.
Le 3ème est aléatoire au niveau de sa présence…
Ca existe du répéteur bluetooth ? :stuck_out_tongue:

Et avec celui la LYWSD03MMC tu as essayé plusieurs fois ?
Il faut savoir que le Bluetooth n’est pas une science sûre :stuck_out_tongue:
En revanche, si au bout de 3 / 4 fois (ce que tu as fait si je comprends bien) tu n’as toujours rien, c’est que je n’ai pas la bonne technique pour ce device, je vais donc voir d’autres sites pour trouver la bonne manière de se connecter au LYWSD03MMC.