Bluetooth `addr_type`?

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
KB1RD
Posts: 1
Joined: Thu Mar 05, 2020 1:36 pm

Bluetooth `addr_type`?

Post by KB1RD » Mon Mar 09, 2020 1:09 pm

I have two boards running MicroPython. One board will act as the central and the other one is working as the peripheral. I have tested the peripheral using `gatttool` on my laptop. It is a derivative of the ble_temperature example (https://github.com/micropython/micropyt ... erature.py) that passes neither the name nor the appearance used for a normal pairing process.
I'm in a somewhat unique situation because the central already knows the address of the peripheral and vice-versa (they're exchanged over UART during a pairing process). Now, all I need is to have the central connect to the fixed address of the peripheral. I saw the connect function (https://docs.micropython.org/en/latest/ ... ap_connect), which appears simple, except I cannot find what the `addr_type` variable is.
  • What is `addr_type`?
  • What is the type of the `address` parameter? Can I just pass a string or should I pass an array of bytes?

tannewt
Posts: 51
Joined: Thu Aug 25, 2016 2:43 am

Re: Bluetooth `addr_type`?

Post by tannewt » Tue Mar 10, 2020 12:02 am

My guess (haven't used it myself) is that it's an int value that matches the value in the BLE spec. Address types are usually "static public", "random static" (here is a Nordic post about it https://devzone.nordicsemi.com/f/nordic ... ress-types), or two others derived from the bonding keys. Hope that helps!

User avatar
jimmo
Posts: 2754
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia
Contact:

Re: Bluetooth `addr_type`?

Post by jimmo » Mon Mar 16, 2020 12:00 am

KB1RD wrote:
Mon Mar 09, 2020 1:09 pm
What is `addr_type`?
Yup, what Scott said -- it comes from the BLE spec.

My intention here is that in the ordinary case of "scan" "save" connect", you just remember what the addr type was from the scan and treat it as an opaque number.

The values are:

Code: Select all

BLE_OWN_ADDR_PUBLIC = 0
BLE_OWN_ADDR_RANDOM = 1
BLE_OWN_ADDR_RPA_PUBLIC_DEFAULT = 2
BLE_OWN_ADDR_RPA_RANDOM_DEFAULT = 3
KB1RD wrote:
Mon Mar 09, 2020 1:09 pm
What is the type of the `address` parameter? Can I just pass a string or should I pass an array of bytes?
Anything that supports the buffer protocol returning the underlying bytes of the address, so yes a string would work, but ideally a byte string. (i.e. 'b\xXX\xXX....').

(But I think the answer to your question might be, no it doesn't support: 'XX:XX:XX:XX:XX:XX' )

Post Reply