Handling BLE Connections
Currently, the bt. object only supports the BLE peripheral role. This means that you cannot initiate a connection from the bt. object, but can only enable it to accept incoming connections from central devices. As soon as you bring up and enable the BLE interface, your device will be ready to accept incoming connections from central devices.
An on_bt_event(PL_BT_EVENT_CONNECTED) is generated every time your device accepts an incoming connection. An on_bt_event(PL_BT_EVENT_DISCONNECTED) is generated when the BLE connection is lost. In the following code example, the on_bt_event event handler sets various LED patterns depending on the BLE state:
sub on_bt_event(bt_event as enum pl_bt_events)
select case bt_event
case PL_BT_EVENT_CONNECTED:
pat.play("G*~",PL_PAT_CANINT) 'Green ON
case PL_BT_EVENT_DISCONNECTED:
pat.play("-G*~",PL_PAT_CANINT) 'Green BLINKING
case PL_BT_EVENT_ENABLED:
bt.advertise=YES
pat.play("-G*~",PL_PAT_CANINT) 'Green BLINKING
case PL_BT_EVENT_DISABLED:
pat.play("-",PL_PAT_CANINT) 'Green OFF
end select
end sub
You can also check the status of the BLE connection at any time using the bt.connected read-only property.
As soon as the connection is established, you can send and receive data through the BLE interface.