<?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>ANCS Code base (bonding) with NUS and strange behaviour with nRF Toolbox</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/22101/ancs-code-base-bonding-with-nus-and-strange-behaviour-with-nrf-toolbox</link><description>Hello the Nordic Team, 
 I come here after a lot of research and testing and do not understand what is going on in my program. (is it Embedded or iPhone nRF Toolbox side ?) 
 I took the ANCS code ( nRF5_SDK_12.2.0_f012efa &amp;gt; ble_app_ancs_c ) as a base</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 23 May 2017 12:38:26 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/22101/ancs-code-base-bonding-with-nus-and-strange-behaviour-with-nrf-toolbox" /><item><title>RE: ANCS Code base (bonding) with NUS and strange behaviour with nRF Toolbox</title><link>https://devzone.nordicsemi.com/thread/86839?ContentTypeID=1</link><pubDate>Tue, 23 May 2017 12:38:26 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ef17e9cc-8626-406d-af0f-83710e633e8a</guid><dc:creator>trdop</dc:creator><description>&lt;p&gt;Thanks Petter,
As it&amp;#39;s used to say, it&amp;#39;s the simplest things that pass to the trap !
It work this way, by handling the re-connecting on the previously bonded device reference on my side with nRF Toolbox !&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: ANCS Code base (bonding) with NUS and strange behaviour with nRF Toolbox</title><link>https://devzone.nordicsemi.com/thread/86838?ContentTypeID=1</link><pubDate>Tue, 23 May 2017 11:39:50 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2bed7e78-d7d2-4c36-907b-b13ce9b16210</guid><dc:creator>trdop</dc:creator><description>&lt;p&gt;Ok thanks, gonna try to make the adaptation on the iOS App Side, what was strange it that the Android will do the reconnection from the nRF Toolbox App.
But it&amp;#39;s maybe because, there is no ANCS and Android
and it wasn&amp;#39;t required me to accept Pairing with Bonding.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: ANCS Code base (bonding) with NUS and strange behaviour with nRF Toolbox</title><link>https://devzone.nordicsemi.com/thread/86837?ContentTypeID=1</link><pubDate>Tue, 23 May 2017 10:48:48 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4f82df56-86ae-4efb-a6d0-e3dc7f9e9ff0</guid><dc:creator>Petter Myhre</dc:creator><description>&lt;p&gt;Ok. I think that is simply because the app itself will not reconnect, even though the is a reconnection at a system level. If this is a behavior you want, I think you must modify the app. The fix I proposed was so that the peripheral will actually send a message, which I believe it didn&amp;#39;t before. But it doesn&amp;#39;t help the it sends a message if there is no iOS app there to receive it. ANCS doesn&amp;#39;t need an app, so that will work.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: ANCS Code base (bonding) with NUS and strange behaviour with nRF Toolbox</title><link>https://devzone.nordicsemi.com/thread/86836?ContentTypeID=1</link><pubDate>Tue, 23 May 2017 10:35:30 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5bb1068f-5958-4729-aceb-3327f5ae7165</guid><dc:creator>trdop</dc:creator><description>&lt;p&gt;Hi Petter,&lt;/p&gt;
&lt;p&gt;Thanks for your response,&lt;/p&gt;
&lt;p&gt;I tried to do as you advised, but it does not work at the &amp;quot;re-connection&amp;quot; after a standby of the board and a wake up. The ANCS is well re-connected and in my settings iOS the device connects well, but from the application nRF Toolbox, the last message I received in my log of the application:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;[35] 12: 26: 27.453 | Network | Thread 8 | Error Code: The connection has timed out unexpectedly.
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;I can always send messages to my board via nRF Toolbox; If I send the command: &amp;gt;LED, the corresponding LED lights up ... but not returning from the Board to the iPhone, when sending a command provided for this purpose.&lt;/p&gt;
&lt;p&gt;Here is what I have changed in the file: ble_nus.c&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;/**@brief Function for handling the @ref BLE_GATTS_EVT_WRITE event from the S110 SoftDevice.
 *
 * @param[in] p_nus     Nordic UART Service structure.
 * @param[in] p_ble_evt Pointer to the event received from BLE stack.
 */
static void on_write(ble_nus_t * p_nus, ble_evt_t * p_ble_evt)
{
    ble_gatts_evt_write_t * p_evt_write = &amp;amp;p_ble_evt-&amp;gt;evt.gatts_evt.params.write;

    **p_nus-&amp;gt;is_notification_enabled = true;**
    
    if (
        (p_evt_write-&amp;gt;handle == p_nus-&amp;gt;rx_handles.cccd_handle)
        &amp;amp;&amp;amp;
        (p_evt_write-&amp;gt;len == 2)
       )
    {
        if (ble_srv_is_notification_enabled(p_evt_write-&amp;gt;data))
        {
            **p_nus-&amp;gt;is_notification_enabled = true;**
        }
        else
        {
**//            p_nus-&amp;gt;is_notification_enabled = false;**
        }
    }
    else if (
             (p_evt_write-&amp;gt;handle == p_nus-&amp;gt;tx_handles.value_handle)
             &amp;amp;&amp;amp;
             (p_nus-&amp;gt;data_handler != NULL)
            )
    {
        p_nus-&amp;gt;data_handler(p_nus, p_evt_write-&amp;gt;data, p_evt_write-&amp;gt;len);
    }
    else
    {
        // Do Nothing. This event is not relevant for this service.
    }
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;and:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;uint32_t ble_nus_init(ble_nus_t * p_nus, const ble_nus_init_t * p_nus_init)
{
    uint32_t      err_code;
    ble_uuid_t    ble_uuid;
    ble_uuid128_t nus_base_uuid = NUS_BASE_UUID;

    VERIFY_PARAM_NOT_NULL(p_nus);
    VERIFY_PARAM_NOT_NULL(p_nus_init);

    // Initialize the service structure.
    p_nus-&amp;gt;conn_handle             = BLE_CONN_HANDLE_INVALID;
    p_nus-&amp;gt;data_handler            = p_nus_init-&amp;gt;data_handler;
    **p_nus-&amp;gt;is_notification_enabled = true;**
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;and:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;uint32_t ble_nus_string_send(ble_nus_t * p_nus, uint8_t * p_string, uint16_t length)
{
    ble_gatts_hvx_params_t hvx_params;

    VERIFY_PARAM_NOT_NULL(p_nus);

**//    if ((p_nus-&amp;gt;conn_handle == BLE_CONN_HANDLE_INVALID) || (!p_nus-&amp;gt;is_notification_enabled))
//    {
//        return NRF_ERROR_INVALID_STATE;
//    }**

    if (length &amp;gt; BLE_NUS_MAX_DATA_LEN)
    {
        return NRF_ERROR_INVALID_PARAM;
    }
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Thank you again, for trying to get me out of this shadow I try to do, in my opinion, something simple.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: ANCS Code base (bonding) with NUS and strange behaviour with nRF Toolbox</title><link>https://devzone.nordicsemi.com/thread/86835?ContentTypeID=1</link><pubDate>Mon, 22 May 2017 15:47:58 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f2a2f219-90e3-493b-85d9-364c2fc4cffe</guid><dc:creator>Petter Myhre</dc:creator><description>&lt;p&gt;I suspect that this check is failing on reconnection:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;if ((p_nus-&amp;gt;conn_handle == BLE_CONN_HANDLE_INVALID) || (!p_nus-&amp;gt;is_notification_enabled))
{
    return NRF_ERROR_INVALID_STATE;
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Because is_notification_enabled is only set to true when the CCCD is written to true by the client:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;    if (ble_srv_is_notification_enabled(p_evt_write-&amp;gt;data))
    {
        p_nus-&amp;gt;is_notification_enabled = true;
    }
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;But since you are bonded, the client will not write to the CCCD, it will expect you to have saved its state from the last connection.&lt;/p&gt;
&lt;p&gt;You can try to remove the check, or set is_notification_enabled to true somehow, for example when you get the PM_EVT_LOCAL_DB_CACHE_APPLIED event.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: ANCS Code base (bonding) with NUS and strange behaviour with nRF Toolbox</title><link>https://devzone.nordicsemi.com/thread/86834?ContentTypeID=1</link><pubDate>Thu, 18 May 2017 12:15:38 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:cc029c75-4767-41e8-ae0f-a4b5d3e72dc7</guid><dc:creator>Petter Myhre</dc:creator><description>&lt;p&gt;Would it be possible for you to share your complete project so I can test it here?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>