How can I include Manufacturer Data in BLE advertisements? #15921
Replies: 4 comments 1 reply
-
Here's the way to set
Please ignore the duplicated items in these screenshots. |
Beta Was this translation helpful? Give feedback.
-
With the suggestion from @Walkline80 in mind, I started looking into advertising with aioble. I found this example of a peripheral server I'm wondering if this bit might be what I'm looking for:
The line with |
Beta Was this translation helpful? Give feedback.
-
I got it to work by taking the aioble temperature sensor example and adding in So this... async def peripheral_task():
while True:
async with await aioble.advertise(
_ADV_INTERVAL_MS,
name="mpy-temp",
services=[_ENV_SENSE_UUID],
appearance=_ADV_APPEARANCE_GENERIC_THERMOMETER,
) as connection:
print("Connection from", connection.device)
await connection.disconnected(timeout_ms=None) Became this... async def peripheral_task():
while True:
async with await aioble.advertise(
_ADV_INTERVAL_MS,
name="mpy-temp",
services=[_ENV_SENSE_UUID],
appearance=_ADV_APPEARANCE_GENERIC_THERMOMETER,
manufacturer=(0xabcd, b"1234")
) as connection:
print("Connection from", connection.device)
await connection.disconnected(timeout_ms=None) And bingo! Manufacturer data showed up in the scan. |
Beta Was this translation helpful? Give feedback.
-
Have you installed the aioble library from here? https://github.com/micropython/micropython-lib/blob/master/micropython/bluetooth/aioble/README.md |
Beta Was this translation helpful? Give feedback.
-
I've put together a proof of concept DIY Bluetooth Low Energy beacon using an ESP32 and the Arduino C++ platform. What it does is to communicate a battery level in the manufacturer data portion of the BLE advertisement.
I'd like to do the same with MicroPython and aioble.
The idea is to broadcast data at periodic intervals rather than requiring clients to connect and poll a GATT characteristic. That way the ESP32 can spend most of its time in deep sleep, waking up just long enough to send out a few dozen advertisements.
It works great with Arduino BLE. Here's the key part of the code:
The
data[]
array contains two bytes for the manufacturer's ID (at the mement, I'm using 0x09A3 which is reistered to Arduino SA.) The last byte is the level of the battery charge between 0 and 100.The problem I'm running across is I cannot find the MicroPython equivalent of
BLE.setManufacturerData()
Any suggestions as to how I can set this manufacturer data portion of the BLE Advertisement with MicroPython and aioble?
Beta Was this translation helpful? Give feedback.
All reactions