blue_heron icon indicating copy to clipboard operation
blue_heron copied to clipboard

Example: xiaomi mi flora passive listener

Open petermm opened this issue 3 years ago • 7 comments

(Know this is inside the govee app, but seems a bit much creating seperate apps for examples - and quite a maintainability issue down the line perhaps)

{status, pid} = XiaomiPassiveScan.start_link(:uart)

to setup hold sensor close to your elixir device and this will popup:

[info]  FOUND SUPPORTED DEVICE, currently not configured:  device_adress: 216039227630131 - name:  Flower care

        Config in @listen_to_device_addresses with something like:

            "216039227630131": %{name: "my avocado plant", pubsub_topic: "avacoda_plant", pubsub_module: MyApp.PubSub }

add the suggested config to @listen_to_device_addresses and then your measurements will come in:

18:03:16.969 [info]  Init commands completed successfully

18:03:16.969 [info]  Scanning for devices

18:03:21.907 [info]  my avocado plant - lux: 217

18:03:31.902 [info]  my avocado plant - moisture: 47

18:03:41.903 [info]  my avocado plant - fertility: 203

18:03:53.945 [info]  my avocado plant - temperature: 19.4

petermm avatar Jan 26 '21 17:01 petermm

This looks really cool! gonna sit on it for a sec because i believe you're correct about the examples, but love it!

ConnorRigby avatar Jan 26 '21 19:01 ConnorRigby

Just letting you know i haven't forgotten about this. Just been very busy.

ConnorRigby avatar Aug 30 '21 14:08 ConnorRigby

no worries, I would suggest we hold out examples for a blue_heron capable nerves_livebook https://github.com/fhunleth/nerves_livebook/issues/50 - and I'll create a livebook example once that happens..

petermm avatar Aug 30 '21 17:08 petermm

Hi @petermm , I tried your example and it detected my device successfully. I do not get any data packets tough... I logged all incoming packets and only get these:

07:32:20.460 [info]  Unexpected packet: %BlueHeron.HCI.Event.LEMeta.AdvertisingReport{code: 62, devices: [%BlueHeron.HCI.Event.LEMeta.AdvertisingReport.Device{address: 216039227090229, address_type: 0, data: ["\tFlower care"], event_type: 4, rss: 184}], num_reports: 1}
07:32:22.429 [info]  Unexpected packet: %BlueHeron.HCI.Event.LEMeta.AdvertisingReport{code: 62, devices: [%BlueHeron.HCI.Event.LEMeta.AdvertisingReport.Device{address: 216039227090229, address_type: 0, data: ["\tFlower care"], event_type: 4, rss: 196}], num_reports: 1}
07:32:23.439 [info]  Unexpected packet: %BlueHeron.HCI.Event.LEMeta.AdvertisingReport{code: 62, devices: [%BlueHeron.HCI.Event.LEMeta.AdvertisingReport.Device{address: 216039227090229, address_type: 0, data: ["\tFlower care"], event_type: 4, rss: 182}], num_reports: 1}
07:32:24.440 [info]  Unexpected packet: %BlueHeron.HCI.Event.LEMeta.AdvertisingReport{code: 62, devices: [%BlueHeron.HCI.Event.LEMeta.AdvertisingReport.Device{address: 216039227090229, address_type: 0, data: ["\tFlower care"], event_type: 4, rss: 182}], num_reports: 1}
07:32:26.456 [info]  Unexpected packet: %BlueHeron.HCI.Event.LEMeta.AdvertisingReport{code: 62, devices: [%BlueHeron.HCI.Event.LEMeta.AdvertisingReport.Device{address: 216039227090229, address_type: 0, data: ["\tFlower care"], event_type: 4, rss: 197}], num_reports: 1}

It's a brand new sensor. Do I have to enable / configure it somehow?


Update: I also get some with event_type 0, but they do not match the requested pattern

07:41:58.400 [info]  Unexpected packet: {:HCI_EVENT_PACKET, %BlueHeron.HCI.Event.LEMeta.AdvertisingReport{code: 62, devices: [%BlueHeron.HCI.Event.LEMeta.AdvertisingReport.Device{address: 216039227090229, address_type: 0, data: [<<1, 6>>, <<2, 149, 254>>, <<22, 149, 254, 49, 2, 152, 0, 2, 53, 101, 99, 141, 124, 196, 13>>], event_type: 0, rss: 200}], num_reports: 1}}
07:42:00.172 [info]  Unexpected packet: {:HCI_EVENT_PACKET, %BlueHeron.HCI.Event.LEMeta.AdvertisingReport{code: 62, devices: [%BlueHeron.HCI.Event.LEMeta.AdvertisingReport.Device{address: 216039227090229, address_type: 0, data: [<<1, 6>>, <<2, 149, 254>>, <<22, 149, 254, 49, 2, 152, 0, 2, 53, 101, 99, 141, 124, 196, 13>>], event_type: 0, rss: 204}], num_reports: 1}}
07:42:00.469 [info]  Unexpected packet: {:HCI_EVENT_PACKET, %BlueHeron.HCI.Event.LEMeta.AdvertisingReport{code: 62, devices: [%BlueHeron.HCI.Event.LEMeta.AdvertisingReport.Device{address: 216039227090229, address_type: 0, data: [<<1, 6>>, <<2, 149, 254>>, <<22, 149, 254, 49, 2, 152, 0, 2, 53, 101, 99, 141, 124, 196, 13>>], event_type: 0, rss: 205}], num_reports: 1}}
07:42:01.299 [info]  Unexpected packet: {:HCI_EVENT_PACKET, %BlueHeron.HCI.Event.LEMeta.AdvertisingReport{code: 62, devices: [%BlueHeron.HCI.Event.LEMeta.AdvertisingReport.Device{address: 216039227090229, address_type: 0, data: [<<1, 6>>, <<2, 149, 254>>, <<22, 149, 254, 49, 2, 152, 0, 2, 53, 101, 99, 141, 124, 196, 13>>], event_type: 0, rss: 197}], num_reports: 1}}

philipgiuliani avatar Sep 15 '21 07:09 philipgiuliani

hi @philipgiuliani - sounds like you have things "wired" up correctly - I assume you have received the "FOUND SUPPORTED DEVICE" message etc.

seems a bit weird - your msg <<1, 6>>, <<2, 149, 254>>, <<22, 149, 254, 49, 2, 152, 0, 2, 53, 101, 99, 141, 124, 196, 13>> has two different bytes before the 152,0 and then no payload after the final 13

only thing I can think of is if you have used the device with the mobile app? - maybe one needs to use the app once to make it start sensoring - also while you're there check for the firmware version, and maybe report that one - also if any firmware updates are available..

petermm avatar Sep 16 '21 16:09 petermm

Thanks for the hint. So the trick was really to register the Sensor via the Mi Home App. This will start the broadcasting of the data.

philipgiuliani avatar Sep 17 '21 07:09 philipgiuliani

great to hear! - will update the PR/example in a few days with:

  • check if logging to disk is enabled and warn in the initial proximity step
  • handling out of box device, match that packet you got and warn/tell how to get device going

bonus: I'll add support for the $5 "LYWSD03MMC" (https://www.aliexpress.com/wholesale?SearchText=LYWSD03MMC) when using this firmware: https://github.com/pvvx/ATC_MiThermometer 68747470733a2f2f7461736d6f74612e6769746875622e696f2f646f63732f5f6d656469612f626c7565746f6f74682f4c5957534430334d4d432e706e67

petermm avatar Sep 17 '21 13:09 petermm