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

BLE 5 Long Range / Coded PHY #58

Open
rbaron opened this issue Sep 11, 2022 · 1 comment
Open

BLE 5 Long Range / Coded PHY #58

rbaron opened this issue Sep 11, 2022 · 1 comment
Labels
research & development Data analysis, power optimization, sensor calibration

Comments

@rbaron
Copy link
Owner

rbaron commented Sep 11, 2022

BLE 5 introduced a new PHY - the Coded PHY - which extends the range of BLE at the expense of data rate and current consumption. For b-parasite, data rate is not very relevant, as we only need a few bytes every few minutes.

This article for Nordic finds that the outdoor range is roughly doubled when using Coded PHY under test conditions.

Test Setup

I implemented experimental support for Coded PHY for b-parasite in a7732f1. I flashed two b-parasites, one running Coded PHY and one running the usual Uncoded PHY. Both advertise for 1 s with a 30 ms interval and sleep for 2 s.

I then hacked support for Coded PHY in ESPHome's esp32_ble_tracker component in rbaron/esphome/ble_ext_tracker_component. I'm using it like this in an ESP32-C3-DevKitC-02 dev board with a PCB antenna:

esphome:
  name: prst-ext-tracker
  platformio_options:
    board_build.flash_mode: dio

esp32:
  board: esp32-c3-devkitm-1
  framework:
    type: esp-idf
    sdkconfig_options:
      CONFIG_BT_BLE_50_FEATURES_SUPPORTED: y

 external_components:
   - source: github://rbaron/esphome@ble_ext_tracker_component
     components: [ esp32_ble_tracker ]

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password

api:
  password: !secret home_assistant_api

esp32_ble_tracker:

sensor:
  # Uses Coded PHY.
  - platform: b_parasite
    mac_address: "f0:ca:f0:ca:02:01"
    humidity:
      name: "Coded PHY Humidity"
    temperature:
      name: "Coded PHY Temperature"
    moisture:
      name: "Coded PHY Soil Moisture"
      force_update: true
    battery_voltage:
      name: "Coded PHY Battery Voltage"
  - platform: ble_rssi
    mac_address: "f0:ca:f0:ca:02:01"
    name: "Coded PHY RSSI"
  # Does not use Coded PHY.
  - platform: b_parasite
    mac_address: "f0:ca:f0:ca:02:02"
    humidity:
      name: "Uncoded PHY Humidity"
    temperature:
      name: "Uncoded PHY Temperature"
    moisture:
      name: "Uncoded PHY Soil Moisture"
      force_update: true
    battery_voltage:
      name: "Uncoded PHY Battery Voltage"
  - platform: ble_rssi
    mac_address: "f0:ca:f0:ca:02:02"
    name: "Uncoded PHY RSSI"

logger:

Power Consumption

Default, Uncoded PHY - Average 1.49 mA while transmitting:
uncoded

Coded PHY - Average 7.2 mA while transmitting:
coded

Indoor Range

In this test, I left the ESP32-C3 in my office and walked down the stairs in my building.
Screen Shot 2022-09-11 at 16 09 04

Initial Results

With this first quick and simple test, I unfortunately haven't observed any meaningful differences in indoor range. There are still many parameters to experiment with, of course, but we have to start somewhere. I also want to try a nRF52-based scanner and a better, non-PCB antenna.

@rbaron rbaron added the research & development Data analysis, power optimization, sensor calibration label Sep 11, 2022
@pvvx
Copy link

pvvx commented Nov 6, 2022

LongRange (Coded PHY) works in HA from USB-BT RTL8761B.
But not all options.
The BLE standard provides for the reception of generic advertisements in the Coded PHY. But this option does not work - there is no support in many OS.
It also doesn't work when extended advertising send the header to the Coded PHY on the main channels. This is also a defect of software manufacturers.

https://www.home-assistant.io/integrations/bluetooth/#known-working-adapters
This description is incorrect. Long Range is not the presence of an external antenna :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
research & development Data analysis, power optimization, sensor calibration
Projects
None yet
Development

No branches or pull requests

2 participants