<?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>Converting BLE_peripheral  UART example to support 4 peripheral connections</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/91718/converting-ble_peripheral-uart-example-to-support-4-peripheral-connections</link><description>Hi All, 
 
 I modified ble_peripheral UART example to support 4 peripheral links instead of one by referring the bel_app_multiperipheral example, I am able to connect four mobiles(central devices) to it and sending (from central devices ) some strings</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Mon, 12 Sep 2022 11:20:51 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/91718/converting-ble_peripheral-uart-example-to-support-4-peripheral-connections" /><item><title>RE: Converting BLE_peripheral  UART example to support 4 peripheral connections</title><link>https://devzone.nordicsemi.com/thread/385703?ContentTypeID=1</link><pubDate>Mon, 12 Sep 2022 11:20:51 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1107764d-c876-4b4e-a9eb-5c9684a3d0e2</guid><dc:creator>A sudheer Kumar</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;changed my function little bit, now it&amp;#39;s working&lt;/p&gt;
&lt;p&gt;void vfnSendSensorResponsOnBle(uint8_t *ptr, uint32_t len)&lt;br /&gt;{&lt;br /&gt;&amp;nbsp; &amp;nbsp; uint8_t uIndex = 0;&lt;br /&gt;&amp;nbsp; &amp;nbsp; uint32_t err_code = 0;&lt;br /&gt;&amp;nbsp; &amp;nbsp; ble_conn_state_conn_handle_list_t conn_handles = ble_conn_state_periph_handles();&lt;br /&gt; &lt;br /&gt;&amp;nbsp; &amp;nbsp; for (uint32_t i = 0; i &amp;lt; conn_handles.len; i++)&lt;br /&gt;&amp;nbsp; &amp;nbsp; {&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;if ((ble_conn_state_valid(conn_handles.conn_handles[i])==true))&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;{&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; NRF_LOG_DEBUG(&amp;quot;Ready to send data over BLE NUS&amp;quot;);&lt;/p&gt;
&lt;p&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;do&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; { &lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; err_code = ble_nus_data_send(&amp;amp;m_nus, ptr, (uint16_t *)&amp;amp;len, conn_handles.conn_handles[i]);&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if ((err_code != NRF_ERROR_INVALID_STATE) &amp;amp;&amp;amp;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (err_code != NRF_ERROR_RESOURCES) &amp;amp;&amp;amp;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (err_code != NRF_ERROR_NOT_FOUND))&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;{&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; APP_ERROR_CHECK(err_code);&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;/p&gt;
&lt;p&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; } while (err_code == NRF_ERROR_RESOURCES);&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; } &lt;br /&gt;&amp;nbsp; &amp;nbsp; } &lt;br /&gt;}&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;and also able to send 253 bytes long string with all the central devices by changing the RAM size.&lt;/p&gt;
&lt;p&gt;thank you every one!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Converting BLE_peripheral  UART example to support 4 peripheral connections</title><link>https://devzone.nordicsemi.com/thread/385698?ContentTypeID=1</link><pubDate>Mon, 12 Sep 2022 11:04:27 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e94cc389-ec75-4d7a-bd42-c503e490deb0</guid><dc:creator>Hieu</dc:creator><description>&lt;p&gt;That&amp;#39;s good to hear.&amp;nbsp;If you don&amp;#39;t mind, please share what the problem is and verify it as the answer, so that future developers can refer from it.&lt;/p&gt;
&lt;p&gt;Sure, you can&amp;nbsp;increase MTU size by updating that exact config.&amp;nbsp;You can refer to the&amp;nbsp;&lt;span&gt;&lt;em&gt;UART/Serial Port Emulation over BLE&lt;/em&gt; (or ble_app_uart) example for a working configuration. You could also&amp;nbsp;discover DevZone for more information on&amp;nbsp;how-to, common issues, and more details.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;If you need further help with that, please open a new ticket, as that would be a different topic from what we are discussing here.&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Converting BLE_peripheral  UART example to support 4 peripheral connections</title><link>https://devzone.nordicsemi.com/thread/385686?ContentTypeID=1</link><pubDate>Mon, 12 Sep 2022 10:43:15 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8817fd13-bd46-42ec-a47e-4630d72031bc</guid><dc:creator>A sudheer Kumar</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;Thanks for reply!&lt;/p&gt;
&lt;p&gt;I am able to share strings up to four central devices , but I am facing challenge with string size.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Unable to send more than 20 characters because of NRF_SDH_BLE_GATT_MAX_MTU_SIZE 23, is there any other option to send up to 128 or 256 characters long Over BLE&amp;nbsp;&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Converting BLE_peripheral  UART example to support 4 peripheral connections</title><link>https://devzone.nordicsemi.com/thread/385670?ContentTypeID=1</link><pubDate>Mon, 12 Sep 2022 09:43:28 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4a231f21-eae3-4544-94cb-4ddf05936c2c</guid><dc:creator>Hieu</dc:creator><description>&lt;p&gt;Hi there, I am&amp;nbsp;taking over from Susheel as he is not available. I checked your information and assume that you are working with a nRF5 SDK version where ble_nus.c supports this function:&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;ble_nus_data_send(ble_nus_t * p_nus, uint8_t * p_data, uint16_t * p_length, uint16_t conn_handle)&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;That is because that with such versions, the ble_nus module should support multiple connections out of the box (unlike earlier versions where you do need to modify it).&lt;/p&gt;
&lt;p&gt;And your code seems to be correct. I have also&amp;nbsp;successfully sent text to two central devices using a&amp;nbsp;very similar implementation I will post below.&lt;/p&gt;
&lt;p&gt;While implementing that from a fresh example, I also notice that, depends on implementation, UART lib, NUS and multiple link support can eat up a lot of memory. Your description of &amp;quot;&lt;span&gt;peripheral device getting restarted&amp;quot; is a symptom that the device might have run out of RAM. Or it could be that some pointers are not being handled correctly.&amp;nbsp;Please also check if you are building with &amp;quot;Release&amp;quot; configuration. In default &amp;quot;Release&amp;quot; build config, the device would just reset at any failed APP_ERROR_CHECK.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;Could you&amp;nbsp;please configure log level to DEBUG in sdk_config.h and debug some more with RTT logs?&amp;nbsp;You might want to try both Debug and Release build configurations to see how it changes things.&lt;/p&gt;
&lt;p&gt;If&amp;nbsp;you need support with that, please produce a clean log of&amp;nbsp;the peripheral application, in Debug build configuration, failing and restarting and reply here.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Finally, this is my current implementation which successfully sends to two centrals:&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;void dummy_nus_send(void)
{
    uint32_t       err_code;
    static uint8_t data_array[] = &amp;quot;dummy\r\n&amp;quot;;
    for (uint32_t i = 0; i &amp;lt; NRF_SDH_BLE_PERIPHERAL_LINK_COUNT; i++)
    {
        if (m_qwr[i].conn_handle != BLE_CONN_HANDLE_INVALID)
        {
            NRF_LOG_DEBUG(&amp;quot;Ready to send data over BLE NUS Conn %d of %d, handle %x&amp;quot;, i, NRF_SDH_BLE_PERIPHERAL_LINK_COUNT, m_qwr[i].conn_handle);
            do
            {
                uint16_t length = (uint16_t) sizeof(data_array);
                err_code = ble_nus_data_send(&amp;amp;m_nus, data_array, &amp;amp;length, m_qwr[i].conn_handle);
                if ((err_code != NRF_ERROR_INVALID_STATE) &amp;amp;&amp;amp;
                    (err_code != NRF_ERROR_RESOURCES) &amp;amp;&amp;amp;
                    (err_code != NRF_ERROR_NOT_FOUND))
                {
                    APP_ERROR_CHECK(err_code);
                }
            } while (err_code == NRF_ERROR_RESOURCES);
            
        }
    }
}&lt;/pre&gt;&lt;code&gt;&lt;span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Converting BLE_peripheral  UART example to support 4 peripheral connections</title><link>https://devzone.nordicsemi.com/thread/385625?ContentTypeID=1</link><pubDate>Mon, 12 Sep 2022 05:23:23 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0f48e778-dfaf-460f-9580-db09a342c62b</guid><dc:creator>A sudheer Kumar</dc:creator><description>&lt;p&gt;Is there any one to help me out&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Converting BLE_peripheral  UART example to support 4 peripheral connections</title><link>https://devzone.nordicsemi.com/thread/385185?ContentTypeID=1</link><pubDate>Thu, 08 Sep 2022 08:13:58 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2349d69f-e361-4f3a-9a43-8c9a22545b21</guid><dc:creator>A sudheer Kumar</dc:creator><description>&lt;p&gt;thanks for your reply&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Converting BLE_peripheral  UART example to support 4 peripheral connections</title><link>https://devzone.nordicsemi.com/thread/385181?ContentTypeID=1</link><pubDate>Thu, 08 Sep 2022 08:07:11 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:14fffe52-b6e0-47f0-9503-70ab26ca493b</guid><dc:creator>Susheel Nuguru</dc:creator><description>&lt;p&gt;I might have done this as a hobby project few years back but unfortunately I cannot find traces of it.&lt;/p&gt;
&lt;p&gt;It is definitely possible to modify the example and ble_nus module to handle multiple connections with central, and could be done in a week effort. But unfortunately, I cannot help with the code, sorry.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Converting BLE_peripheral  UART example to support 4 peripheral connections</title><link>https://devzone.nordicsemi.com/thread/385150?ContentTypeID=1</link><pubDate>Thu, 08 Sep 2022 05:22:01 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:920e636d-ee50-4c3c-abf7-ca1ec32645ae</guid><dc:creator>A sudheer Kumar</dc:creator><description>&lt;p&gt;thanks for the example,&lt;/p&gt;
&lt;p&gt;Actually I am looking for NUS peripheral that can support multiple centrals&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Converting BLE_peripheral  UART example to support 4 peripheral connections</title><link>https://devzone.nordicsemi.com/thread/385148?ContentTypeID=1</link><pubDate>Thu, 08 Sep 2022 05:13:00 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5494b0cf-3b12-4897-b171-cf6f8b425851</guid><dc:creator>Susheel Nuguru</dc:creator><description>&lt;p&gt;If you are looking for a NUS central that can support multiple peripherals, you can try to look at this &lt;a href="https://github.com/NordicPlayground/nrf52-ble-app-uart-c-multilink"&gt;github&lt;/a&gt;&amp;nbsp;project.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Converting BLE_peripheral  UART example to support 4 peripheral connections</title><link>https://devzone.nordicsemi.com/thread/385146?ContentTypeID=1</link><pubDate>Thu, 08 Sep 2022 04:34:59 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7f453263-db4c-49cb-aaad-5d3db4fb59fc</guid><dc:creator>A sudheer Kumar</dc:creator><description>&lt;p&gt;Hi Susheel,&lt;/p&gt;
&lt;p&gt;Thanks for your reply,&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I searched in Devzone, but didn&amp;#39;t get any related links regarding my issue. If you have any, please share us.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&amp;nbsp;You need to make changes to the Nordic UART service data structures to handle multi instance connections. At the moment, it is a single connection only module (out of the box)&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&amp;nbsp;&lt;/strong&gt;what are the changes need do, which example will help me to solve this issue&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Regards,&lt;/p&gt;
&lt;p&gt;Sudheer&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Converting BLE_peripheral  UART example to support 4 peripheral connections</title><link>https://devzone.nordicsemi.com/thread/385086?ContentTypeID=1</link><pubDate>Wed, 07 Sep 2022 15:41:20 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9124f4f7-f406-4b74-aa1d-d9fd3a3af31a</guid><dc:creator>Susheel Nuguru</dc:creator><description>&lt;p&gt;I believe there was some requests similar to this before in devzone. Have you tried to search for them here?&lt;/p&gt;
&lt;p&gt;In the nutshell, it is possible, but need some changes to the ble_nus module. You need to make changes to the Nordic UART service data structures to handle multi instance connections. At the moment, it is a single connection only module (out of the box)&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>