<?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>How does the peripherals reconnect to central board when the BLE connection lost</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/80143/how-does-the-peripherals-reconnect-to-central-board-when-the-ble-connection-lost</link><description>Hello everyone, I am developing a system with multiple peripherals to a central board. How many peripherals can keep connecting with central at one time? I made some peripherals connected to a central board but after several hours, the connection of some</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 07 Oct 2021 08:49:49 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/80143/how-does-the-peripherals-reconnect-to-central-board-when-the-ble-connection-lost" /><item><title>RE: How does the peripherals reconnect to central board when the BLE connection lost</title><link>https://devzone.nordicsemi.com/thread/332955?ContentTypeID=1</link><pubDate>Thu, 07 Oct 2021 08:49:49 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1fb24aaa-2a0f-41ec-9c73-341dd56194c9</guid><dc:creator>Jared</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;It depends on the number of peripherals that are going to be connected to the central. Did you try the multi-link central example that I linked in a previous reply?&lt;/p&gt;
[quote user="laumung"]For the second question, when to reconnection to the BLE network, after the connection is timeout? Thanks.[/quote]
&lt;p&gt;You can restart it after a disconnection event in the ble event handler&lt;/p&gt;
&lt;p&gt;best regards&lt;/p&gt;
&lt;p&gt;Jared&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How does the peripherals reconnect to central board when the BLE connection lost</title><link>https://devzone.nordicsemi.com/thread/332708?ContentTypeID=1</link><pubDate>Tue, 05 Oct 2021 20:35:02 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2fcb37ff-069b-45b5-a880-bc23839968cb</guid><dc:creator>laumung</dc:creator><description>&lt;p&gt;Hi Jared, the peripherals in my project send data at a 20ms interval. The data should be sent to central during the connection interval. Here is the detailed code below.&lt;/p&gt;
&lt;p&gt;For peripherals:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;#define SAADC_SAMPLE_RATE               20                                         /**&amp;lt; SAADC sample rate in ms. */     

// BLE connection parameter.
#define APP_BLE_OBSERVER_PRIO           3                                           /**&amp;lt; Application&amp;#39;s BLE observer priority. You shouldn&amp;#39;t need to modify this value. */

#define APP_ADV_INTERVAL                64  //3000  //64                                  /**&amp;lt; The advertising interval (in units of 0.625 ms. This value corresponds to 40 ms). */

#define APP_ADV_DURATION                18000                                       /**&amp;lt; The advertising duration (180 seconds) in units of 10 milliseconds. */

#define MIN_CONN_INTERVAL               MSEC_TO_UNITS(20, UNIT_1_25_MS)             //10 /**&amp;lt; Minimum acceptable connection interval (20 ms), Connection interval uses 1.25 ms units. */ // VersionINote1: Purpose: change MIN_CONN_INTERVAL to 10ms and MAX_CONN_INTERVAL to 250. change the timing of the BLE transmission.
#define MAX_CONN_INTERVAL               MSEC_TO_UNITS(75, UNIT_1_25_MS)            //1900  /**&amp;lt; Maximum acceptable connection interval (75 ms), Connection interval uses 1.25 ms units. */
#define SLAVE_LATENCY                   0                                           /**&amp;lt; Slave latency. */
#define CONN_SUP_TIMEOUT                MSEC_TO_UNITS(20000, UNIT_10_MS)             /**&amp;lt; Connection supervisory timeout (4 seconds), Supervision Timeout uses 10 ms units. */
#define FIRST_CONN_PARAMS_UPDATE_DELAY  APP_TIMER_TICKS(5000)                       /**&amp;lt; Time from initiating event (connect or start of notification) to first time sd_ble_gap_conn_param_update is called (5 seconds). */
#define NEXT_CONN_PARAMS_UPDATE_DELAY   APP_TIMER_TICKS(30000)                      /**&amp;lt; Time between each call to sd_ble_gap_conn_param_update after the first call (30 seconds). */
#define MAX_CONN_PARAMS_UPDATE_COUNT    16   //3                                           /**&amp;lt; Number of attempts before giving up the connection parameter negotiation. */

// Initialize saadc
void saadc_init(void)
{
    ret_code_t err_code;
	
    nrf_drv_saadc_config_t saadc_config = NRF_DRV_SAADC_DEFAULT_CONFIG;
    saadc_config.resolution = NRF_SAADC_RESOLUTION_12BIT;
	
    nrf_saadc_channel_config_t channel_0_config =
        NRF_DRV_SAADC_DEFAULT_CHANNEL_CONFIG_SE(NRF_SAADC_INPUT_AIN4);
    channel_0_config.gain = NRF_SAADC_GAIN1_4;
    channel_0_config.reference = NRF_SAADC_REFERENCE_VDD4;
	
    nrf_saadc_channel_config_t channel_1_config =
        NRF_DRV_SAADC_DEFAULT_CHANNEL_CONFIG_SE(NRF_SAADC_INPUT_AIN5);
    channel_1_config.gain = NRF_SAADC_GAIN1_4;
    channel_1_config.reference = NRF_SAADC_REFERENCE_VDD4;
	
    nrf_saadc_channel_config_t channel_2_config =
        NRF_DRV_SAADC_DEFAULT_CHANNEL_CONFIG_SE(NRF_SAADC_INPUT_AIN6);
    channel_2_config.gain = NRF_SAADC_GAIN1_4;
    channel_2_config.reference = NRF_SAADC_REFERENCE_VDD4;
	
    nrf_saadc_channel_config_t channel_3_config =
        NRF_DRV_SAADC_DEFAULT_CHANNEL_CONFIG_SE(NRF_SAADC_INPUT_AIN7);
    channel_3_config.gain = NRF_SAADC_GAIN1_4;
    channel_3_config.reference = NRF_SAADC_REFERENCE_VDD4;				
	
    err_code = nrf_drv_saadc_init(&amp;amp;saadc_config, saadc_callback);
    APP_ERROR_CHECK(err_code);

    err_code = nrf_drv_saadc_channel_init(0, &amp;amp;channel_0_config);
    APP_ERROR_CHECK(err_code);
    err_code = nrf_drv_saadc_channel_init(1, &amp;amp;channel_1_config);
    APP_ERROR_CHECK(err_code);
    err_code = nrf_drv_saadc_channel_init(2, &amp;amp;channel_2_config);
    APP_ERROR_CHECK(err_code);
    err_code = nrf_drv_saadc_channel_init(3, &amp;amp;channel_3_config);
    APP_ERROR_CHECK(err_code);	

    err_code = nrf_drv_saadc_buffer_convert(m_buffer_pool[0],SAADC_SAMPLES_IN_BUFFER);
    APP_ERROR_CHECK(err_code);   
    err_code = nrf_drv_saadc_buffer_convert(m_buffer_pool[1],SAADC_SAMPLES_IN_BUFFER);
    APP_ERROR_CHECK(err_code);
}

// Transmit data in SAADC function

void saadc_callback(nrf_drv_saadc_evt_t const * p_event)
{
    if (p_event-&amp;gt;type == NRF_DRV_SAADC_EVT_DONE)
    {
        ret_code_t err_code;
        uint16_t adc_value;
        uint8_t value[SAADC_SAMPLES_IN_BUFFER*2];
        uint16_t bytes_to_send;
     
        // set buffers
        err_code = nrf_drv_saadc_buffer_convert(p_event-&amp;gt;data.done.p_buffer, SAADC_SAMPLES_IN_BUFFER);
        APP_ERROR_CHECK(err_code);
        err_code = ble_nus_data_send(&amp;amp;m_nus, d_tx_buf_1, &amp;amp;nus_length, m_conn_handle);       // VersionFNote1: Purpose: decrease the transfer array by 2. Remove the checking sum.
        if ((err_code != NRF_ERROR_INVALID_STATE) &amp;amp;&amp;amp; (err_code != NRF_ERROR_NOT_FOUND))
        {
            APP_ERROR_CHECK(err_code);
        }
    }
}

&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;For central:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;//BLE Timing in sdk_config.h

// &amp;lt;o&amp;gt; NRF_BLE_SCAN_SCAN_INTERVAL - Scanning interval. Determines the scan interval in units of 0.625 millisecond. 
#ifndef NRF_BLE_SCAN_SCAN_INTERVAL
#define NRF_BLE_SCAN_SCAN_INTERVAL 400      //160
#endif

// &amp;lt;o&amp;gt; NRF_BLE_SCAN_SCAN_DURATION - Duration of a scanning session in units of 10 ms. Range: 0x0001 - 0xFFFF (10 ms to 10.9225 ms). If set to 0x0000, the scanning continues until it is explicitly disabled. 
#ifndef NRF_BLE_SCAN_SCAN_DURATION
#define NRF_BLE_SCAN_SCAN_DURATION 0
#endif

// &amp;lt;o&amp;gt; NRF_BLE_SCAN_SCAN_WINDOW - Scanning window. Determines the scanning window in units of 0.625 millisecond. 
#ifndef NRF_BLE_SCAN_SCAN_WINDOW
#define NRF_BLE_SCAN_SCAN_WINDOW 200      // 80
#endif

// &amp;lt;o&amp;gt; NRF_BLE_SCAN_MIN_CONNECTION_INTERVAL - Determines minimum connection interval in milliseconds. 
#ifndef NRF_BLE_SCAN_MIN_CONNECTION_INTERVAL
#define NRF_BLE_SCAN_MIN_CONNECTION_INTERVAL 7.5       //7.5
#endif

// &amp;lt;o&amp;gt; NRF_BLE_SCAN_MAX_CONNECTION_INTERVAL - Determines maximum connection interval in milliseconds. 
#ifndef NRF_BLE_SCAN_MAX_CONNECTION_INTERVAL
#define NRF_BLE_SCAN_MAX_CONNECTION_INTERVAL 180      //30
#endif

// &amp;lt;o&amp;gt; NRF_BLE_SCAN_SLAVE_LATENCY - Determines the slave latency in counts of connection events. 
#ifndef NRF_BLE_SCAN_SLAVE_LATENCY
#define NRF_BLE_SCAN_SLAVE_LATENCY 0
#endif

// &amp;lt;o&amp;gt; NRF_BLE_SCAN_SUPERVISION_TIMEOUT - Determines the supervision time-out in units of 10 millisecond. 
#ifndef NRF_BLE_SCAN_SUPERVISION_TIMEOUT
#define NRF_BLE_SCAN_SUPERVISION_TIMEOUT 4000
#endif

void uart_event_handle(app_uart_evt_t * p_event)
{
    static uint8_t data_array[BLE_NUS_MAX_DATA_LEN];
    static uint16_t index = 0;
    uint32_t ret_val;

    switch (p_event-&amp;gt;evt_type)
    {
        /**@snippet [Handling data from UART] */
        case APP_UART_DATA_READY:
            UNUSED_VARIABLE(app_uart_get(&amp;amp;data_array[index]));
            index++;
            /*
            if ((data_array[index - 1] == &amp;#39;\n&amp;#39;) ||
                (data_array[index - 1] == &amp;#39;\r&amp;#39;) ||
                (index &amp;gt;= (m_ble_nus_max_data_len)))
            */
            if (index &amp;gt;= (m_ble_nus_max_data_len))
            
            {
                NRF_LOG_DEBUG(&amp;quot;Ready to send data over BLE NUS&amp;quot;);
                NRF_LOG_HEXDUMP_DEBUG(data_array, index);

                NRF_LOG_INFO(&amp;quot;Ready to send data over BLE NUS&amp;quot;);
                for(int c = 0; c &amp;lt; NRF_SDH_BLE_CENTRAL_LINK_COUNT; c++)
                {
                    do
                    {
                        ret_val = ble_nus_c_string_send(&amp;amp;m_ble_nus_c[c], data_array, index);
                        if ( (ret_val != NRF_ERROR_INVALID_STATE) &amp;amp;&amp;amp; (ret_val != NRF_ERROR_RESOURCES) )
                        {
                            APP_ERROR_CHECK(ret_val);
                        }
                    } while (ret_val == NRF_ERROR_RESOURCES);
                }
                index = 0;
            }
            break;

        /**@snippet [Handling data from UART] */
        case APP_UART_COMMUNICATION_ERROR:
            NRF_LOG_ERROR(&amp;quot;Communication error occurred while handling UART.&amp;quot;);
            APP_ERROR_HANDLER(p_event-&amp;gt;data.error_communication);
            break;

        case APP_UART_FIFO_ERROR:
            NRF_LOG_ERROR(&amp;quot;Error occurred in FIFO module used by UART.&amp;quot;);
            APP_ERROR_HANDLER(p_event-&amp;gt;data.error_code);
            break;

        default:
            break;
    }
}


/**@brief Function for handling characters received by the Nordic UART Service (NUS).
 *
 * @details This function takes a list of characters of length data_len and prints the characters out on UART.
 *          If @ref ECHOBACK_BLE_UART_DATA is set, the data is sent back to sender.
 */
static void ble_nus_chars_received_uart_print(uint8_t * p_data, uint16_t data_len)
{
    for (uint32_t i = 0; i &amp;lt; packet; i++)
    {
        app_uart_put( 0xAA );
        for(uint32_t j = 0; j &amp;lt; 16; j++ )
        {
            app_uart_put(p_data[ i*16 + j ]);
        }
        // nrf_gpio_pin_toggle(13);
    }
}
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Are the parameter of my BLE connection correct?&amp;nbsp;&lt;/p&gt;
&lt;p&gt;For the second question, when to reconnection to the BLE network, after the connection is timeout? Thanks.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How does the peripherals reconnect to central board when the BLE connection lost</title><link>https://devzone.nordicsemi.com/thread/332643?ContentTypeID=1</link><pubDate>Tue, 05 Oct 2021 13:27:56 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e23405d0-d797-43cc-a894-4bc053fe87e5</guid><dc:creator>Jared</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
[quote user="laumung"]&lt;p&gt;But they can&amp;#39;t send data in a stable order like the figure shown in the document because the timer of the peripherals is running independently.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;[/quote]
&lt;p&gt;Either way, they should only send during the connection interval?! Have you made sure that all of the connection have a common factor for their connection interval as explained in the documentation? What connection parameters are you using?&lt;/p&gt;
[quote user="laumung"]When some peripherals did not set up links with the central, they will lose connection with the central.&amp;nbsp;[/quote]
&lt;p&gt;So they stop advertising after a set time? Try restarting the advertising periodically after some time.&lt;/p&gt;
&lt;p&gt;regards&lt;/p&gt;
&lt;p&gt;Jared&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How does the peripherals reconnect to central board when the BLE connection lost</title><link>https://devzone.nordicsemi.com/thread/332435?ContentTypeID=1</link><pubDate>Mon, 04 Oct 2021 18:47:21 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1c236c28-c497-4f5e-bc17-bb96ad482ca8</guid><dc:creator>laumung</dc:creator><description>&lt;p&gt;Hi Jared, thank you for your reply. I checked the post you mentioned. I also checked other sections related to it. My project is about multi peripherals to two central. The firmware of the peripherals is based on ble_app_uart. The peripherals have timers and send data periodically to the central. But they can&amp;#39;t send data in a stable order like the figure shown in the document because the timer of the peripherals is running independently.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;img src="https://devzone.nordicsemi.com/resized-image/__size/320x240/__key/communityserver-discussions-components-files/4/pastedimage1633373164224v1.png" alt=" " /&gt;&lt;/p&gt;
&lt;p&gt;When some peripherals did not set up links with the central, they will lose connection with the central.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;What should I do about that? Thanks.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How does the peripherals reconnect to central board when the BLE connection lost</title><link>https://devzone.nordicsemi.com/thread/332142?ContentTypeID=1</link><pubDate>Fri, 01 Oct 2021 12:10:49 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5fa683eb-dee0-4e02-9e61-18354d6c5a96</guid><dc:creator>Jared</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;How would the peripherals re-connect to the central if they never restart the advertising?&amp;nbsp;&lt;/p&gt;
&lt;p&gt;See &lt;a href="https://infocenter.nordicsemi.com/topic/sds_s140/SDS/s1xx/multilink_scheduling/suggested_intervals_windows_s132.html?cp=4_7_4_0_14_9"&gt;this &lt;/a&gt;section for suggested connection interval and window.&lt;/p&gt;
&lt;p&gt;regards&lt;/p&gt;
&lt;p&gt;Jared&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How does the peripherals reconnect to central board when the BLE connection lost</title><link>https://devzone.nordicsemi.com/thread/331983?ContentTypeID=1</link><pubDate>Thu, 30 Sep 2021 14:51:20 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a607872f-721f-4c9d-bf2f-909e7908486e</guid><dc:creator>laumung</dc:creator><description>&lt;p&gt;Hi Jared, thanks for your information. The peripheral boards will not advertise after disconnection. I use S140 for nRF52840 and NUS (Nordic UART Service ) to transfer the data. I think 20 links will be great. Which function did you implement in the project? How to configure the parameter for the multi-link to the central, such as advertising interval? Thanks.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How does the peripherals reconnect to central board when the BLE connection lost</title><link>https://devzone.nordicsemi.com/thread/331889?ContentTypeID=1</link><pubDate>Thu, 30 Sep 2021 10:48:19 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a88f7764-1e74-45d4-88fb-2c07ccb66098</guid><dc:creator>Jared</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;Are the boards still advertising after the disconnection? The S130 should be able to support up 20 links simultaneously.&lt;/p&gt;
&lt;p&gt;best regards&lt;/p&gt;
&lt;p&gt;Jared&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>