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

Trying to integrate bonding into uart example, but peer manager event handler never being called

I developed a functioning application that advertises with Nordic UART Service, connects to a smartphone application, then reads various sensor data using the SAADC and transmits data to a smartphone. I now want to integrate bonding into the application. I have done a lot of reading online, checking examples, and borrowed some code from the ble_app_template example. 

This strategy seemed to work on my iPhone with nRF Connect at first. Upon connection, my application would enter the pm_evt_handler() function and the PM_EVT_CONN_SEC_SUCCEEDED case within peer_manager_handler.c, function pm_handler_evt_log(), would be entered. My debug console would log That the connection was secured, with procedure: encryption. I also noticed that my application was listed and available in my iPhone's bluetooth settings, which had never happened before (only appeared in scans through nRF Connect or similar ble applications). I then wanted to experiment with deleting bonds from with my application, but after doing so my program would enter the PM_EVT_CONN_SEC_FAILED case and print the connection security had failed with error 4102. Research pointed towards the error coming from bonds being deleted on my peripheral device, but not the smartphone. So I selected "forget this device" from within my iPhone bluetooth settings. 

I restarted my application without deleting bonds, then received some sort of database error. I cannot remember what the error was exactly and I did not save it, and can no longer reproduce it. I cannot reproduce it because now my application never enters the peer manager event handler function, pm_evt_handler(). The peer manager is being initialized, but my application seems to have lost all functionality with regards to the peer manager and I have not changed the code at all.

Can somebody please help me try to pinpont what I am doing wrong? My application is based off of the uart example, and I integrated peer manager functions from the ble_app_template example project. My application still functions fine with regards to reading SAADC values, timers, regular advertising/connection, etc, but has no peer manager behavior. Below I am pasting my main.c and sdk_config.h files. Please ignore functions related to SAADC, reading values, etc - there are many parts I should clean up and optimize that I am already aware of. 

Code related to peer manager are: lines 136-143, 230-250, 583-612, 616-624, 1212-1234. I began writing this application when I was first learning C, so code as seen in function "format_bluetooh_packet()" is painful to look at and is on my to-do to fix. All i want right now is to get peer manager working and then I can clean up/refactor older code. 

--

main.c

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
/**
* Copyright (c) 2014 - 2018, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

sdk_config.h

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
/**
* Copyright (c) 2014 - 2018, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX