This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Bondmanager and scheduler

I took the ble_app_proximity as an example. Before I introduced the scheduler it worked ( not always but reasonably well).

I added APP_SCHED_INIT(SCHED_MAX_EVENT_DATA_SIZE, SCHED_QUEUE_SIZE); to the main init. I added app_sched_execute(); to the main for(;;) loop. I changed APP_BUTTON_INIT to use the scheduler I changed BLE_STACK_HANDLER_INIT to use the scheduler

Now when I use Master Control Panel, I can see the unit advertising, I can select it but after trying to bond it shows in the log

========= loading master emulator====================== [15:13:08.1] More than one compatible master emulator devices were found. Please select a device. [15:13:11.8] Loading... [15:13:12.5] Device address: 0x90828F67A47B [15:13:12.6] Master emulator firmware version: MEFW_nRF51822_0.8.0.5879 [15:13:16.3] Ready [15:13:16.7] SERVER: Server has started [15:13:18.5] Device discovery started [15:13:24.5] Device discovery stopped

================= found my devices ========================

[15:13:29.5] GetDeviceInfo() [15:13:30.1] ---------------------------- [15:13:30.1] Connected to device [15:13:30.1] Role: 0 [15:13:30.1] PeerAddressType: 1 [15:13:30.1] PeerAddress (MSB): CE5417DE9B2E [15:13:30.2] Connection Interval: 20.0ms [15:13:30.2] Connection Latency: 0 [15:13:30.2] Supervision Timeout: 3000ms [15:13:30.2] Clock Accuracy: (1) [15:13:30.2] ---------------------------- [15:13:30.3] Connected to address: 2E9BDE1754CE [15:13:30.3] SERVER: Received packet <class 'protocol.Att.AttFindByTypeValueRequest'> - [0x06, 0x01, 0x00, 0xFF, 0xFF, 0x00, 0x28, 0x02, 0x18]

========== service discovery ============================= [15:13:30.4] Starting a Read Information Request on the whole remote DB [15:13:30.5] SERVER: Returned packet <class 'protocol.Att.AttErrorResponse'> - [0x01, 0x06, 0x01, 0x00, 0x0A] [15:13:30.7] Discovering all attribute UUIDs [15:13:30.8] {'UUID': 10240} [15:13:30.8] Received a Service group UUID [15:13:30.8] {'UUID': 10243} [15:13:30.8] Received a Characteristic Group group UUID [15:13:30.8] {'UUID': 10752} [15:13:30.8] Received a Characteristic Group group attribute [15:13:30.8] {'UUID': 10243} [15:13:30.9] Received a Characteristic Group group UUID [15:13:30.9] {'UUID': 10753} [15:13:30.9] Received a Characteristic Group group attribute [15:13:30.9] {'UUID': 10243} [15:13:30.9] Received a Characteristic Group group UUID [15:13:31.0] {'UUID': 10756} [15:13:31.0] Received a Characteristic Group group attribute [15:13:31.0] {'UUID': 10240} [15:13:31.0] Received a Service group UUID [15:13:31.0] {'UUID': 10243} [15:13:31.0] Received a Characteristic Group group UUID [15:13:31.0] {'UUID': 10757} [15:13:31.1] Received a Characteristic Group group attribute [15:13:31.1] {'UUID': 10498} [15:13:31.1] Received a Characteristic Group group attribute [15:13:31.1] {'UUID': 10240} [15:13:31.1] Received a Service group UUID [15:13:31.1] {'UUID': 10243} [15:13:31.1] Received a Characteristic Group group UUID [15:13:31.1] {'UUID': 10759} [15:13:31.1] Received a Characteristic Group group attribute [15:13:31.1] {'UUID': 10240} [15:13:31.2] Received a Service group UUID [15:13:31.2] {'UUID': 10243} [15:13:31.2] Received a Characteristic Group group UUID [15:13:31.2] {'UUID': 10758} [15:13:31.2] Received a Characteristic Group group attribute [15:13:31.2] {'UUID': 10240} [15:13:31.2] Received a Service group UUID [15:13:31.2] {'UUID': 10243} [15:13:31.2] Received a Characteristic Group group UUID [15:13:31.2] {'UUID': 10758} [15:13:31.3] Received a Characteristic Group group attribute [15:13:31.4] Discovering all attribute values [15:13:31.5] Received Read Response, handle: 0x0001, value (0x): 00-18 [15:13:31.6] Received Read Response, handle: 0x0002, value (0x): 0A-03-00-00-2A [15:13:31.7] Received Read Response, handle: 0x0003, value (0x): 41-74-75-73-5F-44-4C-54 [15:13:31.7] Received Read Response, handle: 0x0004, value (0x): 02-05-00-01-2A [15:13:31.8] Received Read Response, handle: 0x0005, value (0x): 00-02 [15:13:31.9] Received Read Response, handle: 0x0006, value (0x): 02-07-00-04-2A [15:13:32.0] Received Read Response, handle: 0x0007, value (0x): 90-01-20-03-00-00-90-01 [15:13:32.0] Received Read Response, handle: 0x0008, value (0x): 01-18 [15:13:32.1] Received Read Response, handle: 0x0009, value (0x): 20-0A-00-05-2A [15:13:32.2] Received Error Response: READ_NOT_PERMITTED, handle: 0x000A [15:13:32.2] Received Read Response, handle: 0x000B, value (0x): 00-00 [15:13:32.3] Received Read Response, handle: 0x000C, value (0x): 04-18 [15:13:32.4] Received Read Response, handle: 0x000D, value (0x): 0A-0E-00-07-2A [15:13:32.4] Received Error Response: INSUFFICIENT_AUTHENTICATION, handle: 0x000E [15:13:32.5] Received Read Response, handle: 0x000F, value (0x): 02-18 [15:13:32.6] Received Read Response, handle: 0x0010, value (0x): 04-11-00-06-2A [15:13:32.6] Received Error Response: READ_NOT_PERMITTED, handle: 0x0011 [15:13:32.7] Received Read Response, handle: 0x0012, value (0x): 03-18 [15:13:32.7] Received Read Response, handle: 0x0013, value (0x): 0A-14-00-06-2A [15:13:32.8] Received Error Response: INSUFFICIENT_AUTHENTICATION, handle: 0x0014 [15:13:32.8] Service Discovery complete

================= discovery complete ===============

[15:13:34.9] Received Connection Parameter Update Request [15:13:35.0] ConnectionParameterUpdateResponse sent with ACCEPTED response [15:13:35.0] Connection Parameters Update sent. ConnInterval:500.0ms, SlaveLatency:0, SupervisionTimeout:4000.0ms [15:13:35.1] PacketQueueSearch skipped event code 0x0D

================= try to bond ================= [15:13:44.7] BondToDevice() [15:13:51.2] Encryption change: Link encryption is ON [15:13:51.3] SERVER: Received packet <HciEvent: eventCode=0x0B> - <HciEvent: eventCode=0x0B> [15:13:51.3] SERVER: Received Encryption Change Event [15:13:57.7] Lost connection to device. Reason: BTLE_CONNECTION_TIMEOUT [15:13:57.7] SERVER: Received packet <HciEvent: eventCode=0x0A> - <HciEvent: eventCode=0x0A> [15:13:57.8] SERVER: Received Link Loss

================ again try to bond ===============

[15:14:12.0] BondToDevice() [15:14:12.5] ---------------------------- [15:14:12.5] Connected to device [15:14:12.5] Role: 0 [15:14:12.5] PeerAddressType: 1 [15:14:12.5] PeerAddress (MSB): CE5417DE9B2E [15:14:12.5] Connection Interval: 20.0ms [15:14:12.5] Connection Latency: 0 [15:14:12.5] Supervision Timeout: 3000ms [15:14:12.5] Clock Accuracy: (1) [15:14:12.5] ---------------------------- [15:14:12.7] Bond already exists with 2E9BDE1754CE [15:14:12.7] Starting encryption [15:14:12.7] Lost connection to device. Reason: BTLE_CONN_FAILED_TO_BE_ESTABLISHED [15:14:12.7] SERVER: Received packet <HciEvent: eventCode=0x0A> - <HciEvent: eventCode=0x0A> [15:14:12.7] SERVER: Received Link Loss

So what am I missing here

  • I saw that the bondmanager init structure also has room for an event handler. This is not implemented in the proximity demo.

    Might this be the cause of the troubles?

  • The bond manager's event handler is not required to make things work.

    By default app_error_handler on top of main contains a reset, but I'd recommend you to remove that for development and instead use an infinite loop (or ble_debug_assert_handler). This should make it possible for you to see what kind of error occurs, and better be able to debug the problem.

    If this does not help you, can you please supply the error code and line number/file the error handler points at (if any), and the full source code of your modified app?

    Edit: Clarified that it is the bond manager's event handler that's not required. You do need the bond manager to support bonding (unless you want to reimplement its functionality yourself, which I would strongly recommend you not to.

Related