espruino / EspruinoHub

A BLE -> MQTT bridge for Raspberry Pi and other Embedded devices
Other
238 stars 62 forks source link

Some refactoring needed "fe95" for many Xiaomi devices #54

Closed GrumpyMeow closed 4 years ago

GrumpyMeow commented 4 years ago

Hi,

the current implementation is very specific for the "Xiaomi Mija LYWSDCGQ/01ZM". Other Xiaomi devices (yee-rc and Amazfit watches) advertise the same service "fe95". I'll try to do some refactoring to support more Xiaomi device types.

Services exposed by my Xiaomi Amazfit Stratos watch:

[{"uuid":"1800","characteristics":[{"uuid":"2a00"},{"uuid":"2a01"}]},{"uuid":"1801","characteristics":[{"uuid":"2a05"}]},{"uuid":"0000fed00000351221180009af100700","characteristics":[{"uuid":"000000010000351221180009af100700"},{"uuid":"000000080000351221180009af100700"},{"uuid":"000000090000351221180009af100700"},{"uuid":"000000100000351221180009af100700"},{"uuid":"000000110000351221180009af100700"},{"uuid":"000000120000351221180009af100700"},{"uuid":"000000200000351221180009af100700"},{"uuid":"000000130000351221180009af100700"},{"uuid":"000000510000351221180009af100700"}]},{"uuid":"0000fed10000351221180009af100700","characteristics":[{"uuid":"0000fed20000351221180009af100700"}]},{"uuid":"fee1","characteristics":[{"uuid":"fedd"},{"uuid":"fede"}]}]
gfwilliams commented 4 years ago

You mean here? https://github.com/espruino/EspruinoHub/blob/master/lib/attributes.js#L44

Aren't those characteristics for when you're connected? attributes.js just deals with advertising data - although I'm sure it could be extended to deal with different types of data.

It'd definitely not specifically for "Xiaomi Mija LYWSDCGQ/01ZM" since I have the Mi Flora and that sends the same advertising data.

jjok commented 4 years ago

I think this commit https://github.com/espruino/EspruinoHub/commit/8a6fe25df61367eb4f1fdeab69a6460be60f17e2 broke support for CGG1. temp, humidity and battery now only work for LYWSDCGQ.

conservatory - MJ_HT_V1 (RSSI -82)
  fe95 => {"frameControl":8272,"productId":426,"counter":233,"productName":"LYWSDCGQ","temp":13.9,"humidity":82.1}
  ffff => {"data":"224,19,104,80,168,155"}
hallway - Qingping Temp & RH M (RSSI -72)
  fe95 => {"frameControl":12368,"productId":839,"counter":70,"productName":"CGG1"}
  fdcd => [8,7,62,82,16,52,45,88,1,4,187,0,165,2,2,1,18]
gfwilliams commented 4 years ago

Thanks for letting me know. Looks like this could be fixed by moving the if (d[11] == 0x04) { line and what follows outside of the switch statement. Do you think you could give it a go and let me know if it works? I don't have the stuff here to test

jjok commented 4 years ago

I'll give it a go tonight.

jjok commented 4 years ago

Yep. That fixes it.

conservatory - MJ_HT_V1 (RSSI -82)
  fe95 => {"frameControl":8272,"productId":426,"counter":36,"productName":"LYWSDCGQ","temp":14.7,"humidity":76.9}
  ffff => {"data":"224,19,104,80,168,155"}
hallway - Qingping Temp & RH M (RSSI -71)
  fdcd => [8,7,62,82,16,52,45,88,1,4,188,0,160,2,2,1,18]
  fe95 => {"frameControl":12368,"productId":839,"counter":239,"productName":"CGG1","temp":18.8,"humidity":67.2}

@gfwilliams was your Mi Flora broken?

gfwilliams commented 4 years ago

Ahh, I didn't twig that the Mi Flora was the one - actually it's not within range of my EspruinoHub device so I'd kindof forgotten about it.

Thanks for the fix!