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


initialize driver


Set GAP name“Zerynth!”)

Start the BLE stack


Begin advertising


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

Initial data load


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

hi @duanekaufman
Please check ESP32 BLE examples in this link:
you can also check the alerts example, and send the data as a charactaristic value:

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?


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:

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)


1 Like