<?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>creating custom service and characteristics with different Base UUID : connecting and discovering</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/75693/creating-custom-service-and-characteristics-with-different-base-uuid-connecting-and-discovering</link><description>Hi, 
 Am using nrf51822 as central, i want to discover and to commuinicate with the service of another ble module (which is RN4871 from microship). 
 My problem here is that this RN4871 advertise a service with a different base UUID for service and for</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 02 Jun 2021 16:09:21 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/75693/creating-custom-service-and-characteristics-with-different-base-uuid-connecting-and-discovering" /><item><title>RE: creating custom service and characteristics with different Base UUID : connecting and discovering</title><link>https://devzone.nordicsemi.com/thread/313190?ContentTypeID=1</link><pubDate>Wed, 02 Jun 2021 16:09:21 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:3f264af0-43e9-4979-9c7b-c122183a40f6</guid><dc:creator>Kenneth</dc:creator><description>&lt;p&gt;The&amp;nbsp;ble_nus_c_on_db_disc_evt() was not designed to&amp;nbsp;handle your UUID configuration no. So you would need to re-write the code to handle your setup, unfortunately I don&amp;#39;t have time to do this for you, but it should be doable if you understand that you need 2 of these if statements:&lt;/p&gt;
&lt;p&gt;if (p_evt-&amp;gt;evt_type == BLE_DB_DISCOVERY_COMPLETE &amp;amp;&amp;amp;&lt;br /&gt; p_evt-&amp;gt;params.discovered_db.srv_uuid.uuid == BLE_UUID_NUS_SERVICE &amp;amp;&amp;amp;&lt;br /&gt; p_evt-&amp;gt;params.discovered_db.srv_uuid.type == p_ble_nus_c-&amp;gt;uuid_type)&lt;/p&gt;
&lt;p&gt;Because even if&amp;nbsp;BLE_UUID_NUS_TX_CHARACTERISTIC and&amp;nbsp;BLE_UUID_NUS_RX_CHARACTERISTIC share the same value, they don&amp;#39;t have the same uuid_type.&lt;/p&gt;
&lt;p&gt;Kenneth&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: creating custom service and characteristics with different Base UUID : connecting and discovering</title><link>https://devzone.nordicsemi.com/thread/313178?ContentTypeID=1</link><pubDate>Wed, 02 Jun 2021 14:57:44 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0224eb01-8e82-47a6-8270-425887672ca6</guid><dc:creator>MokhlesAdalia</dc:creator><description>&lt;p&gt;Hi Mr kenneth,&lt;/p&gt;
&lt;p&gt;i think you didn&amp;#39;t get my question and i wasn&amp;#39;t able to explain.&lt;/p&gt;
&lt;p&gt;my central nrf51 is able to doscover/connect and send messages to the othe BLE device.&lt;/p&gt;
&lt;p&gt;the problem is that i can&amp;#39;t receive messages.&lt;/p&gt;
&lt;p&gt;it is beacuse as mentionned :&lt;/p&gt;
&lt;p&gt;&lt;span&gt;#define BLE_UUID_NUS_SERVICE 0x5343 .&lt;/span&gt;&lt;br /&gt;&lt;span&gt;#define BLE_UUID_NUS_TX_CHARACTERISTIC 0x5343&amp;nbsp;&lt;/span&gt;&lt;br /&gt;&lt;span&gt;#define BLE_UUID_NUS_RX_CHARACTERISTIC 0x5343&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;BLE_UUID_NUS_TX_CHARACTERISTIC&amp;nbsp; and&amp;nbsp;BLE_UUID_NUS_RX_CHARACTERISTIC&amp;nbsp;shares the same value which will make a problem in the function below in ble_nus_c.c ( i made my modification in ble_nus_c.c /&amp;nbsp;ble_nus_c.h).&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;void ble_nus_c_on_db_disc_evt(ble_nus_c_t * p_ble_nus_c, ble_db_discovery_evt_t * p_evt)
{
    ble_nus_c_evt_t nus_c_evt;
    memset(&amp;amp;nus_c_evt,0,sizeof(ble_nus_c_evt_t));

    ble_gatt_db_char_t * p_chars = p_evt-&amp;gt;params.discovered_db.charateristics;

    // Check if the NUS was discovered.
    if (p_evt-&amp;gt;evt_type == BLE_DB_DISCOVERY_COMPLETE &amp;amp;&amp;amp;
        p_evt-&amp;gt;params.discovered_db.srv_uuid.uuid == BLE_UUID_NUS_SERVICE &amp;amp;&amp;amp;
        p_evt-&amp;gt;params.discovered_db.srv_uuid.type == p_ble_nus_c-&amp;gt;uuid_type)
    {

        uint32_t i;

        for (i = 0; i &amp;lt; p_evt-&amp;gt;params.discovered_db.char_count; i++)
        {
            switch (p_chars[i].characteristic.uuid.uuid)
            {
							
							case BLE_UUID_NUS_TX_CHARACTERISTIC:
                    nus_c_evt.handles.nus_tx_handle = p_chars[i].characteristic.handle_value;
                    break;

                case BLE_UUID_NUS_RX_CHARACTERISTIC:
                    nus_c_evt.handles.nus_rx_handle = p_chars[i].characteristic.handle_value;
                    nus_c_evt.handles.nus_rx_cccd_handle = p_chars[i].cccd_handle;
                    break;

                default:
                    break;
							
            }
        }
        if (p_ble_nus_c-&amp;gt;evt_handler != NULL)
        {
            nus_c_evt.conn_handle = p_evt-&amp;gt;conn_handle;
            nus_c_evt.evt_type    = BLE_NUS_C_EVT_DISCOVERY_COMPLETE;
            p_ble_nus_c-&amp;gt;evt_handler(p_ble_nus_c, &amp;amp;nus_c_evt);
        }
    }
}&lt;/pre&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;having the same value (0x5343) will make a problem in this switch case!&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: creating custom service and characteristics with different Base UUID : connecting and discovering</title><link>https://devzone.nordicsemi.com/thread/312979?ContentTypeID=1</link><pubDate>Tue, 01 Jun 2021 20:40:37 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f82ac9e3-b399-4411-86aa-c92361fcd640</guid><dc:creator>Kenneth</dc:creator><description>&lt;p&gt;You are calling&amp;nbsp;sd_ble_uuid_vs_add() several times, but you don&amp;#39;t really store away the unique&amp;nbsp;uart_uuid.type that you will get every time you call &lt;span&gt;sd_ble_uuid_vs_add()&lt;/span&gt;, instead you just overwrite it? That won&amp;#39;t work, you need to buffer in a variable the &lt;span&gt;uart_uuid.type, so you can use it when you later&amp;nbsp;add the&amp;nbsp;characteristic or service you want to create.&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;If you call&amp;nbsp;&lt;span&gt;sd_ble_uuid_vs_add() 3 times, then you will receive 3 unique&amp;nbsp;uart_uuid.type. When later for instance call&amp;nbsp;sd_ble_gatts_service_add(), then make sure to use the uart_uuid.type that returned when you added the&amp;nbsp;sd_ble_uuid_vs_add() for the service.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;Kenneth&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: creating custom service and characteristics with different Base UUID : connecting and discovering</title><link>https://devzone.nordicsemi.com/thread/312674?ContentTypeID=1</link><pubDate>Mon, 31 May 2021 14:03:28 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0390f35f-0520-4401-ba4a-919e6aa75c6b</guid><dc:creator>MokhlesAdalia</dc:creator><description>&lt;p&gt;can someone help please!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: creating custom service and characteristics with different Base UUID : connecting and discovering</title><link>https://devzone.nordicsemi.com/thread/312100?ContentTypeID=1</link><pubDate>Thu, 27 May 2021 12:53:59 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f0675552-29c0-4f92-9385-fb3af4148345</guid><dc:creator>MokhlesAdalia</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;Yeah, all of that was done, i think you didn&amp;#39;t get what i mean exactly,&lt;/p&gt;
&lt;p&gt;in ble_nus_c.c i added that :&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;uint32_t ble_nus_c_init(ble_nus_c_t * p_ble_nus_c, ble_nus_c_init_t * p_ble_nus_c_init)
{
	
    ble_uuid_t    uart_uuid;
    ble_uuid128_t nus_base_uuid = NUS_BASE_UUID;
	
    ble_uuid128_t char1_base_uuid = CHAR1_BASE_UUID;
    ble_uuid128_t char2_base_uuid = CHAR2_BASE_UUID;
	
    VERIFY_PARAM_NOT_NULL(p_ble_nus_c);
    VERIFY_PARAM_NOT_NULL(p_ble_nus_c_init);


    err2 = sd_ble_uuid_vs_add(&amp;amp;char1_base_uuid, &amp;amp;p_ble_nus_c-&amp;gt;uuid_type);
    //VERIFY_SUCCESS(err_code);
		APP_ERROR_CHECK (err2);
		uart_uuid.type = p_ble_nus_c-&amp;gt;uuid_type;
    uart_uuid.uuid = BLE_UUID_NUS_TX_CHARACTERISTIC;

    err3 = sd_ble_uuid_vs_add(&amp;amp;char2_base_uuid, &amp;amp;p_ble_nus_c-&amp;gt;uuid_type);
    //VERIFY_SUCCESS(err3);
		APP_ERROR_CHECK (err3);
		//printf(&amp;quot;error_code = %d\n&amp;quot;,err3);
    uart_uuid.type = p_ble_nus_c-&amp;gt;uuid_type;
    uart_uuid.uuid = BLE_UUID_NUS_RX_CHARACTERISTIC;



		err1 = sd_ble_uuid_vs_add(&amp;amp;nus_base_uuid, &amp;amp;p_ble_nus_c-&amp;gt;uuid_type);
    //VERIFY_SUCCESS(err_code);
		APP_ERROR_CHECK (err1);
		uart_uuid.type = p_ble_nus_c-&amp;gt;uuid_type;
    uart_uuid.uuid = BLE_UUID_NUS_SERVICE;
		
    p_ble_nus_c-&amp;gt;conn_handle           = BLE_CONN_HANDLE_INVALID;
    p_ble_nus_c-&amp;gt;evt_handler           = p_ble_nus_c_init-&amp;gt;evt_handler;
    p_ble_nus_c-&amp;gt;handles.nus_rx_handle = BLE_GATT_HANDLE_INVALID;
    p_ble_nus_c-&amp;gt;handles.nus_tx_handle = BLE_GATT_HANDLE_INVALID;

    return ble_db_discovery_evt_register(&amp;amp;uart_uuid);
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;the problem here will be in this function in ble_nus_c.c:&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;void ble_nus_c_on_db_disc_evt(ble_nus_c_t * p_ble_nus_c, ble_db_discovery_evt_t * p_evt)
{
    ble_nus_c_evt_t nus_c_evt;
    memset(&amp;amp;nus_c_evt,0,sizeof(ble_nus_c_evt_t));

    ble_gatt_db_char_t * p_chars = p_evt-&amp;gt;params.discovered_db.charateristics;

    // Check if the NUS was discovered.
    if (p_evt-&amp;gt;evt_type == BLE_DB_DISCOVERY_COMPLETE &amp;amp;&amp;amp;
        p_evt-&amp;gt;params.discovered_db.srv_uuid.uuid == BLE_UUID_NUS_SERVICE &amp;amp;&amp;amp;
        p_evt-&amp;gt;params.discovered_db.srv_uuid.type == p_ble_nus_c-&amp;gt;uuid_type)
    {

        uint32_t i;

        for (i = 0; i &amp;lt; p_evt-&amp;gt;params.discovered_db.char_count; i++)
        {
            switch (p_chars[i].characteristic.uuid.uuid)
            {
							
							case BLE_UUID_NUS_TX_CHARACTERISTIC:
                    nus_c_evt.handles.nus_tx_handle = p_chars[i].characteristic.handle_value;
                    break;

                case BLE_UUID_NUS_RX_CHARACTERISTIC:
                    nus_c_evt.handles.nus_rx_handle = p_chars[i].characteristic.handle_value;
                    nus_c_evt.handles.nus_rx_cccd_handle = p_chars[i].cccd_handle;
                    break;

                default:
                    break;
							
            }
        }
        if (p_ble_nus_c-&amp;gt;evt_handler != NULL)
        {
            nus_c_evt.conn_handle = p_evt-&amp;gt;conn_handle;
            nus_c_evt.evt_type    = BLE_NUS_C_EVT_DISCOVERY_COMPLETE;
            p_ble_nus_c-&amp;gt;evt_handler(p_ble_nus_c, &amp;amp;nus_c_evt);
        }
    }
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;as&amp;nbsp;BLE_UUID_NUS_RX_CHARACTERISTIC =&amp;nbsp;BLE_UUID_NUS_TX_CHARACTERISTIC = 0x5343&lt;/p&gt;
&lt;p&gt;which will make an error on ble_nus_c_on_db_disc_evt() function.&lt;/p&gt;
&lt;p&gt;Also&amp;nbsp;&lt;span&gt;NRF_SDH_BLE_VS_UUID_COUNT = 3 is well done.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;i won&amp;#39;t be able to send /receive messsages in this case between the central (nrf51) and the periph (RN4871).&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;i hope i clarified what i mean!&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: creating custom service and characteristics with different Base UUID : connecting and discovering</title><link>https://devzone.nordicsemi.com/thread/312091?ContentTypeID=1</link><pubDate>Thu, 27 May 2021 12:39:40 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:3dfb1753-4a73-4568-9c87-87843590954a</guid><dc:creator>Kenneth</dc:creator><description>&lt;p&gt;You will need to add&amp;nbsp;a BASE UUID for each of these. So make sure that NRF_SDH_BLE_VS_UUID_COUNT is set to 3 (or more).&lt;/p&gt;
&lt;p&gt;To add a BASE UUID you will need to call&amp;nbsp;sd_ble_uuid_vs_add() for each BASE UUID you want to add, e.g. something like:&lt;/p&gt;
&lt;p&gt;&lt;span&gt;sd_ble_uuid_vs_add(base_uuid1, uuid_type1);&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;Then to add the service or characteristic you use sd_ble_gatts_service_add(), where you refer to the uuid_type you received from &lt;span&gt;sd_ble_uuid_vs_add() above, e.g. something like&lt;/span&gt;:&lt;/p&gt;
&lt;p&gt;sd_ble_gatts_service_add(BLE_GATTS_SRVC_TYPE_PRIMARY, &lt;span&gt;uuid_type1&lt;/span&gt;, service_handle);&lt;/p&gt;
&lt;p&gt;Kenneth&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>