Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Xiaomi Thermometer 2 #1

Closed
DazWilkin opened this issue Apr 14, 2020 · 9 comments
Closed

Xiaomi Thermometer 2 #1

DazWilkin opened this issue Apr 14, 2020 · 9 comments

Comments

@DazWilkin
Copy link

DazWilkin commented Apr 14, 2020

Thanks for this code!

I've bought some of the new Xiaomi Thermometer 2 but I'm unable to read from them with your code.

I suspect (!) the Advertisment (!?) format has changed.

How did you determine the protocol for the original sensor?

Your code looks for Data > 14 but I only receive Data == 14

I also only receive id == 0x0128 (not 0x1004, 0x1006, 0x100A, 0x100D)

I'm able to enumerate|scan for the devices that I have.

They report being Connectable().

But I don't understand how to decode the Data I receive from them.

Any pointers would be appreciated.

Thanks!

@u1f35c
Copy link
Owner

u1f35c commented Apr 15, 2020

Do you have an example of the data you're getting back from the device?

@DazWilkin
Copy link
Author

Thank you for the prompt reply!

I had some success Dial'ing the devices and enumerating services|characteristics. Once I do, I receive "Got an unregistered notification" which may be the device(s) notifying me of the temperature|humidity.

The currantlabs/ble has good examples but I'd prefer more comprehensive documentation. I'm working through subscribing to the notifications.

I was able to produce a detailed GATT (!?) using Paypal's gatt tool and Nordic's excellent nRF Connect.

Last night, I found JsBergbau MiTemperature2 which explains that the new device does not advertize the temperature|humidity and requires connection. I will try the Python code.

This appears to be the service of interest:

Service: ebe0ccb07a0a4b0c8a1a6ff2997da3a6
  Characteristic  ebe0ccb77a0a4b0c8a1a6ff2997da3a6
    properties    read write 
    value         cce20200 | "\xcc\xe2\x02\x00"
  Descriptor      2901 (Characteristic User Description)
    value         54696d6500 | "Time\x00"
  Characteristic  ebe0ccb97a0a4b0c8a1a6ff2997da3a6
    properties    read 
    value         3300000034000000 | "3\x00\x00\x004\x00\x00\x00"
  Descriptor      2901 (Characteristic User Description)
    value         4461746120436f756e7400 | "Data Count\x00"
  Characteristic  ebe0ccba7a0a4b0c8a1a6ff2997da3a6
    properties    read write 
    value         00000000 | "\x00\x00\x00\x00"
  Descriptor      2901 (Characteristic User Description)
    value         496e64657800 | "Index\x00"
  Characteristic  ebe0ccbb7a0a4b0c8a1a6ff2997da3a6
    properties    read 
    value         3300000040db0200bc002bb70024 | "3\x00\x00\x00@\xdb\x02\x00\xbc\x00+\xb7\x00$"
  Descriptor      2901 (Characteristic User Description)
    value         44617461205265616400 | "Data Read\x00"
  Characteristic  ebe0ccbc7a0a4b0c8a1a6ff2997da3a6
    properties    notify 
  Descriptor      2901 (Characteristic User Description)
    value         44617461204e6f7469667900 | "Data Notify\x00"
  Descriptor      2902 (Client Characteristic Configuration)
    value         0000 | "\x00\x00"
  Characteristic  ebe0ccbe7a0a4b0c8a1a6ff2997da3a6
    properties    read write 
    value         00 | "\x00"
  Descriptor      2901 (Characteristic User Description)
    value         54656d70657261747572652055696e7400 | "Temperature Uint\x00"
  Characteristic  ebe0ccc17a0a4b0c8a1a6ff2997da3a6
    properties    read notify 
    value         000000 | "\x00\x00\x00"
  Descriptor      2901 (Characteristic User Description)
    value         54656d706572617475726520616e642048756d696469 | "Temperature and Humidi"
  Descriptor      2902 (Client Characteristic Configuration)
    value         0000 | "\x00\x00"
  Characteristic  ebe0ccc47a0a4b0c8a1a6ff2997da3a6
    properties    read 
    value         64 | "d"
  Descriptor      2901 (Characteristic User Description)
    value         4261747400 | "Batt\x00"
  Characteristic  ebe0ccc87a0a4b0c8a1a6ff2997da3a6
    properties    write 
  Descriptor      2901 (Characteristic User Description)
    value         646973636f6e6e65637400 | "disconnect\x00"
  Characteristic  ebe0ccd17a0a4b0c8a1a6ff2997da3a6
    properties    write 
  Descriptor      2901 (Characteristic User Description)
    value         636c656172206461746100 | "clear data\x00"
  Characteristic  ebe0ccd77a0a4b0c8a1a6ff2997da3a6
    properties    read write 
    value         8c0a6c075514 | "\x8c\nl\aU\x14"
  Descriptor      2901 (Characteristic User Description)
    value         636f6d666f727461626c652074656d7020616e642068 | "comfortable temp and h"
  Characteristic  ebe0ccd87a0a4b0c8a1a6ff2997da3a6
    properties    write 
  Descriptor      2901 (Characteristic User Description)
    value         73657420636f6e6e20696e74657276616c00 | "set conn interval\x00"
  Characteristic  ebe0ccd97a0a4b0c8a1a6ff2997da3a6
    properties    write notify 
  Descriptor      2901 (Characteristic User Description)
    value         706172615f76616c75655f67657400 | "para_value_get\x00"
  Descriptor      2902 (Client Characteristic Configuration)
    value         0000 | "\x00\x00"

But, IIUC, the default (!?) notification is for characteristic (ebe0ccd97a0a4b0c8a1a6ff2997da3a6) which corresponds to set conn interval.

@u1f35c
Copy link
Owner

u1f35c commented Apr 16, 2020

It does sound like you need to maintain the connection to get the readings + I wonder if that will affect battery life - the nice thing about the earlier revision is that there's no handshake required which I'm assuming makes for better battery life (I got over 6 months with the provided battery and listening mostly constantly for transmissions).

@DazWilkin
Copy link
Author

IIUC I should be able to subscribe to updates from the device (using CCCD?) and that would keep the power consumption lower (avoiding polling).

Everyone else that's succeeded in interrogating the device seems to miraculously know that handles 0x0038 and 0x0046 are relevant. Using PayPayl's gatt tool, I am able to enumerate handles and get a list of UUIDs but, when I enumerate services and their characteristics (and their handles), I'm unable to find e.g. 0x0038. So, I need to learn more clearly :-)

Thanks for your responsiveness.

@DazWilkin
Copy link
Author

DazWilkin commented Apr 16, 2020

I got it working!

I'll share my code tomorrow.

Thanks again!

@DazWilkin
Copy link
Author

Code: https://github.com/DazWilkin/gomijia2

I've credited you and hope that's acceptable?

@u1f35c
Copy link
Owner

u1f35c commented Apr 18, 2020

Very cool, glad to hear you got it working. Only comment on the credit (which is much appreciated) is that my name only has a single h in it. ;)

@DazWilkin
Copy link
Author

DazWilkin commented Apr 18, 2020 via email

@u1f35c u1f35c closed this as completed Apr 21, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants