ESP32 and dynamic BLE advertising

Dear Sirs,
I would like to use my ESP32 to read a sensor and put a limited amount of data into a BLE advertising packet for communications.
I wrote the below in an attempt to use the manufacturers data to store my dynamic data.
Using a BLE scanner on a phone, I can see the advertisement, but no mfg data shows up.

is there an example somewhere?

import streams
#import the ESP32 BLE driver: a BLE capable VM is also needed!
from espressif.esp32ble import esp32ble as bledrv

then import the BLE modue

from wireless import ble

streams.serial()

initialize driver

bledrv.init()

Set GAP name

ble.gap(“Zerynth!”)

Start the BLE stack

ble.start()

Begin advertising

ble.start_advertising()

def UpdateAdvertising(Mfg_data):
# Update the manufacturer section of the advertising packet
# Stop advertising
ble.stop_advertising()
# Update data must put in first parameter (interval)
ble.advertising(100, payload = Mfg_data)
ble.start_advertising()

Initial data load

UpdateAdvertising(“DEADBEEF\x00”)

while True:
r_val = random(0,100)
print("r_val: ", r_val)
sleep(1000)

hi @duanekaufman
Please check ESP32 BLE examples in this link:
https://docs.zerynth.com/latest/reference/libs/espressif/esp32ble/docs/examples/#examples
you can also check the alerts example, and send the data as a charactaristic value:
https://docs.zerynth.com/latest/reference/libs/espressif/esp32ble/docs/examples/#ble-alerts

Let me know what you think

Dear Sir,

I have looked at the examples (which is what I based my code on).
The specification is for the data to be embedded in the advertisement packet, to avoid having to make a connection.

My code throws a TypeError in the call:
ble.advertising(100, payload = Mfg_data)

How is this documented function supposed to be called? The help states payload should be bytes or a string, but either one throws a TypeError.

Is there a short example using this function I can work from?

Sincerely,
Duane

Hi @duanekaufman
Apologies for this inconveniences with the BLE library, Let me test it and Will keep you updated.

Dear karimhamdy1,
I found a way to do what I want in the example found here for the EddyStone beacon:
https://docs.zerynth.com/latest/reference/libs/espressif/esp32ble/docs/examples/#ble-alerts

If I encode a payload using the methods for the Eddystone beacon, things work:
ble.advertising(100, payload = bb.eddy_encode_uid(namespace,instance,txpower))

I can adjust the variables namespace and instance to my liking (within length limits, of course)

Sincerely,
Duane

1 Like