Bluetooth: Xiaomi temperature/humidity

Oh! And what does it do?
I saw that it decrypted the data sent over Bluetooth, but apparently, you can run your own programs on it?

So, this should simplify Bluetooth data retrieval.

Out of curiosity, can this service be used to retrieve information from this Xiaomi sensor?

I can’t confirm that for you, I haven’t studied the matter, but to not forget, you can always create an issue on the GitHub of the small program.

I would tell you to try it, but there are a few manipulations to activate Bluetooth under npm, so I need to complete the documentation and fix a first bug.

In short, this tool (me) will be used to test and validate that a Bluetooth device is properly integrated into Gladys.

This is not a super generic Bluetooth tool that does everything, we are really on a case-by-case basis.

Got it, thanks for the details!

Ok, I have updated the library related to error logs.
You will need to follow the instructions according to the PC’s OS.
Once the instructions are up to date, you will need to update the tool locally with git pull (for those who have already cloned the tool).

I will try to improve it gradually.

✔ This tool 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' }

I will try with others.
It detected 3 on the first attempt, then 2 on the second, out of 4 (1 is out of range I think and 1 is on the limit)

✔ This tool 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' }

Same response on another one.
The third one is random in terms of its presence

Do Bluetooth repeaters exist? :stuck_out_tongue:

Have you tried several times with the LYWSD03MMC?
You should know that Bluetooth is not an exact science :stuck_out_tongue:
However, if after 3 or 4 attempts (which you’ve done, as far as I understand) you still get nothing, it means I don’t have the right technique for this device. I will therefore look at other sites to find the right way to connect to the LYWSD03MMC.

✔ This tool 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: â€ș - Use arrow-keys. Return to submit.
❯   57:e6:74:6e:f4:5e
    6a:1b:c2:5f:3d:e5
    a4:c1:38:6f:99:ab - LYWSD03MMC
    60:4c:7e:5b:25:e6
    a4:c1:38:c2:1a:8f - LYWSD03MMC

It seems like the protocol isn’t very stable.
I have a lot of variations in the scans. Do you think flashing them could improve it?

Nothing is flashing.

It sometimes happens that devices are not visible, because the scan is done in 5 seconds, which may be a bit short if you scan in a loop.

It’s mainly the NPM library that is not ultra stable.
That’s exactly why I insist on using the same one as Gladys, so as not to have any surprises.

But we’ll get there, keep up the good work :wink:

@Hamtaro I just delivered a version to scan the device in a more generic way.
It will scan all the visible ports of the device :wink:
However, in addition to git pull, you will need to run npm install again :slightly_smiling_face:

There is now a generic service, what do you want me to go through?
I tried again in a « classic Â» way:

✔ Select device you want to analyse: â€ș a4:c1:38:c2:1a:8f - LYWSD03MMC
  → Device:
    - Name: LYWSD03MMC
    - Model: undefined
    - 0 features
    - 1 params
      - loaded: true
✔ Continue with Generic service on this device? 
 yes
Now executing Generic steps...
✔ This mode will try to scan your peripheral to get maximum information, continue? 
 yes
{ Error: Bluetooth: no characteristics found for service 1800
    at service.discoverCharacteristics (/home/pi/gladys-bluetooth-analyzer/gladys/server/services/bluetooth/lib/utils/service/bluetooth.discoverCharacteristics.js:27:16)
    at Service.once.characteristics (/home/pi/gladys-bluetooth-analyzer/gladys/server/services/bluetooth/node_modules/@abandonware/noble/lib/service.js:56:7)
    at Object.onceWrapper (events.js:286:20)
    at Service.emit (events.js:198:13)
    at Noble.onCharacteristicsDiscover (/home/pi/gladys-bluetooth-analyzer/gladys/server/services/bluetooth/node_modules/@abandonware/noble/lib/noble.js:398:13)
    at NobleBindings.emit (events.js:198:13)
    at NobleBindings.onCharacteristicsDiscovered (/home/pi/gladys-bluetooth-analyzer/gladys/server/services/bluetooth/node_modules/@abandonware/noble/lib/hci-socket/bindings.js:368: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:515: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 characteristics found for service 1800' }
pi@gladys:~/gladys-bluetooth-analyzer $

Try with the generic mode to list the available services, from there I could try to fix the Xiaomi mode.

Boom ! :wink:

✔ Select device you want to analyse: â€ș a4:c1:38:6f:99:ab - LYWSD03MMC
 -> Device:
    - Name: LYWSD03MMC
    - Model: undefined
    - 0 features
    - 1 params
      - loaded: true
✔ Continue with Generic service on this device? 
 yes
Now executing Generic steps...
✔ This mode will try to scan your peripheral to get maximum information, continue? 
 yes
 -> Peripheral:
   -> Address type: public
   -> Connectable: true
   -> Advertisement:
     -> Local name: LYWSD03MMC
     -> Services: 
   -> Services (3):
     -> 1800 (Generic Access)
       -> Characteristics (3):
         -> 2a00 (Device Name): read,notify
         -> 2a01 (Appearance): read
         -> 2a04 (Peripheral Preferred Connection Parameters): read
     -> 1801 (Generic Attribute)
       -> Characteristics (1):
         -> 2a05 (Service Changed): indicate
     -> 180a (Device Information)
       -> Characteristics (6):
         -> 2a24 (Model Number String): read
         -> 2a25 (Serial Number String): read
         -> 2a26 (Firmware Revision String): read
         -> 2a27 (Hardware Revision String): read
         -> 2a28 (Software Revision String): read
         -> 2a29 (Manufacturer Name String): read
✔ Did your analyse ends with success? 
 yes
HURRAY!!!
Please give back following data on https://github.com/atrovato/gladys-bluetooth-analyzer/issues GitHub issues
Bye!

Okay great, I just (re)updated the project taking these data into account.
A quick git pull and you can retest with Xiaomi?

✔ Select device you want to analyse: â€ș a4:c1:38:6f:99:ab - LYWSD03MMC
 -> Device:
    - Name: LYWSD03MMC
    - Model: undefined
    - 0 features
    - 1 params
      - loaded: true
✔ Continue with Xiaomi service on this device? 
 yes
Now executing Xiaomi steps...
✔ Select model you want to check: â€ș LYWSD03MMC
{ Error: Bluetooth: no characteristics found for service 1801
    at service.discoverCharacteristics (/home/pi/gladys-bluetooth-analyzer/gladys/server/services/bluetooth/lib/utils/service/bluetooth.discoverCharacteristics.js:27:16)
    at Service.once.characteristics (/home/pi/gladys-bluetooth-analyzer/gladys/server/services/bluetooth/node_modules/@abandonware/noble/lib/service.js:56:7)
    at Object.onceWrapper (events.js:286:20)
    at Service.emit (events.js:198:13)
    at Noble.onCharacteristicsDiscover (/home/pi/gladys-bluetooth-analyzer/gladys/server/services/bluetooth/node_modules/@abandonware/noble/lib/noble.js:398:13)
    at NobleBindings.emit (events.js:198:13)
    at NobleBindings.onCharacteristicsDiscovered (/home/pi/gladys-bluetooth-analyzer/gladys/server/services/bluetooth/node_modules/@abandonware/noble/lib/hci-socket/bindings.js:368: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:515: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 characteristics found for service 1801' }

I’m annoying but have you tried several times?

Because this isn’t a good sign :confused:

✔ Select device you want to analyse: â€ș a4:c1:38:6f:99:ab - LYWSD03MMC
 -> Device:
    - Name: LYWSD03MMC
    - Model: undefined
    - 0 features
    - 1 params
      - loaded: true
✔ Continue with Generic service on this device? 
 yes
Now executing Generic steps...
✔ This mode will try to scan your peripheral to get maximum information, continue? 
 yes
No services found.
 -> Peripheral:
   -> Address type: public
   -> Connectable: true
   -> Advertisement:
     -> Local name: LYWSD03MMC
     -> Services:
   -> Services (0):
✔ Did your analyse ends with success? 
 yes
HURRAY!!!
Please give back following data on https://github.com/atrovato/gladys-bluetooth-analyzer/issues GitHub issues
Bye!

I continue

✔ Select device you want to analyse: â€ș a4:c1:38:c2:1a:8f - LYWSD03MMC
 -> Device:
    - Name: LYWSD03MMC
    - Model: LYWSD03MMC
    - 1 features
      - battery / integer
    - 2 params
      - loaded: true
      - manufacturer: miaomiaoce.com
✔ Continue with Generic service on this device? 
 yes
Now executing Generic steps...
✔ This mode will try to scan your peripheral to get maximum information, continue? 
 yes
{ Error: Bluetooth: no characteristics found for service 1800
    at service.discoverCharacteristics (/home/pi/gladys-bluetooth-analyzer/gladys/server/services/bluetooth/lib/utils/service/bluetooth.discoverCharacteristics.js:27:16)
    at Service.once.characteristics (/home/pi/gladys-bluetooth-analyzer/gladys/server/services/bluetooth/node_modules/@abandonware/noble/lib/service.js:56:7)
    at Object.onceWrapper (events.js:286:20)
    at Service.emit (events.js:198:13)
    at Noble.onCharacteristicsDiscover (/home/pi/gladys-bluetooth-analyzer/gladys/server/services/bluetooth/node_modules/@abandonware/noble/lib/noble.js:398:13)
    at NobleBindings.emit (events.js:198:13)
    at NobleBindings.onCharacteristicsDiscovered (/home/pi/gladys-bluetooth-analyzer/gladys/server/services/bluetooth/node_modules/@abandonware/noble/lib/hci-socket/bindings.js:368: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:515: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 characteristics found for service 1800' }

Another

✔ Select device you want to analyse: â€ș a4:c1:38:b8:ba:2a - LYWSD03MMC
 -> Device:
    - Name: LYWSD03MMC
    - Model: undefined
    - 0 features
    - 1 params
      - loaded: true
✔ Continue with Generic service on this device? 
 yes
Now executing Generic steps...
✔ This mode will try to scan your peripheral to get maximum information, continue? 
 yes
◑ Connecting to device...TimeoutError: operation timed out
    at afterTimeout (/home/pi/gladys-bluetooth-analyzer/gladys/server/services/bluetooth/node_modules/bluebird/js/release/timers.js:46:19)
    at Timeout.timeoutTimeout [as _onTimeout] (/home/pi/gladys-bluetooth-analyzer/gladys/server/services/bluetooth/node_modules/bluebird/js/release/timers.js:76:13)
    at ontimeout (timers.js:436:11)
    at tryOnTimeout (timers.js:300:5)
    at listOnTimeout (timers.js:263:5)
    at Timer.processTimers (timers.js:223:10)

Again

✔ Select device you want to analyse: â€ș a4:c1:38:b8:ba:2a - LYWSD03MMC
 -> Device:
    - Name: LYWSD03MMC
    - Model: undefined
    - 0 features
    - 1 params
      - loaded: true
✔ Continue with Generic service on this device? 
 yes
Now executing Generic steps...
✔ This mode will try to scan your peripheral to get maximum information, continue? 
 yes
No services found.
 -> Peripheral:
   -> Address type: public
   -> Connectable: true
   -> Advertisement:
     -> Local name: LYWSD03MMC
     -> Services:
   -> Services (0):
✔ Did your analyse ends with success? 
 yes
HURRAY!!!
Please give back following data on https://github.com/atrovato/gladys-bluetooth-analyzer/issues GitHub issues
Bye!

I feel like I’m playing Russian roulette
 :stuck_out_tongue:

lol we’re going to end up with the ball !! :stuck_out_tongue:
I just took a look at other projects that claim to integrate the sensor, and I updated our random project.
A git pull and a lot of crossed fingers :crossed_fingers:

I’m waiting for your new results (try 2/3 times taking your time) :slight_smile:

✔ Select device you want to analyse: â€ș a4:c1:38:0c:c2:f9 - LYWSD03MMC
  → Device:
    - Name: LYWSD03MMC
    - Model: undefined
    - 0 features
    - 1 params
      - loaded: true
✔ Continue with Xiaomi service on this device? 
 yes
Now executing Xiaomi steps...
✔ Select model you want to check: â€ș LYWSD03MMC
◒ Connecting to device...{ Error: Bluetooth: peripheral a4c1380cc2f9 not found
    at Noble.scanStop (/home/pi/gladys-bluetooth-analyzer/gladys/server/services/bluetooth/lib/commands/bluetooth.scan.js:46:20)
    at Object.onceWrapper (events.js:286:20)
    at Noble.emit (events.js:203:15)
    at Noble.onScanStop (/home/pi/gladys-bluetooth-analyzer/gladys/server/services/bluetooth/node_modules/@abandonware/noble/lib/noble.js:164:8)
    at NobleBindings.emit (events.js:198:13)
    at NobleBindings.onScanStop (/home/pi/gladys-bluetooth-analyzer/gladys/server/services/bluetooth/node_modules/@abandonware/noble/lib/hci-socket/bindings.js:133:8)
    at Gap.emit (events.js:198:13)
    at Gap.onHciLeScanEnableSet (/home/pi/gladys-bluetooth-analyzer/gladys/server/services/bluetooth/node_modules/@abandonware/noble/lib/hci-socket/gap.js:74:10)
    at Hci.emit (events.js:198:13)
    at Hci.processCmdCompleteEvent (/home/pi/gladys-bluetooth-analyzer/gladys/server/services/bluetooth/node_modules/@abandonware/noble/lib/hci-socket/hci.js:596:10)
    at Hci.onSocketData (/home/pi/gladys-bluetooth-analyzer/gladys/server/services/bluetooth/node_modules/@abandonware/noble/lib/hci-socket/hci.js:465:12)
    at BluetoothHciSocket.emit (events.js:198:13) message: 'Bluetooth: peripheral a4c1380cc2f9 not found' }

And this happens for all other devices detected in the list.
I will try again later in the day.