lancaster-university / codal-microbit-v2

CODAL target for the micro:bit v2.x series of devices
MIT License
41 stars 50 forks source link

Issues with BLE connections #381

Closed MatsSyvertsen closed 9 months ago

MatsSyvertsen commented 9 months ago

I've been trying to get BLE working an university project, but have hit two issues:

Nothing happens when I attempt to connect to the micro:bit with MICROBIT_BLE_OPEN set to 1 (Nothing is printed in DMESG)

DMESG logs for MICROBIT_BLE_OPEN ``` relocate vtor to 0x0 -> 0x20003800 0x20003800 MicroBitBLEManager::init NRF_SDH_BLE_VS_UUID_COUNT = 4 NRF_SDH_BLE_GATTS_ATTR_TAB_SIZE = 0x720 12:microbit_ble_sdh_req_handler changeOK = 1 No security DEVICE_INFORMATION_SERVICE servicesChanged getBondCount 0 configureAdvertising connectable 1, discoverable 1 whitelist 0, interval_ms 50, timeout_seconds 0 setTransmitPower 6 BLE_GAP_TX_POWER_ROLE_ADV advertise MicroBitBLEService::RegisterBaseUUID bs_uuid_type = 2 MicroBitBLEService::CreateService( 0x100) = 21 MICROBIT_BLE_SECURITY_MODE 1 MicroBitBLEService::CreateCharacteristic( 0x101) = 23 0 0 0 ```

When switching BLE_OPEN out for pairing with SECURITY_MODE_ENCRYPTION_NO_MITM as SECURITY_LEVEL I can pair and be "connected", but I cannot connect after the reset, also it seems to only advertise once at start-up. Connecting to it gives a "Device unreachable" in Bluetooth LE Explorer.

DMESG logs for SECURITY_MODE_ENCRYPTION_NO_MITM pairing ``` relocate vtor to 0x0 -> 0x20003800 0x20003800 MicroBitBLEManager::init NRF_SDH_BLE_VS_UUID_COUNT = 4 NRF_SDH_BLE_GATTS_ATTR_TAB_SIZE = 0x720 1412:microbit_ble_sdh_req_handler changeOK = 1 Just Works security enableBonding getBondCount 1 DEVICE_INFORMATION_SERVICE servicesChanged getBondCount 1 service_changed_pending for peer 0 = 1 (err 0x0) configureAdvertising connectable 1, discoverable 1 whitelist 0, interval_ms 50, timeout_seconds 0 setTransmitPower 1 BLE_GAP_TX_POWER_ROLE_ADV advertise pairingMode stopAdvertising configureAdvertising connectable 1, discoverable 1 whitelist 0, interval_ms 200, timeout_seconds 0 advertise PM_EVT_PEER_DATA_UPDATE_SUCCEEDED pairingComplete UPDATE BLE_GAP_EVT_CONNECTED 1 bleConnectionCallback 0 PM_EVT_PEER_DATA_UPDATE_SUCCEEDED pairingComplete UPDATE PM_EVT_PEER_DATA_UPDATE_SUCCEEDED pairingComplete UPDATE PM_EVT_PEER_DATA_UPDATE_SUCCEEDED pairingComplete UPDATE pairingComplete UPDATE BLE_GAP_EVT_AUTH_STATUS 1 pairingComplete AUTH PM_EVT_PEER_DATA_UPDATE_SUCCEEDED pairingComplete UPDATE PM_EVT_PEER_DATA_UPDATE_SUCCEEDED pairingComplete UPDATE pairingComplete SUCCESS 18846:MicroBitBLEManager::idleCallback MICROBIT_BLE_STATUS_DISCONNECT microbit_ble_for_each_connected_disconnect 0 onDisconnect advertise ```
DMESG logs for SECURITY_MODE_ENCRYPTION_NO_MITM after reset ``` Pairing mode resetrelocate vtor to 0x0 -> 0x20003800 0x20003800 MicroBitBLEManager::init NRF_SDH_BLE_VS_UUID_COUNT = 4 NRF_SDH_BLE_GATTS_ATTR_TAB_SIZE = 0x720 112:microbit_ble_sdh_req_handler changeOK = 1 Just Works security DEVICE_INFORMATION_SERVICE servicesChanged getBondCount 1 service_changed_pending for peer 0 = 0 (err 0x0) PM_EVT_PEER_DATA_UPDATE_SUCCEEDED pm_local_database_has_changed complete after 3ms configureAdvertising connectable 1, discoverable 1 whitelist 0, interval_ms 50, timeout_seconds 0 setTransmitPower 1 BLE_GAP_TX_POWER_ROLE_ADV advertise MicroBitBLEService::RegisterBaseUUID bs_uuid_type = 2 MicroBitBLEService::CreateService( 0x100) = 21 MICROBIT_BLE_SECURITY_MODE 2 MicroBitBLEService::CreateCharacteristic( 0x101) = 23 0 0 0 ```

For reference these are the defines I have set:

DEVICE_BLE=1
MICROBIT_BLE_ENABLED=1
MICROBIT_BLE_DFU_SERVICE=0
MICROBIT_BLE_DEVICE_INFORMATION_SERVICE=1
MICROBIT_BLE_PARTIAL_FLASHING=0

with for the BLE_OPEN logs

MICROBIT_BLE_OPEN=1

with the pairing one

MICROBIT_BLE_SECURITY_LEVEL=SECURITY_MODE_ENCRYPTION_NO_MITM

It did work once with MICROBIT_BLE_OPEN, but I have been unable to connect with it in that mode ever since.

MatsSyvertsen commented 9 months ago

Turns out I had managed to create a BLEService on the stack instead of the heap leading to this weird behaviour