Skip to content

ble_client passkey should be string, not integer to support leading zeroes #5423

@massimo2001

Description

@massimo2001

Feedback

Hi!

I've been trying to solve a ble_client authentication issue that presented itself like this in the logs:

[19:01:57.101][I][esp32_ble_client:530]: [2] [AA:BB:CC:DD:EE:FF] auth complete addr: aabbccddeeff
[19:01:57.101][E][esp32_ble_client:225]: [2] [AA:BB:CC:DD:EE:FF] auth fail reason=102

The config section looked like that:

ble_client:
  - mac_address: AA:BB:CC:DD:EE:FF
    id: some_device_name
    auto_connect: true
    on_passkey_request:
      then:
        - logger.log: "Authenticating some_device_name (AA:BB:CC:DD:EE:FF) with passkey..."
        - ble_client.passkey_reply:
            id: some_device_name
            passkey: 012345

I tried several things like clearning NVS of the ESP32 and resetting the BLE device in question, but to no avail.

In the docs I noticed

passkey (Required, int): The 6-digit passkey.

Then it hit me... integers don't have leading zeroes. And indeed, updating the config by simply surrounding the passkey in quotes, effectively passing it as a string, fixed my troubles (in many cases there is nothing one can do about a device requiring a passkey that has a or multiple leading zeroes):

            passkey: "012345"

The compiler didn't complain and then I got the auth success message in the logs:

[19:46:27.652][I][esp32_ble_client:530]: [2] [AA:BB:CC:DD:EE:FF] auth complete addr: aabbccddeeff
[19:46:27.699][D][esp32_ble_client:536]: [2] [AA:BB:CC:DD:EE:FF] auth success type = 0 mode = 5

I found it on the ble_client documentation and am reporting it, hoping others can avoid this stumbling block.

Thank you for all the time and effort you put into ESPHome!

Br,
Mo

URL

https://esphome.io/components/ble_client/

Additional information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions