<?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>Issue in Adding 2nd characteristics in Custom Service</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/66049/issue-in-adding-2nd-characteristics-in-custom-service</link><description>Hi, I am following the below link for creating custom services/characteristics. https://github.com/bjornspockeli/nRF52-Bluetooth-Course Now I am adding the second characteristic in that service but unable to see in the nRF app. 
 I have added 2nd custom_value_char_add_2</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 23 Sep 2020 11:56:41 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/66049/issue-in-adding-2nd-characteristics-in-custom-service" /><item><title>RE: Issue in Adding 2nd characteristics in Custom Service</title><link>https://devzone.nordicsemi.com/thread/271071?ContentTypeID=1</link><pubDate>Wed, 23 Sep 2020 11:56:41 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f2f13d32-1bed-4c36-8c54-bf8e59199878</guid><dc:creator>Muqarrab</dc:creator><description>&lt;p&gt;Thanks I have solved the problem by adding this.&lt;br /&gt;&lt;br /&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;/**@brief Custom Service structure. This contains various status information for the service. */
struct ble_cus_s
{
    uint16_t                      service_handle;                 /**&amp;lt; Handle of Custom Service (as provided by the BLE stack). */
    uint16_t                      conn_handle;                    /**&amp;lt; Handle of the current connection (as provided by the BLE stack, is BLE_CONN_HANDLE_INVALID if not in a connection). */
    uint8_t                       uuid_type; 
    ble_gatts_char_handles_t      custom_value_handles;           /**&amp;lt; Handles related to the Custom Value characteristic. */
    ble_gatts_char_handles_t      custom_value_handles_2;           /**&amp;lt; Handles related to the Custom Value characteristic. */

};    
&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Issue in Adding 2nd characteristics in Custom Service</title><link>https://devzone.nordicsemi.com/thread/271070?ContentTypeID=1</link><pubDate>Wed, 23 Sep 2020 11:54:47 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a93cd575-bb12-4e14-a055-359ba21d469d</guid><dc:creator>Edvin</dc:creator><description>[quote user="muqarrab_rahman"]This making me confuse as both&amp;nbsp;characteristics are added by the same&amp;nbsp;&lt;strong&gt;p_cus&amp;nbsp;&lt;/strong&gt;so how can I differentiate&amp;nbsp;&amp;nbsp;&lt;br /&gt;&lt;strong&gt;p_cus-&amp;gt;custom_value_handles.value_handle&amp;nbsp;&lt;/strong&gt;for 2&amp;nbsp;characteristics.[/quote]
&lt;p&gt;&amp;nbsp;Just like in ble_app_uart, you need to declare two different handles in p_cus.&lt;/p&gt;
&lt;p&gt;p_cus-&amp;gt;custom_value_handles_characteristic_1&lt;/p&gt;
&lt;p&gt;and&amp;nbsp;&lt;/p&gt;
&lt;p&gt;p_cus-&amp;gt;custom_value_handles_characteristic_2&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;So somewhere in ble_cus.h, you should have something like this:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;struct ble_cus_s
{
    uint8_t                         uuid_type;                                      /**&amp;lt; UUID type for Nordic UART Service Base UUID. */
    uint16_t                        service_handle;                                 /**&amp;lt; Handle of Nordic UART Service (as provided by the SoftDevice). */
    ble_gatts_char_handles_t        custom_value_handles_characteristic_1;          /**&amp;lt; Handles related to the TX characteristic (as provided by the SoftDevice). */
    ble_gatts_char_handles_t        custom_value_handles_characteristic_2;          /**&amp;lt; Handles related to the RX characteristic (as provided by the SoftDevice). */
    ble_cus_data_handler_t          data_handler;                                   /**&amp;lt; Event handler to be called for handling received data. */
};&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
[quote user="muqarrab_rahman"]Is there any other example that has 2+&amp;nbsp;&lt;span&gt;characteristics in 1 service and sending back data?&lt;/span&gt;[/quote]
&lt;p&gt;&amp;nbsp;Yes. ble_app_uart, but only one is for sending. The other characteristic is only for receiving. But what I am trying to tell you is that this example points to the characteristic handle that belongs to that specific characteristic.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Issue in Adding 2nd characteristics in Custom Service</title><link>https://devzone.nordicsemi.com/thread/271049?ContentTypeID=1</link><pubDate>Wed, 23 Sep 2020 11:09:41 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5d0cc9f0-13de-4f7c-94b6-15e580bf0721</guid><dc:creator>Muqarrab</dc:creator><description>&lt;p&gt;Hi @Edvin,&lt;br /&gt;&lt;br /&gt;I have checked the mentioned example which has Tx Rx &lt;span&gt;characteristics.&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;The above-mentioned example making me confuse as it has only 1&amp;nbsp;&lt;span&gt;characteristic to write back data.&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;I have also successfully written data in our code on one&amp;nbsp;&lt;span&gt;characteristic&lt;/span&gt;&amp;nbsp;but unable to write the second&amp;nbsp;&lt;span&gt;characteristic.(Unable to handle &lt;strong&gt;p_cus-&amp;gt;custom_value_handles.value_handle&lt;/strong&gt;).&lt;br /&gt;&lt;br /&gt;This making me confuse as both&amp;nbsp;characteristics are added by the same&amp;nbsp;&lt;strong&gt;p_cus&amp;nbsp;&lt;/strong&gt;so how can I differentiate&amp;nbsp;&amp;nbsp;&lt;br /&gt;&lt;strong&gt;p_cus-&amp;gt;custom_value_handles.value_handle&amp;nbsp;&lt;/strong&gt;for 2&amp;nbsp;characteristics.&lt;br /&gt;&lt;br /&gt;Any help for this point?&lt;br /&gt;&lt;br /&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;    // Add Custom value characteristic
    err_code = custom_value_char_add(p_cus, p_cus_init);
    APP_ERROR_CHECK(err_code);
    
    err_code = custom_value_char_add_2(p_cus, p_cus_init);
    APP_ERROR_CHECK(err_code);  // This line is not strictly needed, but if you plan to do more, don&amp;#39;t return this value
&lt;/pre&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Is there any other example that has 2+&amp;nbsp;&lt;span&gt;characteristics in 1 service and sending back data?&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;Thanks!&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Issue in Adding 2nd characteristics in Custom Service</title><link>https://devzone.nordicsemi.com/thread/271008?ContentTypeID=1</link><pubDate>Wed, 23 Sep 2020 08:35:35 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:abc92e90-b7ed-4f98-8fd4-bc2054445f13</guid><dc:creator>Edvin</dc:creator><description>&lt;p&gt;For the solution, please see how it is done in the example:&lt;/p&gt;
&lt;p&gt;SDK\examples\ble_peripheral\ble_app_uart&lt;/p&gt;
&lt;p&gt;Look at how the function ble_nus_data_send() is implemented. it sends a notification using a specific handle:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;hvx_params.handle = p_nus-&amp;gt;tx_handles.value_handle;&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;This characteristic specific handle is set in characteristic_add(..., p_nus-&amp;gt;tx_handles).&lt;/p&gt;
&lt;p&gt;There is actually a lot of useful information in this example.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;As far as I can tell, you haven&amp;#39;t implemented anything that sends any data yet. I suggest you try to start by following the tutorial, which only has one characteristic, to get the basic understanding first, and then you can look at the ble_app_uart example, to see how to use two different characteristics. It is difficult to point to something in your code, because I don&amp;#39;t see your ble_cus.h file. But see how this has two handles in the ble_app_uart example. One for the TX characteristic and one for the RX characteristic:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;struct ble_nus_s
{
    uint8_t                         uuid_type;          /**&amp;lt; UUID type for Nordic UART Service Base UUID. */
    uint16_t                        service_handle;     /**&amp;lt; Handle of Nordic UART Service (as provided by the SoftDevice). */
    ble_gatts_char_handles_t        tx_handles;         /**&amp;lt; Handles related to the TX characteristic (as provided by the SoftDevice). */
    ble_gatts_char_handles_t        rx_handles;         /**&amp;lt; Handles related to the RX characteristic (as provided by the SoftDevice). */
    blcm_link_ctx_storage_t * const p_link_ctx_storage; /**&amp;lt; Pointer to link context storage with handles of all current connections and its context. */
    ble_nus_data_handler_t          data_handler;       /**&amp;lt; Event handler to be called for handling received data. */
};&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: Issue in Adding 2nd characteristics in Custom Service</title><link>https://devzone.nordicsemi.com/thread/270831?ContentTypeID=1</link><pubDate>Tue, 22 Sep 2020 12:06:25 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:40fcb6cd-83bd-4157-9393-f4e198b56b61</guid><dc:creator>Muqarrab</dc:creator><description>&lt;p&gt;Thanks @Edvin&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
[quote userid="26071" url="~/f/nordic-q-a/66049/issue-in-adding-2nd-characteristics-in-custom-service/270529"]&amp;nbsp;That is because you are using the same UUID in&amp;nbsp;custom_value_char_add() and&amp;nbsp;custom_value_char_add_2().[/quote]
&lt;p&gt;I have solved the issue by using this.&lt;br /&gt;&lt;br /&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;#define CUSTOM_VALUE_CHAR_UUID       0x1401
#define CUSTOM_VALUE_CHAR_UUID_2     0x1402

ble_uuid.uuid = CUSTOM_VALUE_CHAR_UUID_2;//In custom_value_char_add_2
&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;
[quote userid="26071" url="~/f/nordic-q-a/66049/issue-in-adding-2nd-characteristics-in-custom-service/270529"]&amp;nbsp;You need to implement and handle the handles correctly. Play around with it and read Bjørn&amp;#39;s tutorial (the first link in your ticket).[/quote]
&lt;p&gt;Also solved by&amp;nbsp;&lt;strong&gt;p_evt_write-&amp;gt;uuid.uuid&amp;nbsp;&lt;/strong&gt;by this.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;
[quote userid="26071" url="~/f/nordic-q-a/66049/issue-in-adding-2nd-characteristics-in-custom-service/270529"]You need to send something called a notification. Please see section 8 in the guide.[/quote]
&lt;p&gt;I have seen the tutorial. But there is not mentioned how can I send data on specific&amp;nbsp;characteristics?&lt;br /&gt;Can you please explain how can I write back on specific UUID&amp;nbsp;characteristics?&lt;br /&gt;&lt;br /&gt;Thanks!&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Issue in Adding 2nd characteristics in Custom Service</title><link>https://devzone.nordicsemi.com/thread/270529?ContentTypeID=1</link><pubDate>Mon, 21 Sep 2020 09:54:35 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:cdefc525-33a9-49ba-b6c0-b79b2cdbaa3c</guid><dc:creator>Edvin</dc:creator><description>[quote user="muqarrab_rahman"]1-Now the issue both&amp;nbsp;characteristic is showing the same id. (As shown in the attached image)[/quote]
&lt;p&gt;&amp;nbsp;That is because you are using the same UUID in&amp;nbsp;custom_value_char_add() and&amp;nbsp;custom_value_char_add_2().&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
[quote user="muqarrab_rahman"]2-How can I handle data of both&amp;nbsp;characteristics separately?[/quote]
&lt;p&gt;&amp;nbsp;You need to implement and handle the handles correctly. Play around with it and read Bjørn&amp;#39;s tutorial (the first link in your ticket).&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
[quote user="muqarrab_rahman"]3-How can I write back data from the device side on that&amp;nbsp;characteristic? (For response)[/quote]
&lt;p&gt;&amp;nbsp;You need to send something called a notification. Please see section 8 in the guide.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Issue in Adding 2nd characteristics in Custom Service</title><link>https://devzone.nordicsemi.com/thread/270524?ContentTypeID=1</link><pubDate>Mon, 21 Sep 2020 09:46:25 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b7e3b223-8bfc-49af-8210-2b2fe93b4963</guid><dc:creator>Muqarrab</dc:creator><description>&lt;p&gt;Thanks,&amp;nbsp;&lt;a href="https://devzone.nordicsemi.com/members/edvin-holmseth"&gt;Edvin&lt;/a&gt;&lt;br /&gt;I have changed the above code and now able to see 2nd&amp;nbsp;&lt;span&gt;characteristic. &lt;span class="emoticon" data-url="https://devzone.nordicsemi.com/cfs-file/__key/system/emoji/1f642.svg" title="Slight smile"&gt;&amp;#x1f642;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;1-Now the issue both&amp;nbsp;characteristic is showing the same id. (As shown in the attached image)&lt;br /&gt;&lt;br /&gt;&lt;img src="https://devzone.nordicsemi.com/resized-image/__size/320x240/__key/communityserver-discussions-components-files/4/WhatsApp-Image-2020_2D00_09_2D00_21-at-2.41.09-PM.jpeg" alt=" " /&gt;&lt;br /&gt;&lt;br /&gt;2-How can I handle data of both&amp;nbsp;characteristics separately?&lt;br /&gt;3-How can I write back data from the device side on that&amp;nbsp;characteristic? (For response)&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;/**@brief Function for handling the Write event.
 *
 * @param[in]   p_cus       Custom Service structure.
 * @param[in]   p_ble_evt   Event received from the BLE stack.
 */
void on_write(ble_cus_t * p_cus, ble_evt_t const * p_ble_evt)
{
    ble_gatts_evt_write_t *p_evt_write = &amp;amp;p_ble_evt-&amp;gt;evt.gatts_evt.params.write;
    
    // Check if the handle passed with the event matches the Custom Value Characteristic handle.
    if (p_evt_write-&amp;gt;handle == p_cus-&amp;gt;custom_value_handles.value_handle)
    {
        NRF_LOG_INFO(&amp;quot;Data Write: %x&amp;quot;, p_evt_write-&amp;gt;data[0]);
 
        if(nrf_gpio_pin_read(Input_PIN)){
          NRF_LOG_INFO(&amp;quot;Button is Off&amp;quot;);
        }else{
          NRF_LOG_INFO(&amp;quot;Button is On&amp;quot;);
        }

        if(p_evt_write-&amp;gt;data[0]==0x01)
        {
            NRF_LOG_INFO(&amp;quot;Locked&amp;quot;);
            nrf_gpio_pin_set(Lock_PIN);
            nrf_delay_ms(1000);
            nrf_gpio_pin_clear(Lock_PIN);

        }
        else if(p_evt_write-&amp;gt;data[0]==0x02)
        {
            NRF_LOG_INFO(&amp;quot;UnLocked&amp;quot;);
            nrf_gpio_pin_set(Lock_PIN);
            nrf_delay_ms(1000);
            nrf_gpio_pin_clear(Lock_PIN);
        }
    }

}
&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Thanks again&amp;nbsp;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Issue in Adding 2nd characteristics in Custom Service</title><link>https://devzone.nordicsemi.com/thread/270491?ContentTypeID=1</link><pubDate>Mon, 21 Sep 2020 08:30:20 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:cf5079ea-259d-4d07-8ec7-75c2b784ac01</guid><dc:creator>Edvin</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;[quote user=""][/quote]&lt;/p&gt;
&lt;div&gt;Now I am adding the second&amp;nbsp;characteristic in that service but unable to see in the nRF app.&lt;/div&gt;
&lt;div&gt;&lt;br /&gt;I have added 2nd&amp;nbsp;&lt;strong&gt;custom_value_char_add_2 function&amp;nbsp;&lt;/strong&gt;for 2nd&amp;nbsp;&lt;span&gt;characteristics.&lt;/span&gt;&amp;nbsp;&lt;/div&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;Do you see the device at all? Are you able to connect to the device?&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;It is quite common that phones cache BLE services. Try to disconnect from the device from your phone. If you have the option &amp;quot;forget device&amp;quot; try that. Then turn Bluetooth completely off for a minute, and turn it back on. Does the new service appear?&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;I wrote this before I looked at your attached file. But it may still be the case after you fix the bug in the file. So that is why I keep it.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;The issue with your code is in ble_cus_init().&amp;nbsp;&lt;/p&gt;
&lt;p&gt;You return the value from custom_value_char_add(). When you return from a function, the part after this return will not be executed, so your line:&lt;/p&gt;
&lt;p&gt;return custom_value_char_add_2() will not be executed. Try to change to this:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;uint32_t ble_cus_init(ble_cus_t * p_cus, const ble_cus_init_t * p_cus_init)
{
    ... //all the stuff that you already have
    
    // Add Custom value characteristic
    err_code = custom_value_char_add(p_cus, p_cus_init);
    APP_ERROR_CHECK(err_code);
    err_code = custom_value_char_add2(p_cus, p_cus_init);
    APP_ERROR_CHECK(err_code);  // This line is not strictly needed, but if you plan to do more, don&amp;#39;t return this value
    
    return err_code;
}&lt;/pre&gt;&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>