ESP32 Bluetooth: Error code "OSError: -18" when advertising with a too long payload
MicroPython v1.15 on 2021-04-18; ESP32 module with ESP32
When trying to advertising with a long payload(longer than 31 bytes) using bluetooth lib on esp32, Micropython would give an unclear error code " OSError: -18 ".
import bluetooth
esp32_ble = bluetooth.BLE()
esp32_ble.active(True)
payload = b'\x02\x01\x06\n\taLongName\x11\x07\x9e\xca\xdc$\x0e\xe5\xa9\xe0\x93\xf3\xa3\xb5\x01\x00@n'
esp32_ble.gap_advertise(interval_us=200000, adv_data=payload)
# Traceback (most recent call last):
# File "<stdin>", line 6, in <module>
# OSError: -18
A payload longer than 31 bytes might be generated with a 128bit Service UUID and a long name(len>8).
from ble_advertising import advertising_payload #example in /micropython/example/bluetooth
ServiceUUID = bluetooth.UUID("6E400001-B5A3-F393-E0A9-E50E24DCCA9E")
payload = advertising_payload(name="muchTooLong", services=[ServiceUUID])
A short name would work just fine.
The error code is not helpful for debugging, but I'm not sure how to improve this.
I opened this issue to notify who have met the same problem.
BLE Server for ESP32
Hi.
i just started with micropython. but i can't get a BLE server working on my ESP32 with micropython.
I want to connect to my esp32 via my phone with an app like "BLE IO".
I'm using ubluetooth and this is my code:
import bluetooth
bt = bluetooth.BLE()
bt.active(True)
bt.gap_advertise(1000)
but this goes into "OSError: [Errno 5] EIO". I can't understand how to do it.
i also tried to copy the example "bt_advertising", but if i edit the demo() as this:
def demo():
payload = advertising_payload(name='micropython', services=[bluetooth.UUID(0x181A), bluetooth.UUID('6E400001-B5A3-F393-E0A9-E50E24DCCA9E')])
print(payload)
print(decode_name(payload))
print(decode_services(payload))
bt = bluetooth.BLE()
bt.active(True)
bt.gap_advertise(1000, adv_data=payload)
it always give me errorno 5