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
This question is better suited to https://forum.micropython.org
In short: BLE has concepts of "central" and "peripheral", but not "server". Examples of both are provided in examples/bluetooth/, ble_temperature_central.py and ble_temperature.py.
@dpgeorge I am going to be pedantic, sorry. BLE does have client and server, which are orthogonal to central and peripheral. All four terms are "official". A server provides a service; a client talks to a server, accessing its characteristics. Once a client and a peripheral connect, either one can be a server to the other.
Usually, a peripheral is a server, and a central (e.g. a phone) is a client (e.g., a heart rate monitor provides a service), but there are use cases the other way. The Current Time Service provided by iOS is an example. A peripheral can ask to connect to the phone, and then access the time service on the phone.
So peripheral/client has to do with GAP (advertising), the pre-connection phase. Once connected, the two devices are peers, and move into GATT concepts: server/client.
This multiple identities thing makes it hard to write a nice object-oriented API for BLE, as we've found. A physical device can have multiple roles, and the roles change over time.
(I keep editing this reply, because BLE is so hard to explain succinctly; it is not a nicely layered protocol. @dpgeorge, I am not directing this at you, but at the future reader.)
@dhalbert yes, of course, you are right! I was being too simplistic and just thinking of the peripheral/central/observer/broadcaster roles, forgetting about things like GATT server/client. Yes it's complex.
Most helpful comment
@dpgeorge I am going to be pedantic, sorry. BLE does have client and server, which are orthogonal to central and peripheral. All four terms are "official". A server provides a service; a client talks to a server, accessing its characteristics. Once a client and a peripheral connect, either one can be a server to the other.
Usually, a peripheral is a server, and a central (e.g. a phone) is a client (e.g., a heart rate monitor provides a service), but there are use cases the other way. The Current Time Service provided by iOS is an example. A peripheral can ask to connect to the phone, and then access the time service on the phone.
So peripheral/client has to do with GAP (advertising), the pre-connection phase. Once connected, the two devices are peers, and move into GATT concepts: server/client.
This multiple identities thing makes it hard to write a nice object-oriented API for BLE, as we've found. A physical device can have multiple roles, and the roles change over time.
(I keep editing this reply, because BLE is so hard to explain succinctly; it is not a nicely layered protocol. @dpgeorge, I am not directing this at you, but at the future reader.)