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

Create nimble_distance component #128

Merged
merged 17 commits into from
Nov 8, 2022

Conversation

mvgijssel
Copy link
Member

@mvgijssel mvgijssel commented Nov 4, 2022

ref #115

The nimble_distance component will implement the same logic for distance calculation as ESPresence does https://github.com/ESPresense/ESPresense/blob/master/lib/BleFingerprint/BleFingerprint.cpp#L489-L496. Currently ESPhome supports filters on sensor components, but this is not advanced enough just yet to really replicate the behaviour from ESPresence which is very accurate. Maybe in the future this can be implemented in a more general way instead of needing a separate component.

The idea behind the design is that the NimbleDeviceListener will figure out if there is a match with a passed in advertised_device. If there is a match then a virtual method update_state will be called which needs to be implemented by the nimble_rssi and nimble_distance components.

TODO

  • Test using a Shelly connected to Home Assistant and see if OTA still works
  • Test if we can configure MQTT client on the Shelly and make the ble_distance sensor not report to Home Assistant (internal: true)
  • Send MQTT messages whenever the ble_distance sensor triggers sending a message for the mqtt_room component
  • Does this work for longer periods of time? Seems to report not_home after running for ~20 minutes. Does NimBLE stop scanning? Could be due to the limit on known devices! Can we somehow prune this list?
    • Happens because the known_devices list if full and the new random mac cannot be added. Need to change the NimBLEScan to have no limit and create a copy of the NimBLEAdvertisedDevice in the callback as the original is deleted immediately after the callback.
  • Figure out how to use the external component in the home installed shellys (at home-assistant/esphome-data/*)
  • Make sure ESP_LOGD maps to NIMBLE_LOGD (fixed in https://github.com/h2zero/esp-nimble-cpp/pull/42/files)
  • Determine the update rate, how often should the sensor send an event to Home Assistant? Currently use the same as ESPresence 100ms scan window with a 100ms scan interval.
  • Setup ota mode after clicking button sequence (5x click?) in case of emergency and WiFi connection no longer working
  • Move all of the variables used in distance calculation into ESPHome configuration with sane default values
  • Ability to specify a default "Measured Power" or "Tx Power" for the ble_distance component (so it's not inferred from the advertised device)

@mvgijssel mvgijssel marked this pull request as draft November 6, 2022 11:10
@mvgijssel
Copy link
Member Author

Let the nimble_tracker with nimble_distance for an Apple Watch for over an hour without any problem 🎉.

@mvgijssel mvgijssel marked this pull request as ready for review November 8, 2022 08:44
@mvgijssel mvgijssel merged commit 4d5798e into master Nov 8, 2022
@mvgijssel mvgijssel deleted the mg/115/create-ble-distance-component branch November 8, 2022 08:45
@jsnyde30
Copy link

I've been following along with this project for a few days now and would love to help with testing, but I keep getting an error when trying to install this on my esp-wroom-32 chips. This is an epic project and could really help out with bridging the gap between espresense and esphome. great work @mvgijssel !!

Tool Manager: Installing platformio/toolchain-esp32ulp @ ~1.22851.0
INFO Installing platformio/toolchain-esp32ulp @ ~1.22851.0
Error: Could not find the package with 'platformio/toolchain-esp32ulp @ ~1.22851.0' requirements for your system 'linux_aarch64'

I've tried quite a few things but not really finding any help on the web. wanted to reach out and see if you noticed this during your testing.

@mvgijssel
Copy link
Member Author

@jsnyde30 Yeah ran into this exact issue trying to run the esphome compile from within my VScode devcontainer running on my m1 MacBook.

macOS amd64, macOS arm64 and Linux amd64 all work, only Linux arm64 (aarch64) seems to have a problem with that particular library. This should be a temporary problem I think, newer versions of ESPhome will use newer libraries which will also work on Linux amd64.

So for now you’ll have to run it on Mac or Linux amd64! Let me know if that helps :)

@jsnyde30
Copy link

@mvgijssel thanks man! I've been pulling my hair out for 2 days now lol. I'll try the old trust macbook out.

@jsnyde30
Copy link

@mvgijssel I had to set up a 2nd esphome instance on my NAS, but I was able to install, set up a sensor for my android phone with IRK and it's working!! I have an old iphone I can test with for multi-device tracking, then there's only 2 things left to figure out; multiple sensors in different rooms, and how to make regular ibeacons work.

Great job on this project! It would be epic if I could replace all 9 of my espresense devices with ESPHomes because sensors seem to be way more reliable with the later.

If you need help or testing for this project, feel free to reach out.

@mvgijssel
Copy link
Member Author

Sorry for the late reply 🤦‍♂️.

@mvgijssel I had to set up a 2nd esphome instance on my NAS, but I was able to install, set up a sensor for my android phone with IRK and it's working!!

Great to hear! 💪

multiple sensors in different rooms

I'm about to add a second Apple Watch to the setup, so will let you know how that works!

and how to make regular ibeacons work.

I think adding iBeacon (or any other device for that matter) support should not be too hard, though note I'm a big c++ n00b 🙈.

I've built the nimble_tracker component to validate if it's feasible to do room occupancy using Apple Watch bluetooth object tracking. If I get positive results then I'll contact the ESPHome peeps to see what it takes to upstream the NimBLE based BLE library in place of/next to the existing Bluedroid, so everyone can use it to track all BLE devices!

BTW if you are investigating room occupancy using BLE devices as well, after finding mqtt_room and ad-espresense-ips too noisy, I'm now trying find3 in #153 with some good results so far!

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.

None yet

2 participants