<?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>Client without Notifications bricking device</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/61011/client-without-notifications-bricking-device</link><description>Hey everyone, I have a device that&amp;#39;s in production and everything is working great, however we have a customer that is creating their own software to interface with our sensor and they bricked a couple units because they did not turn notifications on</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Mon, 18 May 2020 08:35:11 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/61011/client-without-notifications-bricking-device" /><item><title>RE: Client without Notifications bricking device</title><link>https://devzone.nordicsemi.com/thread/250377?ContentTypeID=1</link><pubDate>Mon, 18 May 2020 08:35:11 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f3c3114e-788b-422d-af5d-8614f0fb785c</guid><dc:creator>Edvin</dc:creator><description>&lt;p&gt;My colleague&amp;nbsp;&lt;a href="https://devzone.nordicsemi.com/members/foolsday"&gt;Daniel Veilleux&lt;/a&gt;&amp;nbsp;is right. Your transmit_samples() function never lets go. If this called from an interrupt, it will block other interrupts, because you never exit this interrupt. You should definitely consider calling this from your main loop.&lt;/p&gt;
&lt;p&gt;I don&amp;#39;t know what interrupt you are calling&amp;nbsp;transmit_samples() from, but for the arguments sake, let&amp;#39;s say it is a button press. How about something like this:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;volatile bool transmit_samples_flag = false;

void button_press_handler()
{
    transmit_samples_flag = true;
}


...
int main(void)
{
    ...
    while (true)
    {
        if (transmit_samples_flag)
        {
            transmit_samples_flag = false;
            transmit_samples();
        }
        pwr_management_function();
    }
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;I believe you mentioned that you didn&amp;#39;t want this kind of implementations because of current consumption. If current consumption is a concern, you should definitely break out of the:&lt;/p&gt;
&lt;p&gt;while((err_code != NRF_ERROR_RESOURCES) &amp;amp;&amp;amp; (requested_samples &amp;gt; transmitted_samples)){&lt;/p&gt;
&lt;p&gt;if err_code = NRF_INVALID_STATE, because if you don&amp;#39;t, the application will just spin through this while loop, actually never going to sleep at all.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;    while((err_code != NRF_ERROR_RESOURCES) &amp;amp;&amp;amp; (requested_samples &amp;gt; transmitted_samples)){
        
        /*FORM THE PACKET*/

        //send the packet!
        err_code = ble_ctcws_send_data(m_conn_handle, &amp;amp;m_ctcws, ble_packet, &amp;amp;packet_bytes_to_tx);
    
        //if we didn&amp;#39;t get an error, and we&amp;#39;re not done: incriment the number of samples and packets
        if (err_code == NRF_SUCCESS){
          transmitted_samples += (bytes_to_tx/2);
          packet_number ++;
        }
        else if (err_code != NRF_ERROR_RESOURCES)
        {
            break;  // you might as well break out of the while loop here, because if 
                    // err_code is not NRF_SUCCESS or NRF_ERROR_RESOURCES, it will not
                    // be the next time you call it either (until notifications are enabled).
        }
      }//while != NRF_ERROR_RESOURCES&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;BR,&lt;/p&gt;
&lt;p&gt;Edvin&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Client without Notifications bricking device</title><link>https://devzone.nordicsemi.com/thread/250273?ContentTypeID=1</link><pubDate>Fri, 15 May 2020 18:31:22 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:85114525-0691-4c55-a1dc-4eb88f883658</guid><dc:creator>Adam Gerken</dc:creator><description>&lt;p&gt;I&amp;#39;m not convinced that&amp;#39;s the right solution. Everything is event driven in my app, all main does is go to low power mode to wait for an event. This device has to operate for a couple years on a pair of coin cells so I have no extra power to spare.&lt;/p&gt;
&lt;p&gt;This thread has gone way off into left field as I grasp at straws. The right solution is for my app to know if the client has notifications enabled. Edvin kept talking about it but I still have no idea how to do that.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Client without Notifications bricking device</title><link>https://devzone.nordicsemi.com/thread/250272?ContentTypeID=1</link><pubDate>Fri, 15 May 2020 18:17:46 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:98962850-e84a-4341-ab91-100710f5375b</guid><dc:creator>Daniel Veilleux</dc:creator><description>&lt;p&gt;OK, so then your final ADC reading calls&amp;nbsp;&lt;em&gt;transmit_samples&lt;/em&gt; and gets stuck in an infinite loop at interrupt priority 5 -- the end result is the same. I think a lot of your problems would go away if you stopped calling &lt;em&gt;transmit_samples&lt;/em&gt; from an interrupt context / callback and only called it from main.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Client without Notifications bricking device</title><link>https://devzone.nordicsemi.com/thread/250271?ContentTypeID=1</link><pubDate>Fri, 15 May 2020 18:05:43 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:beb4697a-12af-4f98-a1f3-57dd122ee05b</guid><dc:creator>Adam Gerken</dc:creator><description>[quote userid="4528" url="~/f/nordic-q-a/61011/client-without-notifications-bricking-device/250267"]OK, the adc_callback is probably getting executed at interrupt priority 6 in your firmware (usually defined as&amp;nbsp;NRFX_SAADC_CONFIG_IRQ_PRIORITY in your &lt;strong&gt;sdk_config.h&lt;/strong&gt;)[/quote]
&lt;p&gt;The SAADC is actually priority 5, since when it&amp;#39;s running it&amp;#39;s the most important thing happening. It&amp;#39;s also only the last ADC reading that triggers the transmit_samples routine. The ADC is timing critical so I write all the samples into a buffer, then transmit_samples reads the buffer memory, forms packets and send them out.&lt;/p&gt;
&lt;p&gt;So it basically:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Gets a read request&lt;/li&gt;
&lt;li&gt;Turns on a PPI to start taking readings&lt;/li&gt;
&lt;li&gt;Triggers an ADC event that the ADC buffer is full, put these readings into an external QSPI memory&lt;/li&gt;
&lt;li&gt;Turn off the PPI channel to stop the ADC readings then call transmit_samples to compile and send the first packet&lt;/li&gt;
&lt;li&gt;BLE_GATTS_EVT_HVN_TX_COMPLETE then calls the remaining iterations of transmit_samples&lt;/li&gt;
&lt;li&gt;Once it&amp;#39;s done, I send a confirmation, disconnect and advertise.&lt;/li&gt;
&lt;/ul&gt;
[quote userid="4528" url="~/f/nordic-q-a/61011/client-without-notifications-bricking-device/250267"]You should check for NRF_ERROR_INVALID_STATE when you call &lt;em&gt;ble_ctcws_send_status. &lt;/em&gt;Then you can either wait for the peer device to enable the notification, as described by Edvin above, or disconnect[/quote]
&lt;p&gt;This is exactly what I was trying to do at the bottom of my transmit_samples routine and it wasn&amp;#39;t working. When I try to disconnect after getting NRF_ERROR_INVALID_STATE&amp;nbsp; back from ble_ctcws_send_data nothing works. Nothing. sd_ble_gap_disconnect doesn&amp;#39;t work, interrupts are gone, etc.&lt;/p&gt;
[quote userid="4528" url="~/f/nordic-q-a/61011/client-without-notifications-bricking-device/250267"]If you disconnect then I&amp;#39;d recommend calling &lt;em&gt;sd_ble_gap_disconnect&lt;/em&gt; and then waiting for the BLE_GAP_EVT_DISCONNECTED before restarting advertising (or simply calling NVIC_SystemReset).[/quote]
&lt;p&gt;This is exactly what I do... send the sd_ble_gap_disconnect then wait for the&amp;nbsp;BLE_GAP_EVT_DISCONNECTED event, which triggers the hardware to go into low power mode, and start advertising again.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;As I said above, I&amp;#39;m totally lost with the soft device functionality for the most part, and I have no idea whats going on for most of it... I&amp;#39;m a consultant and have like 100 projects going at the same time so this isn&amp;#39;t a full time thing trying to understand all the tiny details of this. I guess that&amp;#39;s an issue but there&amp;#39;s not much I can do about it. I just need to get this tiny thing done so my customer can start shipping these.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Client without Notifications bricking device</title><link>https://devzone.nordicsemi.com/thread/250267?ContentTypeID=1</link><pubDate>Fri, 15 May 2020 17:19:25 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:74ba2374-2317-4f2a-a2c7-10f03ecff412</guid><dc:creator>Daniel Veilleux</dc:creator><description>&lt;p&gt;Hello Adam,&lt;/p&gt;
&lt;p&gt;OK, the adc_callback is probably getting executed at interrupt priority 6 in your firmware (usually defined as&amp;nbsp;NRFX_SAADC_CONFIG_IRQ_PRIORITY in your &lt;strong&gt;sdk_config.h&lt;/strong&gt;). The events from the SoftDevice are also delivered in interrupt priority 6 for the S140. So it sounds like you end up in an infinite while loop in&amp;nbsp;&lt;em&gt;transmit_samples --&lt;/em&gt;executing at interrupt priority 6-- because you aren&amp;#39;t exiting when you see NRF_ERROR_INVALID_STATE. This will effectively block you from receiving further SoftDevice or SAADC events.&lt;/p&gt;
&lt;p&gt;You should check for NRF_ERROR_INVALID_STATE when you call &lt;em&gt;ble_ctcws_send_status. &lt;/em&gt;Then you can either wait for the peer device to enable the notification, as described by Edvin above, or disconnect. If you disconnect then I&amp;#39;d recommend calling &lt;em&gt;sd_ble_gap_disconnect&lt;/em&gt; and then waiting for the BLE_GAP_EVT_DISCONNECTED before restarting advertising (or simply calling NVIC_SystemReset).&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Client without Notifications bricking device</title><link>https://devzone.nordicsemi.com/thread/250247?ContentTypeID=1</link><pubDate>Fri, 15 May 2020 15:38:45 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9a7f7869-92d1-4dd1-8cdf-8d09490c2e2f</guid><dc:creator>Adam Gerken</dc:creator><description>[quote userid="4528" url="~/f/nordic-q-a/61011/client-without-notifications-bricking-device/250058"]Is your &lt;em&gt;transmit_samples&lt;/em&gt; function called in an interrupt context? If so, no other interrupts can preempt it unless they are a strictly greater priority (lower number).[/quote]
&lt;p&gt;Um, I don&amp;#39;t think so? It gets called initially from the final adc_callback, then from there on it gets called from the&amp;nbsp;BLE_GATTS_EVT_HVN_TX_COMPLETE event, as the softdevice buffer empties. So I guess maybe?&lt;/p&gt;
&lt;p&gt;I have absolutely no issues with interrupts if the client device has notifications enabled, the whole thing works perfectly and reliably. As soon as it gets tripped up with a client that doesn&amp;#39;t have notifications enabled everything stops. I don&amp;#39;t really need to &amp;quot;handle&amp;quot; this other than just disconnecting the connection... not using notifications isn&amp;#39;t supported, the only issue is if a customer messes this up somehow the device hangs forever.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
[quote userid="4528" url="~/f/nordic-q-a/61011/client-without-notifications-bricking-device/250058"]f &lt;em&gt;sd_ble_gap_disconnect&lt;/em&gt; is returning NRF_ERROR_INVALID_STATE then &amp;quot;Disconnection in progress or link has not been established.&amp;quot; Not sure how you debugged it but maybe the first call to &lt;em&gt;sd_ble_gap_disconnect&lt;/em&gt; succeeded and then the second call reported an error and got your attention?[/quote]
&lt;p&gt;This really confused me... I can&amp;#39;t find the logic in why this is the error that sd_ble_gap_disconnect is returning. I&amp;#39;m only calling it once and it fails, even though the connection is still up. This goes back to the issue of the whole thing just locking up once I try to send a packet to a client without notifications. I just can&amp;#39;t get my hands around what it&amp;#39;s doing.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Client without Notifications bricking device</title><link>https://devzone.nordicsemi.com/thread/250058?ContentTypeID=1</link><pubDate>Thu, 14 May 2020 20:17:09 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b4ba1c35-efa1-46bb-a9a1-660e0e6108e2</guid><dc:creator>Daniel Veilleux</dc:creator><description>&lt;p&gt;Is your &lt;em&gt;transmit_samples&lt;/em&gt; function called in an interrupt context? If so, no other interrupts can preempt it unless they are a strictly greater priority (lower number).&lt;/p&gt;
&lt;p&gt;If &lt;em&gt;sd_ble_gap_disconnect&lt;/em&gt; is returning NRF_ERROR_INVALID_STATE then &amp;quot;Disconnection in progress or link has not been established.&amp;quot; Not sure how you debugged it but maybe the first call to &lt;em&gt;sd_ble_gap_disconnect&lt;/em&gt; succeeded and then the second call reported an error and got your attention?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Client without Notifications bricking device</title><link>https://devzone.nordicsemi.com/thread/250055?ContentTypeID=1</link><pubDate>Thu, 14 May 2020 19:38:06 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:cfabbb39-d54b-4e3e-920a-895d0103aae2</guid><dc:creator>Adam Gerken</dc:creator><description>&lt;p&gt;I don&amp;#39;t believe so. My preprocessor defines are just:&lt;/p&gt;
&lt;p&gt;CONFIG_GPIO_AS_PINRESET&lt;/p&gt;
&lt;p&gt;CONFIG_NFCT_PINS_AS_GPIOS&lt;/p&gt;
&lt;p&gt;FLOAT_ABI_HARD&lt;/p&gt;
&lt;p&gt;INITIALIZE_USER_SECTIONS&lt;/p&gt;
&lt;p&gt;NO_VTOR_CONFIG&lt;/p&gt;
&lt;p&gt;NRF52840_XXAA&lt;/p&gt;
&lt;p&gt;NRF_SD_BLE_API_VERSION=6&lt;/p&gt;
&lt;p&gt;S140&lt;/p&gt;
&lt;p&gt;SOFTDEVICE_PRESENT&lt;/p&gt;
&lt;p&gt;SWI_DISABLE0&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;I do believe that I&amp;#39;m getting NRF_ERROR_INVALID_STATE back after I call my send_data, which does call&amp;nbsp;&lt;span&gt;sd_ble_gatts_hvx. The issue I&amp;#39;m running into now, is what do I do then? If I call&amp;nbsp;sd_ble_gap_disconnect I also just get&amp;nbsp;NRF_ERROR_INVALID_STATE&amp;nbsp;back. I think this is where it&amp;#39;s all hung up.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;I don&amp;#39;t do an error check after calling my send data routine though, so I&amp;#39;m not sure why it would be getting hung up to the point of disabling all the interrupts. I only look for SUCCESS, or ERROR_RESOURCES for program logic stuff.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Here&amp;#39;s the routine that&amp;#39;s calling my &amp;quot;send_data&amp;quot;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;pre class="ui-code" data-mode="text"&gt;void transmit_samples(void){

    ret_code_t            err_code;
    uint16_t              bytes_to_tx, packet_bytes_to_tx;
    uint8_t               ble_packet[DEFAULT_MAX_MTU_SIZE];
    uint8_t               checksum;

    //send packets until we&amp;#39;ve filled the buffer, or we&amp;#39;re done.
    if (requested_samples &amp;gt; transmitted_samples){

      while((err_code != NRF_ERROR_RESOURCES) &amp;amp;&amp;amp; (requested_samples &amp;gt; transmitted_samples)){
        
        /*FORM THE PACKET*/

        //send the packet!
        err_code = ble_ctcws_send_data(m_conn_handle, &amp;amp;m_ctcws, ble_packet, &amp;amp;packet_bytes_to_tx);
    
        //if we didn&amp;#39;t get an error, and we&amp;#39;re not done: incriment the number of samples and packets
        if (err_code == NRF_SUCCESS){
          transmitted_samples += (bytes_to_tx/2);
          packet_number ++;
        }
      }//while != NRF_ERROR_RESOURCES

    }//if (requested_samples &amp;gt; transmitted_samples)

    //if we&amp;#39;re done, let the device know
    else {
        send_application_status(TRANSFER_DONE);
        #ifdef DEBUG
        printf(&amp;quot;Transmission done, sent %d samples in %d packets\r\n&amp;quot;,transmitted_samples, packet_number);
        #endif
        rtc_set(DEFAULT_TIMEOUT);
        requested_samples = 0;
    }

}//transmit_samples&lt;/pre&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Here&amp;#39;s my &amp;quot;send_data&amp;quot;:&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;pre class="ui-code" data-mode="text"&gt;uint32_t ble_ctcws_send_status(uint16_t conn_handle, ble_ctcws_t * p_ctcws, uint8_t * p_data, uint16_t * p_length)
{
    ble_gatts_hvx_params_t params;

    memset(&amp;amp;params, 0, sizeof(params));
    params.type   = BLE_GATT_HVX_NOTIFICATION;
    params.handle = p_ctcws-&amp;gt;status_char_handles.value_handle;
    params.p_data = p_data;
    params.p_len  = p_length;

    return sd_ble_gatts_hvx(conn_handle, &amp;amp;params);
}&lt;/pre&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Client without Notifications bricking device</title><link>https://devzone.nordicsemi.com/thread/250051?ContentTypeID=1</link><pubDate>Thu, 14 May 2020 19:03:05 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ac2f92bd-24af-4ffa-9cca-bab01f09aa99</guid><dc:creator>Daniel Veilleux</dc:creator><description>&lt;p&gt;Hello Adam,&lt;/p&gt;
&lt;p&gt;Do you have &amp;quot;DEBUG&amp;quot; in the preprocessor symbols for your project? I suspect that your project is calling sd_ble_gatts_hvx and then asserting when it receives the NRF_ERROR_INVALID_STATE error code. If DEBUG was defined then this can put you into an infinite loop at the bottom of the default app_error_fault_handler, with all of your application&amp;#39;s interrupts disabled. If you remove the DEBUG symbol then the assert handler will initiate a system reset instead.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Client without Notifications bricking device</title><link>https://devzone.nordicsemi.com/thread/250049?ContentTypeID=1</link><pubDate>Thu, 14 May 2020 18:22:36 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b381ea43-aa5c-44c6-a780-edf892d713b1</guid><dc:creator>Adam Gerken</dc:creator><description>[quote userid="26071" url="~/f/nordic-q-a/61011/client-without-notifications-bricking-device/249829"]Perhaps this is because the ble_nus_data_send() returns != 0?[/quote]
&lt;p&gt;I&amp;#39;m not using nus, it&amp;#39;s a custom service but is probably similar. I&amp;#39;m only processing two error codes right now, NRF_SUCCESS and NRF_ERROR_RESOURCES. If the &amp;quot;send_data&amp;quot; service returns success, I compile another packet and send it to the SD until I get an NRF_ERROR_RESOURCES, then I wait for the&amp;nbsp;BLE_GATTS_EVT_HVN_TX_COMPLETE event, and do the whole process again.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;I just tried looking for other error codes and quitting the transmission if &amp;quot;send_data&amp;quot; returns something other than SUCCESS or ERROR_RESOURCES but it still hangs up before I can even look at what the code is.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
[quote userid="26071" url="~/f/nordic-q-a/61011/client-without-notifications-bricking-device/249829"]&lt;div class="quote-user"&gt;&lt;/div&gt;&lt;div class="quote-content"&gt;Are you able to see from your application when the notification is enabled?&lt;/div&gt;[/quote]
&lt;p&gt;No. This is the whole point of this whole thread. I don&amp;#39;t know how to do this. This is exactly what I want to do.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Client without Notifications bricking device</title><link>https://devzone.nordicsemi.com/thread/249829?ContentTypeID=1</link><pubDate>Thu, 14 May 2020 06:34:01 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:36fc0162-907d-4988-b19a-3a28e7513b79</guid><dc:creator>Edvin</dc:creator><description>&lt;p&gt;I think you are rushing ahead:&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
[quote user="Adam Gerken"]When my application sends data to a client that doesn&amp;#39;t have notifications enabled, the program hangs up and no interrupts work any more.[/quote]
&lt;p&gt;&amp;nbsp;Perhaps this is because the ble_nus_data_send() returns != 0?&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
[quote user="Edvin Holmseth"]Are you able to see from your application when the notification is enabled?[/quote]&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Client without Notifications bricking device</title><link>https://devzone.nordicsemi.com/thread/249764?ContentTypeID=1</link><pubDate>Wed, 13 May 2020 13:58:48 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:24046e84-88e2-4f68-86da-c01afe88949c</guid><dc:creator>Adam Gerken</dc:creator><description>&lt;p&gt;Yes, I&amp;#39;m talking about interrupts. When my application sends data to a client that doesn&amp;#39;t have notifications enabled, the program hangs up and no interrupts work any more. I&amp;#39;m trying to use a timer to reset the connection and go back to advertising when this happens, but it doesn&amp;#39;t work because interrupts don&amp;#39;t work. No interrupts work when this happens.... My SPI hangs up, Timer hangs up, RTC hangs up, everything.&lt;/p&gt;
&lt;p&gt;No, I can not see in my application when notifications are enabled. That&amp;#39;s exactly what I said I can&amp;#39;t get to work.&lt;/p&gt;
&lt;p&gt;How does a timer help me check for an event when notifications are enabled? I&amp;#39;m not following you at all here, I think we&amp;#39;re talking about very different things. Are you suggesting using a timer to poll the notification status? I asked a while ago if I can just check the status of notifications, because then I can just do that before trying to transmit on that characteristic, and just not transmit if notifications aren&amp;#39;t enabled. That would be the ideal situation, but I thought you said you can&amp;#39;t query the notification status.&lt;/p&gt;
&lt;p&gt;The basic flow of the program:&lt;/p&gt;
&lt;p&gt;Server = Nordic device, Client = PC&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Server advertises&lt;/li&gt;
&lt;li&gt;Client connects&lt;/li&gt;
&lt;li&gt;Client requests x number of data samples&lt;/li&gt;
&lt;li&gt;Server collects samples&lt;/li&gt;
&lt;li&gt;Server transmits samples&amp;nbsp;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;It&amp;#39;s the last step that&amp;#39;s getting hung up if the client doesn&amp;#39;t have notifications enabled. The Server needs to transmit a large amount of data but just locks up.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Client without Notifications bricking device</title><link>https://devzone.nordicsemi.com/thread/249609?ContentTypeID=1</link><pubDate>Wed, 13 May 2020 07:42:40 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:693454d3-4c12-4df5-9ed7-15731467253c</guid><dc:creator>Edvin</dc:creator><description>[quote user="Adam Gerken"]I set my RTC interrupt to 0 to try and over ride whatever the SD is doing. I&amp;#39;m totally lost now... I get that some SD events are priority 0, but I don&amp;#39;t know how/why writing to a characteristic that doesn&amp;#39;t have notifications set on the other side would trigger a priority 0 interrupt.[/quote]
&lt;p&gt;&amp;nbsp;Are you talking about the interrupt priorities now? If so, don&amp;#39;t change them. It shouldn&amp;#39;t be needed in this case. Setting the RTC interrupt IRQ priority to 0 will damage the softdevice functionality.&lt;/p&gt;
&lt;p&gt;Set the RTC priority back to 6.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Are you able to see from your application when the notification is enabled? If yes, I suggest you look into using the app_timer as your timer to check whether notifications are enabled. Check out the ble_app_hrs example, which uses an app_timer to generate simulated battery measurements.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Edvin&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Client without Notifications bricking device</title><link>https://devzone.nordicsemi.com/thread/249563?ContentTypeID=1</link><pubDate>Tue, 12 May 2020 17:40:53 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a40904e7-4e11-4e63-bac1-120c05b4ab3d</guid><dc:creator>Adam Gerken</dc:creator><description>&lt;p&gt;So I can&amp;#39;t get that to work, no other coder here, just me. I&amp;#39;m a pretty competent C coder but this SDK is so hard to follow (very common complaint around the internet.) I was going to implement a time out, since that&amp;#39;s pretty easy... if the program gets stuck, force a timeout and go back to advertising. However, when I hit this snag it seems to be disabling all other interrupts. My SPIM gets hung up waiting for an event end interrupt, and my RTC interrupt to reset everything doesn&amp;#39;t trigger.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;I set my RTC interrupt to 0 to try and over ride whatever the SD is doing. I&amp;#39;m totally lost now... I get that some SD events are priority 0, but I don&amp;#39;t know how/why writing to a characteristic that doesn&amp;#39;t have notifications set on the other side would trigger a priority 0 interrupt.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Any thoughts? I&amp;#39;m beating my head against the wall here.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Client without Notifications bricking device</title><link>https://devzone.nordicsemi.com/thread/248712?ContentTypeID=1</link><pubDate>Thu, 07 May 2020 12:40:51 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6b37f954-287b-4411-834f-2d6f46f4b54a</guid><dc:creator>Edvin</dc:creator><description>&lt;p&gt;Do you have anyone with more software experience that can have a look?&lt;/p&gt;
&lt;p&gt;If you look at the ble_app_uart example, in the same event handler:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;    if ((p_evt_write-&amp;gt;handle == p_nus-&amp;gt;tx_handles.cccd_handle) &amp;amp;&amp;amp;
        (p_evt_write-&amp;gt;len == 2))
    {
        if (p_client != NULL)
        {
            if (ble_srv_is_notification_enabled(p_evt_write-&amp;gt;data))
            {
                p_client-&amp;gt;is_notification_enabled = true;
                evt.type                          = BLE_NUS_EVT_COMM_STARTED;
            }
            else
            {
                p_client-&amp;gt;is_notification_enabled = false;
                evt.type                          = BLE_NUS_EVT_COMM_STOPPED;
            }

            if (p_nus-&amp;gt;data_handler != NULL)
            {
                p_nus-&amp;gt;data_handler(&amp;amp;evt);
            }

        }&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;The line:&lt;/p&gt;
&lt;p&gt;evt.type&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; = BLE_NUS_EVT_COMM_STARTED;&lt;/p&gt;
&lt;p&gt;and&amp;nbsp;&lt;/p&gt;
&lt;p&gt;p_nus-&amp;gt;data_handler(&amp;amp;evt); You don&amp;#39;t see this event in the event handler in main.c, but that is only because it is not checked.&lt;/p&gt;
&lt;p&gt;If you add this event in the nus_data_handler() event handler in main.c you can see it:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;static void nus_data_handler(ble_nus_evt_t * p_evt)
{

    if (p_evt-&amp;gt;type == BLE_NUS_EVT_RX_DATA)
    {
        uint32_t err_code;

        NRF_LOG_DEBUG(&amp;quot;Received data from BLE NUS. Writing data on UART.&amp;quot;);
        NRF_LOG_HEXDUMP_DEBUG(p_evt-&amp;gt;params.rx_data.p_data, p_evt-&amp;gt;params.rx_data.length);

        for (uint32_t i = 0; i &amp;lt; p_evt-&amp;gt;params.rx_data.length; i++)
        {
            do
            {
                err_code = app_uart_put(p_evt-&amp;gt;params.rx_data.p_data[i]);
                if ((err_code != NRF_SUCCESS) &amp;amp;&amp;amp; (err_code != NRF_ERROR_BUSY))
                {
                    NRF_LOG_ERROR(&amp;quot;Failed receiving NUS message. Error 0x%x. &amp;quot;, err_code);
                    APP_ERROR_CHECK(err_code);
                }
            } while (err_code == NRF_ERROR_BUSY);
        }
        if (p_evt-&amp;gt;params.rx_data.p_data[p_evt-&amp;gt;params.rx_data.length - 1] == &amp;#39;\r&amp;#39;)
        {
            while (app_uart_put(&amp;#39;\n&amp;#39;) == NRF_ERROR_BUSY);
        }
    }
    else if (p_evt-&amp;gt;type == BLE_NUS_EVT_COMM_STARTED)
    {
        NRF_LOG_INFO(&amp;quot;notifications started&amp;quot;);
    }

}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;will forward the event to the event handler that is passed on in ble_nus_init(). But in your custom project, I am not sure whether you have implemented this kind of event handler. But it is possible.&lt;/p&gt;
&lt;p&gt;This characteristic (the TX characteristic) is not a write characteristic either, but since it is possible to enable notifications on it, it is possible to write to the CCCD of the characteristic. This will appear as an&amp;nbsp;BLE_GATTS_EVT_WRITE event.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I don&amp;#39;t know anything about how your characteristic is set up. Are notifications supported?&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;If you want a getting started guide, you can check out this github guide:&lt;/p&gt;
&lt;p&gt;&lt;a href="https://github.com/edvinand/custom_ble_service_example"&gt;https://github.com/edvinand/custom_ble_service_example&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;However, I believe that you have already made a working application, so this guide may not suit very well.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;This is at least how you can check whether the notifications are enabled, but how to forward this to main.c, is not Nordic SDK specific, but this is one way to do it in C.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Edvin&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Client without Notifications bricking device</title><link>https://devzone.nordicsemi.com/thread/248555?ContentTypeID=1</link><pubDate>Wed, 06 May 2020 19:42:20 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8d999ac8-df2e-482f-81c6-5f5abcd48dc0</guid><dc:creator>Adam Gerken</dc:creator><description>&lt;p&gt;Alright, I&amp;#39;m totally lost... this sdk is so hard to follow for hardware guy like me.&lt;/p&gt;
&lt;p&gt;Right now my &amp;quot;on_write&amp;quot; function is:&lt;pre class="ui-code" data-mode="text"&gt;static void on_write(ble_ctcws_t * p_ctcws, ble_evt_t const * p_ble_evt)
{
    ble_gatts_evt_write_t const * p_evt_write = &amp;amp;p_ble_evt-&amp;gt;evt.gatts_evt.params.write;

    //take care of a write to config
    if (p_evt_write-&amp;gt;handle == p_ctcws-&amp;gt;config_char_handles.value_handle)
    {
        p_ctcws-&amp;gt;config_write_handler(p_ctcws, p_evt_write-&amp;gt;data, p_evt_write-&amp;gt;len);
    }

    //take care of a write to samples
    else if (p_evt_write-&amp;gt;handle == p_ctcws-&amp;gt;samples_char_handles.value_handle)
    {
        p_ctcws-&amp;gt;samples_write_handler(p_ctcws, p_evt_write-&amp;gt;data, p_evt_write-&amp;gt;len);
    }

    //take care of a write to status
    else if (p_evt_write-&amp;gt;handle == p_ctcws-&amp;gt;status_char_handles.value_handle)
    {
        p_ctcws-&amp;gt;status_write_handler(p_ctcws, p_evt_write-&amp;gt;data, p_evt_write-&amp;gt;len);
    }
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;One of those (status) is one that I need to check notifications on, would I just add the cccd stuff like so (line 22+):&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;static void on_write(ble_ctcws_t * p_ctcws, ble_evt_t const * p_ble_evt)
{
    ble_gatts_evt_write_t const * p_evt_write = &amp;amp;p_ble_evt-&amp;gt;evt.gatts_evt.params.write;

    //take care of a write to config
    if (p_evt_write-&amp;gt;handle == p_ctcws-&amp;gt;config_char_handles.value_handle)
    {
        p_ctcws-&amp;gt;config_write_handler(p_ctcws, p_evt_write-&amp;gt;data, p_evt_write-&amp;gt;len);
    }

    //take care of a write to samples
    else if (p_evt_write-&amp;gt;handle == p_ctcws-&amp;gt;samples_char_handles.value_handle)
    {
        p_ctcws-&amp;gt;samples_write_handler(p_ctcws, p_evt_write-&amp;gt;data, p_evt_write-&amp;gt;len);
    }

    //take care of a write to status
    else if (p_evt_write-&amp;gt;handle == p_ctcws-&amp;gt;status_char_handles.value_handle)
    {
        p_ctcws-&amp;gt;status_write_handler(p_ctcws, p_evt_write-&amp;gt;data, p_evt_write-&amp;gt;len);

        if ((p_evt_write-&amp;gt;handle == p_ctcws-&amp;gt;status_char_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)){
            //notifications are on
            }
            else{
            //notifications are off
            }
        }
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;The other characteristic doesn&amp;#39;t have a write event because it&amp;#39;s data is transmit only, I would just create a new write handle and all that for that one then implement similar to the status one above?&lt;/p&gt;
&lt;p&gt;Also, how does this status get back to the main program?.. this service thing is the one part of the code I never really got my head around... it all just looks like an enormous web of data structures and things I can&amp;#39;t follow.&lt;/p&gt;
&lt;p&gt;Also, just thinking out loud, what happens if the notifications are on by default, will this ever get called? Is there a way I can just check notification status in my main.c? That would be way easier, if I could just check before sending a packet.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Client without Notifications bricking device</title><link>https://devzone.nordicsemi.com/thread/248460?ContentTypeID=1</link><pubDate>Wed, 06 May 2020 12:42:38 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e0962655-7b5f-4f20-89ba-fc75c3271690</guid><dc:creator>Edvin</dc:creator><description>&lt;p&gt;Looking at the ble_app_uart example, the&amp;nbsp;BLE_GATTS_EVT_WRITE event in ble_nus.c is triggered whenever someone write something to a characteristic, including the CCCD (for enabling notifications). In SDK16, it looks like this:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;static void on_write(ble_nus_t * p_nus, ble_evt_t const * p_ble_evt)
{
    ret_code_t                    err_code;
    ble_nus_evt_t                 evt;
    ble_nus_client_context_t    * p_client;
    ble_gatts_evt_write_t const * p_evt_write = &amp;amp;p_ble_evt-&amp;gt;evt.gatts_evt.params.write;

    err_code = blcm_link_ctx_get(p_nus-&amp;gt;p_link_ctx_storage,
                                 p_ble_evt-&amp;gt;evt.gatts_evt.conn_handle,
                                 (void *) &amp;amp;p_client);
    if (err_code != NRF_SUCCESS)
    {
        NRF_LOG_ERROR(&amp;quot;Link context for 0x%02X connection handle could not be fetched.&amp;quot;,
                      p_ble_evt-&amp;gt;evt.gatts_evt.conn_handle);
    }

    memset(&amp;amp;evt, 0, sizeof(ble_nus_evt_t));
    evt.p_nus       = p_nus;
    evt.conn_handle = p_ble_evt-&amp;gt;evt.gatts_evt.conn_handle;
    evt.p_link_ctx  = p_client;

    if ((p_evt_write-&amp;gt;handle == p_nus-&amp;gt;tx_handles.cccd_handle) &amp;amp;&amp;amp;
        (p_evt_write-&amp;gt;len == 2))
    {
    ...&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;The last if-check in this snippet checks whether this event is caused by a notification change. If the value is 0x0001 then notifications are enabled.&lt;/p&gt;
&lt;p&gt;You can do this with a central that enables notifications to see what it looks like.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Client without Notifications bricking device</title><link>https://devzone.nordicsemi.com/thread/248262?ContentTypeID=1</link><pubDate>Tue, 05 May 2020 15:06:48 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e943a83e-adfc-41a0-91fb-7ed33786c112</guid><dc:creator>Adam Gerken</dc:creator><description>&lt;p&gt;Seems like a reasonable idea. How would I see if the connected device enables notifications? I could also just check when the client requests that I send data (part of our application) and just deny the request if they don&amp;#39;t have notifications enabled.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Client without Notifications bricking device</title><link>https://devzone.nordicsemi.com/thread/248258?ContentTypeID=1</link><pubDate>Tue, 05 May 2020 15:02:40 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:801378bd-9853-459c-9d86-3fb0090a717c</guid><dc:creator>Edvin</dc:creator><description>&lt;p&gt;Oh, I see. Well. There is no event for something that never occurs in this case, unfortunately. Since it isn&amp;#39;t mandatory to enable notifications, there will be no timeout from the SoftDevice.&lt;/p&gt;
&lt;p&gt;I suggest that you try to add an app_timer to the device that you start in the connected event. If the connected device enables notifications on this characteristic, stop the timer, but if the timer times out, you would disconnect from the connected device, and it should start advertising again.&lt;/p&gt;
&lt;p&gt;Does that seem like a viable solution?&lt;/p&gt;
&lt;p&gt;BR,&lt;/p&gt;
&lt;p&gt;Edvin&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Client without Notifications bricking device</title><link>https://devzone.nordicsemi.com/thread/248217?ContentTypeID=1</link><pubDate>Tue, 05 May 2020 13:57:40 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5baf2955-95c5-437c-9e99-3cdf025bc2d6</guid><dc:creator>Adam Gerken</dc:creator><description>&lt;p&gt;This is a production device that a customer is having this issue with when trying to integrate into their software ecosystem, no debug available. Like I said, there&amp;#39;s no hardware reset, and the device disappears.&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&amp;quot;My suspicion is that the device is trying to send a notification, but this isn&amp;#39;t possible since it isn&amp;#39;t enabled by the central(client).&amp;quot;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Yes, exactly what&amp;#39;s happening.&amp;nbsp;I need to detect when this happens, and instead of sitting there waiting forever, I need to disconnect and advertise. I just can&amp;#39;t find the notification that says the client hasn&amp;#39;t responded or whatever to trigger the disconnect and advertise.&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Client without Notifications bricking device</title><link>https://devzone.nordicsemi.com/thread/248208?ContentTypeID=1</link><pubDate>Tue, 05 May 2020 13:45:09 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f9758eea-70de-48ed-8be0-ea3204943652</guid><dc:creator>Edvin</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;What do you mean by &amp;quot;bricking device&amp;quot;?&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
[quote user=""]This causes the unit to seemingly&amp;nbsp; wait indefinitely waiting to get the thumbs up from the client that it received the packet, which never comes.[/quote]
&lt;p&gt;&amp;nbsp;What device is waiting? Central or peripheral? And is this &amp;quot;thumbs up&amp;quot; supposed to be delivered via a notification, perhaps?&lt;/p&gt;
&lt;p&gt;Have you/they tried to debug the &amp;quot;bricked device&amp;quot; while this is happening? Does the log say anything?&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;My suspicion is that the device is trying to send a notification, but this isn&amp;#39;t possible since it isn&amp;#39;t enabled by the central(client). But you/they would need to debug to see why the thumbs up is not working. Remember that we don&amp;#39;t know anything about the logic in your application.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Edvin&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>