<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Proper way to wait for events</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/8475/proper-way-to-wait-for-events</link><description>I&amp;#39;m trying to establish a bond in my project and then perform service discovery, however the discovery is returning the BUSY error. 
 I tried to wait for the events according to the documentation but they will never trigger so long as I have the while</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Mon, 03 Aug 2015 06:37:26 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/8475/proper-way-to-wait-for-events" /><item><title>RE: Proper way to wait for events</title><link>https://devzone.nordicsemi.com/thread/30911?ContentTypeID=1</link><pubDate>Mon, 03 Aug 2015 06:37:26 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c65df73e-bfaf-4d55-a204-b3c731557c92</guid><dc:creator>Susheel Nuguru</dc:creator><description>&lt;p&gt;dm_security_setup_req calls sd_ble_gap_encrypt
This is what I read from the header file ble_gap.h-&amp;gt;sd_ble_gap_encrypt&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;@retval ::NRF_ERROR_BUSY Procedure already in progress or not allowed at this time, wait for pending procedures to complete and retry.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;It says that just waiting is not enough, you need to retry again&lt;/p&gt;
&lt;p&gt;You can start a timer instead of WHILE  and check for the bondPending flag in the timer callback and call dm_security_setup_req again. That should be safe way to do this. There are few examples in SDK that do it this way (ble_app_ancs_c for example), how much time you app can wait is app specific, I recommend you to wait few connection intervals until the possibility of security setup failure is excluded.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>