BLE advertising packet

All ESP32 boards running MicroPython.
Target audience: MicroPython users with an ESP32 board.
Post Reply
Beezy
Posts: 3
Joined: Sat Feb 01, 2020 12:00 am
Location: Pittsburgh, PA

BLE advertising packet

Post by Beezy » Sat Feb 01, 2020 1:01 am

I want to create a custom advertising packet to pass to gap_advertise(). Does anyone have any information how to do this? I tried to use the example in ble_advertise.py but I get OSError: [Errno 5] EIO when I pass it to the function. When I just pass a string value to the function such as "Micropython" I see nothing in the packet that is sent. My raw data is 0x4553503332 and the rest of the packet is 0's.
I have tried both using the latest build esp32-idf3-20200131-v1.12-107-g31ba06ce8.bin and have built myself with ESP-IDF 3.3.1 and micropython 1.12.
Any help or suggestions would be greatly appreciated.
Thanks in advance!

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

Re: BLE advertising packet

Post by jimmo » Sun Feb 02, 2020 11:24 pm

It might be that the payload is too long... I think that triggers the EIO error.

Can you share the code you used with ble_advertise.py and the call to gap_advertise().

bart.cerneels
Posts: 1
Joined: Mon Feb 03, 2020 12:02 pm

Re: BLE advertising packet

Post by bart.cerneels » Mon Feb 03, 2020 12:05 pm

I've had success copying the advertising init code from here:
https://github.com/jamestiotio/deLIGHT/ ... ipheral.py

Code: Select all

def adv_encode(adv_type, value):
    return bytes((len(value) + 1, adv_type,)) + value

def adv_encode_name(name):
    return adv_encode(const(0x09), name.encode())

bt.gap_advertise(100, adv_encode_name('HelloFri3d'))
Proof that my BLE hello world works:
Image

My application is a conference badge for https://www.fri3d.be/

Beezy
Posts: 3
Joined: Sat Feb 01, 2020 12:00 am
Location: Pittsburgh, PA

Re: BLE advertising packet

Post by Beezy » Tue Feb 04, 2020 10:52 pm

Thanks bart.cerneels that worked perfectly.

Jimmo, I was trying to take the return from advertise_payload() and pass it to gap_advertise. That was my problem, I misunderstood the comment above and thought I could just pass it as is, without using the other two functions.

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

Re: BLE advertising packet

Post by jimmo » Wed Feb 05, 2020 1:26 am

Beezy wrote:
Tue Feb 04, 2020 10:52 pm
Jimmo, I was trying to take the return from advertise_payload() and pass it to gap_advertise. That was my problem, I misunderstood the comment above and thought I could just pass it as is, without using the other two functions.
I'm not quite sure what you mean, you should be able to pass the result of advertising_payload directly to gap_advertise:

Code: Select all

from ble_advertising import advertising_payload
payload = advertising_payload(name='my-device')  #also, services=[..], appearance=N, etc
ble.gap_advertise(interval_us, adv_data=payload)
See https://github.com/micropython/micropyt ... erature.py

Beezy
Posts: 3
Joined: Sat Feb 01, 2020 12:00 am
Location: Pittsburgh, PA

Re: BLE advertising packet

Post by Beezy » Thu Feb 06, 2020 8:11 pm

I was doing:

Code: Select all

payload =  advertising_payload(name='MicroPython', services=[ubluetooth.UUID(0x181A), ubluetooth.UUID('6E400001-B5A3-F393-E0A9-E50E24DCCA9E')])
bt.gap_advertise(100, payload)

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

Re: BLE advertising packet

Post by jimmo » Thu Feb 06, 2020 9:23 pm

Yeah, in that case what I said earlier -- the payload is too long. Try leaving out the services.

Post Reply