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

Example: xiaomi mi flora passive listener #57

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

petermm
Copy link
Contributor

@petermm petermm commented Jan 26, 2021

(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

@ConnorRigby
Copy link
Collaborator

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

@ConnorRigby
Copy link
Collaborator

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

@petermm
Copy link
Contributor Author

petermm commented Aug 30, 2021

no worries, I would suggest we hold out examples for a blue_heron capable nerves_livebook nerves-livebook/nerves_livebook#50 - and I'll create a livebook example once that happens..

@philipgiuliani
Copy link

philipgiuliani commented Sep 15, 2021

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}}

@petermm
Copy link
Contributor Author

petermm commented Sep 16, 2021

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..

@philipgiuliani
Copy link

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.

@petermm
Copy link
Contributor Author

petermm commented Sep 17, 2021

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

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

Successfully merging this pull request may close these issues.

3 participants