hannseman / homebridge-mi-hygrothermograph

Homebridge plugin for the Xiaomi Mi Bluetooth Temperature and Humidity Sensor
MIT License
266 stars 52 forks source link

Raspberry Pi: Error: Unsupported state or unable to authenticate data #101

Closed filipthoen closed 8 months ago

filipthoen commented 4 years ago

Hi there,

Excited to try this plug-in, my YWD03MMC sensors finally came in after 4 months of shipping delay!

I've installed the latest version of Raspian, Homebridge & the home-bridge-mi-hygrothermograph, and was able to extract the link_key from the MI app key exchange.

I see the following error in the home bridge log:

[4/14/2020, 10:24:29 PM] [Temperature & Humidity] Error: Unsupported state or unable to authenticate data at Decipheriv.final (internal/crypto/cipher.js:172:29) at Parser.decryptPayload (/usr/lib/node_modules/homebridge-mi-hygrothermograph/lib/parser.js:191:14) at Parser.parse (/usr/lib/node_modules/homebridge-mi-hygrothermograph/lib/parser.js:59:12) at Scanner.parseServiceData (/usr/lib/node_modules/homebridge-mi-hygrothermograph/lib/scanner.js:171:52) at Scanner.onDiscover (/usr/lib/node_modules/homebridge-mi-hygrothermograph/lib/scanner.js:92:25) at Noble.emit (events.js:310:20) at Noble.onDiscover (/usr/lib/node_modules/homebridge-mi-hygrothermograph/node_modules/@abandonware/noble/lib/noble.js:178:10) at NobleBindings.emit (events.js:310:20) at NobleBindings.onDiscover (/usr/lib/node_modules/homebridge-mi-hygrothermograph/node_modules/@abandonware/noble/lib/hci-socket/bindings.js:174:10) at Gap.emit (events.js:310:20)

Here is my config.json entry:

{ "accessory": "Hygrotermograph", "name": "Temperature & Humidity", "humidityName": "Humidity", "temperatureName": "Temperature", "address": "a4:c1:38:a0:a9:4f", "bindKey": "1ECEE08ABAA8C51845**" }

The sensors appear correctly own the IOS Home app.

Here are my versions:

Node.js Version: v12.16.2 npm" v6.14.4 homebridge: 0.4.53 homebridge-mi-hygrothermograph: 3.0.0 Raspian: Stretch - Linux raspberrypi 4.19.97-v7+ #1294 SMP Thu Jan 30 13:15:58 GMT 2020 armv7l GNU/Linux

Any ideas or tips? Is anybody running this on a Raspberry PI, or is this only proven to work on Mac or other host?

Thanks in advance,

Filip

hannseman commented 4 years ago

Thanks for your report and sorry for the late reply. I don't have this version myself yet but maybe @ulrich-berl who added the support for LYWSD03MMC might have some insight?

Naqsaq commented 4 years ago

Same issue. I have a single LYWSD02MMC working just fine. It's the two LYWSD03MMC causing this. Definitely needs further investigation, so let me know what I can do for you. Running HB as root does not do anything for me, as tried out here https://github.com/hannseman/homebridge-mi-hygrothermograph/issues/106.

My logs are slightly different (maybe due to different hardware):

 Error: Unsupported state or unable to authenticate data
    at Decipheriv.final (internal/crypto/cipher.js:172:29)
    at Parser.decryptPayload (/usr/local/lib/node_modules/homebridge-mi-hygrothermograph/lib/parser.js:191:14)
    at Parser.parse (/usr/local/lib/node_modules/homebridge-mi-hygrothermograph/lib/parser.js:59:12)
    at Scanner.parseServiceData (/usr/local/lib/node_modules/homebridge-mi-hygrothermograph/lib/scanner.js:171:52)
    at Scanner.onDiscover (/usr/local/lib/node_modules/homebridge-mi-hygrothermograph/lib/scanner.js:92:25)
    at Noble.emit (events.js:322:22)
    at Noble.onDiscover (/usr/local/lib/node_modules/homebridge-mi-hygrothermograph/node_modules/@abandonware/noble/lib/noble.js:196:10)
    at NobleBindings.emit (events.js:310:20)
    at NobleBindings.onDiscover (/usr/local/lib/node_modules/homebridge-mi-hygrothermograph/node_modules/@abandonware/noble/lib/hci-socket/bindings.js:169:10)
    at Gap.emit (events.js:310:20)
    at Gap.onHciLeAdvertisingReport (/usr/local/lib/node_modules/homebridge-mi-hygrothermograph/node_modules/@abandonware/noble/lib/hci-socket/gap.js:244:10)
    at Hci.emit (events.js:310:20)
    at Hci.processLeAdvertisingReport (/usr/local/lib/node_modules/homebridge-mi-hygrothermograph/node_modules/@abandonware/noble/lib/hci-socket/hci.js:650:12)
    at Hci.processLeMetaEvent (/usr/local/lib/node_modules/homebridge-mi-hygrothermograph/node_modules/@abandonware/noble/lib/hci-socket/hci.js:606:10)
    at Hci.onSocketData (/usr/local/lib/node_modules/homebridge-mi-hygrothermograph/node_modules/@abandonware/noble/lib/hci-socket/hci.js:477:12)
    at BluetoothHciSocket.emit (events.js:310:20)

Update: after turning on -D for debugging, the LYWSD03MMC's are actually replying, though it mostly looks like this..:

[Office Temperature & Humidity] [a4:c1:38:70:07:eb] Discovered peripheral
      Id: a4c1387007eb
      LocalName: LYWSD03MMC
      rssi: -85
      serviceData: 30585b058feb077038c1a408
[Office Temperature & Humidity] No event

.. so the data is not really coming in. The working LYWSD02MMC reports every few seconds:

[Living room Temperature & Humidity] [e7:2e:00:d3:14:3f] Discovered peripheral
      Id: e72e00d3143f
      LocalName: LYWSD02
      rssi: -71
      serviceData: 70205b04aa3f14d3002ee709061002bc02
[Living room Temperature & Humidity] [e7:2e:00:d3:14:3f] Humidity: 70%

The thing crashes when a LYWSD03MMC actually sends some meaningful data:

[Bedroom Temperature & Humidity] [a4:c1:38:fd:e1:45] Discovered peripheral
      Id: a4c138fde145
      LocalName: LYWSD03MMC
      rssi: -60
      serviceData: 58585b05a245e1fd38c1a474569103b6000000b22dec27
[Bedroom Temperature & Humidity] Error: Unsupported state or unable to authenticate data

But then again, once or twice it worked:

[Office Temperature & Humidity] [a4:c1:38:70:07:eb] Discovered peripheral
      Id: a4c1387007eb
      LocalName: LYWSD03MMC
      rssi: -83
      serviceData: 58585b058eeb077038c1a4e6832cc815000000ee0d3a07
[Office Temperature & Humidity] [a4:c1:38:70:07:eb] Temperature: 25.8C

Something wrong with intepreting the LYWSD03MMC serviceData?

Naqsaq commented 4 years ago

Same issue. Something wrong with intepreting the LYWSD03MMC serviceData?

Any chance for someone to take a quick look into this? @hannseman @ulrich-berl Do let me know if you need more datapoints to debug.

y0m1g commented 4 years ago

I'm facing the same issue with 2 LYWSD03MMC, with the exact same stack trace as @Naqsaq. Rasbperry Pi 3, Ubuntu 18.04.3 LTS, Node v12.16.1, Npm v6.14.1, Homebridge 1.1.1, Mi Hygrothermograph 3.0.1

Lars83 commented 4 years ago

Hello, I have the same problem as you and have already tried everything possible, but I am not getting anywhere and my sensors are all in the home app for no answer. Can you tell me step by step how you got the sensors working again? The sensors were not running anymore but one.

sambal0 commented 4 years ago

Same over here. The plugin stops after a while and the home app loses the connection and shows “no answer”. A homebridge restart solves the problem, but just for a few hours.

oleksiikutuzov commented 4 years ago

Just updated YWD03MMC to latest 0109 software and also started receiving this errors

UPD: Removed from the app and connected again, inserted new bindKey and it seems to be working again

gapaus commented 4 years ago

Hi! I have same error. Error: Attempting to set auth tag in unsupported state at Decipheriv.setAuthTag (crypto.js:205:16)

Data is: const bindKey = '01F7F2DD8334E64505F3BF7272C1EFC2'; const serviceData = Buffer.from([88, 88, 91, 5, 79, 49, 60, 127, 56, 193, 164, 121, 219, 178, 251, 13, 0, 0, 0, 34, 29, 61, 15]);

dominiakmarek commented 3 years ago

Does anyone sorted this out ?

Regards, Marek

hugozheng2017 commented 3 years ago

I have the same error : Error: Unsupported state or unable to authenticate data. But I can get the correct data from the Telink Flasher.

daniel0076 commented 3 years ago

I recently purchased the LYWSD03MMC and observed very similar phenomenon as @Naqsaq.

I initially got Error: Unsupported state or unable to authenticate data but is later solved with re-activation with Telink Flasher Once the temperature and humidity can be interpreted, the setup is correct in my opinion.

According to Tasmota Bluetooth Document, the LYWSD03MMC sends encrypted sensor data every 10 minutes, so it is not going to send the sensed values all the time. And I can confirm this because once my bindKey is setup correctly, I got the sensed values approximately every 10 mins.

I am not a BLE expert but I think perhaps the data in this format 30585b058febxxxxxxxxxx08 (xxx is the MAC address) is just the advertisement message (like beacon), while the meaningful data is sent only per 10 minutes.

As a result, try to get a new bindKey if you got the error, and wait for 10 minutes to check the result, and the -D option in homebridge helps you with detailed debug messages.

ahmadnazirafiq commented 3 years ago

Hi, I can use LYWSD03MMC alongside LYWSD02 just fine. Once I added a second LYWSD03MMC, neither of those works anymore. It seems like as if we can't use two or more units of LYWSD03MMC despite each of them came with its own bindKey and MAC address.

I obtained both the bindKey and MAC address for LYWSD03MMC from Telink Flasher. I added both of these sensors using a different browser (Chrome and Edge) just to avoid it from clashes. I ran below command and reboot Homebridge but only LYWSD02 data was shown:

sudo setcap cap_net_raw+eip $(eval readlink -fwhich node)

Any fixes for this?

hannseman commented 3 years ago

Unfortunately have yet to acquire this device but I've seen people having success in turning of the encryption by using this custom firmware: https://github.com/atc1441/ATC_MiThermometer

ErimElidor commented 2 years ago

I was having the same error: Unsupported state or unable to authenticate data. After obtaining the bind keys again, it began working 10 minutes after rebooting Homebridge (with two LYWSD03MMC).

Do you have to keep obtaining the bind keys every now and then?