<?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 to add an additional characteristic to the NUS service</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/41173/how-to-add-an-additional-characteristic-to-the-nus-service</link><description>I tried to add an additional characteristic to NUS service as below. 
 However, any mobile apps could find only existing Nordic Rx and Nordic Tx characteristics, other than the new characteristics. 
 Based on the several experiment, only two characteristics</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Mon, 10 Dec 2018 17:17:17 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/41173/how-to-add-an-additional-characteristic-to-the-nus-service" /><item><title>RE: How to add an additional characteristic to the NUS service</title><link>https://devzone.nordicsemi.com/thread/161072?ContentTypeID=1</link><pubDate>Mon, 10 Dec 2018 17:17:17 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d0983145-1370-44bf-8de1-c180809fdb16</guid><dc:creator>jay</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;Now working fine. Please close the ticket.&lt;/p&gt;
&lt;p&gt;Thank you for your help&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to add an additional characteristic to the NUS service</title><link>https://devzone.nordicsemi.com/thread/161044?ContentTypeID=1</link><pubDate>Mon, 10 Dec 2018 15:18:25 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8a6c9350-28f3-4215-859c-afbaa3f4305a</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;Have you&amp;nbsp;tested this, I think it should work, but still think that sd_ble_gatts_value_get()&amp;nbsp;is&amp;nbsp;redundant since you can retrieve&amp;nbsp;the same&amp;nbsp;data from the&amp;nbsp;&lt;span&gt;p_ble_evt-&amp;gt;evt.gatts_evt.params.write.data pointer. Please try&amp;nbsp;code below&amp;nbsp;if it doesn&amp;#39;t work:&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;static void on_write(ble_nus_t * p_nus, ble_evt_t * p_ble_evt)
{
    ble_gatts_evt_write_t * p_evt_write = &amp;amp;p_ble_evt-&amp;gt;evt.gatts_evt.params.write;
	
    if (
        (p_evt_write-&amp;gt;handle == p_nus-&amp;gt;rx_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))
        {
            p_nus-&amp;gt;is_notification_enabled = true;
        }
        else
        {
            p_nus-&amp;gt;is_notification_enabled = false;
        }
    }
    else if 
		(
        (p_evt_write-&amp;gt;handle == p_nus-&amp;gt;char_handles1.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))
			{
				printf(&amp;quot;Notification enabled\r\n&amp;quot;);
			}
			else
			{
				printf(&amp;quot;Notification disabled\r\n&amp;quot;);
			}
	
    else if (
             (p_evt_write-&amp;gt;handle == p_nus-&amp;gt;tx_handles.value_handle)
             &amp;amp;&amp;amp;
             (p_nus-&amp;gt;data_handler != NULL)
            )
    {
        p_nus-&amp;gt;data_handler(p_nus, p_evt_write-&amp;gt;data, p_evt_write-&amp;gt;len);
    }
	else if ( (p_evt_write-&amp;gt;handle == p_nus-&amp;gt;char_handles1.value_handle) &amp;amp;&amp;amp; (p_evt_write-&amp;gt;len == 4))
	{
		uint32_t data_buffer0;
		
		memcpy(&amp;amp;data_buffer0, p_evt_write-&amp;gt;data, sizeof(uint32_t));
		p_nus-&amp;gt;gpio_output_write_handler(p_nus, data_buffer0)
		
	)	
}&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to add an additional characteristic to the NUS service</title><link>https://devzone.nordicsemi.com/thread/161027?ContentTypeID=1</link><pubDate>Mon, 10 Dec 2018 14:27:17 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:3f1d128a-a69a-45e5-8f62-28f011757d21</guid><dc:creator>jay</dc:creator><description>&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;static void on_write(ble_nus_t * p_nus, ble_evt_t * p_ble_evt)
{
    ble_gatts_evt_write_t * p_evt_write = &amp;amp;p_ble_evt-&amp;gt;evt.gatts_evt.params.write;

	
    if (
        (p_evt_write-&amp;gt;handle == p_nus-&amp;gt;rx_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))
        {
            p_nus-&amp;gt;is_notification_enabled = true;
        }
        else
        {
            p_nus-&amp;gt;is_notification_enabled = false;
        }
    }
    else if (
             (p_evt_write-&amp;gt;handle == p_nus-&amp;gt;tx_handles.value_handle)
             &amp;amp;&amp;amp;
             (p_nus-&amp;gt;data_handler != NULL)
            )
    {
        p_nus-&amp;gt;data_handler(p_nus, p_evt_write-&amp;gt;data, p_evt_write-&amp;gt;len);
    }
    else
    {
				// Decclare buffer variable to hold received data. The data can only be 32 bit long.
				uint32_t data_buffer0;
				// Populate ble_gatts_value_t structure to hold received data and metadata.
				ble_gatts_value_t rx_data;
				rx_data.len = sizeof(uint32_t);
				rx_data.offset = 0;
				rx_data.p_value = (uint8_t*)&amp;amp;data_buffer0;
			
                // Check if write event is performed on asi characteristic or the CCCD
				if (p_evt_write-&amp;gt;handle == p_nus-&amp;gt;char_handles1.value_handle)
				{
					// Get data
					sd_ble_gatts_value_get(p_nus-&amp;gt;conn_handle, p_nus-&amp;gt;char_handles1.value_handle, &amp;amp;rx_data);
					p_nus-&amp;gt;gpio_output_write_handler(p_nus, data_buffer0);
				
				}
				else if((p_evt_write-&amp;gt;handle == p_nus-&amp;gt;char_handles1.cccd_handle)&amp;amp;&amp;amp;(p_evt_write-&amp;gt;len == 2))
				{
					// Get data
					sd_ble_gatts_value_get(p_nus-&amp;gt;conn_handle, p_nus-&amp;gt;char_handles1.cccd_handle, &amp;amp;rx_data);
					if(data_buffer0 == 0x0001)
					{
            printf(&amp;quot;Notification enabled\r\n&amp;quot;);
					}
					else if(data_buffer0 == 0x0000)
					{
            printf(&amp;quot;Notification disabled\r\n&amp;quot;);
					}
				}
    }
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;What about this way? I want to add a separate char under NUS service.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to add an additional characteristic to the NUS service</title><link>https://devzone.nordicsemi.com/thread/160911?ContentTypeID=1</link><pubDate>Mon, 10 Dec 2018 09:59:38 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:35a941ba-6067-447a-aaec-ece27d826acd</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;I don&amp;#39;t see anything in your code snippet that can cause the program to get stuck. However, you don&amp;#39;t need to call&amp;nbsp;&amp;nbsp;&lt;span&gt;sd_ble_gatts_value_get() as the data pointer is provided&amp;nbsp;in&amp;nbsp;p_ble_evt-&amp;gt;evt.gatts_evt.params.write.data.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&amp;nbsp;default on_write handler in nordic uart service:&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;/**@brief Function for handling the @ref BLE_GATTS_EVT_WRITE event from the S110 SoftDevice.
 *
 * @param[in] p_nus     Nordic UART Service structure.
 * @param[in] p_ble_evt Pointer to the event received from BLE stack.
 */
static void on_write(ble_nus_t * p_nus, ble_evt_t * p_ble_evt)
{
    ble_gatts_evt_write_t * p_evt_write = &amp;amp;p_ble_evt-&amp;gt;evt.gatts_evt.params.write;

    if (
        (p_evt_write-&amp;gt;handle == p_nus-&amp;gt;rx_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))
        {
            p_nus-&amp;gt;is_notification_enabled = true;
        }
        else
        {
            p_nus-&amp;gt;is_notification_enabled = false;
        }
    }
    else if (
             (p_evt_write-&amp;gt;handle == p_nus-&amp;gt;tx_handles.value_handle)
             &amp;amp;&amp;amp;
             (p_nus-&amp;gt;data_handler != NULL)
            )
    {
        p_nus-&amp;gt;data_handler(p_nus, p_evt_write-&amp;gt;data, p_evt_write-&amp;gt;len); // Notify app through registered callback
    }
    else
    {
        // Do Nothing. This event is not relevant for this service.
    }
}&lt;/pre&gt;&lt;/span&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: How to add an additional characteristic to the NUS service</title><link>https://devzone.nordicsemi.com/thread/160773?ContentTypeID=1</link><pubDate>Fri, 07 Dec 2018 14:42:02 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e711631e-f182-46ab-9225-056c6c1978f1</guid><dc:creator>jay</dc:creator><description>&lt;p&gt;Hi Vidar,&lt;/p&gt;
&lt;p&gt;Thank you for your feedback. Yes, you are right. It was the cache clearance issue from mobile phone.&lt;/p&gt;
&lt;p&gt;Now I have a new problem related with &amp;quot;sd_ble_gatts_value_get&amp;quot;. My code was stuck at it.&lt;/p&gt;
&lt;p&gt;if (p_evt_write-&amp;gt;handle == p_nus-&amp;gt;char_handles1.value_handle)&lt;br /&gt; {&lt;br /&gt;&lt;br /&gt; sd_ble_gatts_value_get(p_nus-&amp;gt;conn_handle, p_nus-&amp;gt;char_handles1.value_handle, &amp;amp;rx_data);&lt;br /&gt; printf(&amp;quot;Value received on handle %#06x: %#010x\r\n&amp;quot;, p_evt_write-&amp;gt;handle, data_buffer0);&lt;br /&gt; p_nus-&amp;gt;gpio_output_write_handler(p_nus, data_buffer0);&lt;br /&gt; &lt;br /&gt; }&lt;/p&gt;
&lt;p&gt;Do you have any suggestion around this issue?&amp;nbsp;&lt;/p&gt;
&lt;p&gt;BTW, should I close this and re-open the ticket for this new issue?&lt;/p&gt;
&lt;p&gt;Thanks&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to add an additional characteristic to the NUS service</title><link>https://devzone.nordicsemi.com/thread/160221?ContentTypeID=1</link><pubDate>Tue, 04 Dec 2018 13:56:07 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:98215274-656c-4b15-8b10-44771fb286bd</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;Hi,&amp;nbsp;&lt;/p&gt;
&lt;p&gt;This may be&amp;nbsp;caused by attribute caching, your code appears to be correct. The phone will&amp;nbsp;cache the attribute table across connections unless the &amp;quot;service changed&amp;quot; characteristic is present. I.e., it will remember the attribute table from before you added the new characteristic. If you have an iphone you can clear the cache by enabling and disabling flight mode.&amp;nbsp;&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>