<?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 handle characteristic data?</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/7341/how-to-handle-characteristic-data</link><description>Hello, 
 For me, at the moment there are two things unclear.
With the help of some Nordic examples, I was able to add a Service with 3 characteristics to the used S120 BLE stack.
I`m able to connect to the PCA10028 demoboard via a Smartphone. I can</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 11 Jun 2015 09:37:54 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/7341/how-to-handle-characteristic-data" /><item><title>RE: How to handle characteristic data?</title><link>https://devzone.nordicsemi.com/thread/25999?ContentTypeID=1</link><pubDate>Thu, 11 Jun 2015 09:37:54 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6a831cf8-b2b4-405b-9682-742d2c1cb85c</guid><dc:creator>Ulrich Myhre</dc:creator><description>&lt;p&gt;The property flags are not actually enforcing anything, they are just indications to the peer that this characteristic supports to be e.g. read. It should be possible to read things even without the flag set, but &amp;quot;intelligent&amp;quot; tools might hide the option to do so based on the available flags.&lt;/p&gt;
&lt;p&gt;To add new characteristics in addition to the SDK, I would just look closely on how the SDK is handling modules like BAS (Battery Service). They have an init() function that adds all services/characteristics and saves their handles internally. Also an on_ble_evt() function that looks through incoming events to see if something is interesting (using the saved handles to compare).&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to handle characteristic data?</title><link>https://devzone.nordicsemi.com/thread/25998?ContentTypeID=1</link><pubDate>Thu, 11 Jun 2015 09:19:26 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:78fea743-44a9-463a-8988-bf3092f6464a</guid><dc:creator>Andreas</dc:creator><description>&lt;p&gt;A small leak will sink a great ship...
Thank you Ulrich!! Now reading and writing my variables is working...
By the way, is there any documentation of how to set up a new characteristic additional to the SDK? I think the missing read Flag was a copy paste error because the UART example (I copied from there) didn`t use this.
I know the apllication note 36. But there is no detailed code description...&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to handle characteristic data?</title><link>https://devzone.nordicsemi.com/thread/25997?ContentTypeID=1</link><pubDate>Thu, 11 Jun 2015 08:59:43 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2e9a8915-3bfd-4fe3-b355-16bb95d75c3b</guid><dc:creator>Ulrich Myhre</dc:creator><description>&lt;p&gt;You are reading the characteristic declaration (which has its own handle). The value handle should be just below this one. The &amp;quot;readable&amp;quot; property flag is also not set in char_md (you only set notify), which is why you see this &amp;quot;notifications enabled&amp;quot;.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to handle characteristic data?</title><link>https://devzone.nordicsemi.com/thread/25996?ContentTypeID=1</link><pubDate>Thu, 11 Jun 2015 08:52:54 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:97386a84-2142-4178-b6d8-a10aad156fe6</guid><dc:creator>Andreas</dc:creator><description>&lt;p&gt;Hello Ulrich,&lt;/p&gt;
&lt;p&gt;thanks for your answer and sorry for my misunderstanding. Currently I`m not able to get this topic running. :-(
Here is how I add my &amp;quot;sernum&amp;quot; characteristic.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;static uint32_t sernum_char_add(ble_device_t * p_dev, const ble_device_init_t * p_dev_init)
{
    ble_gatts_char_md_t char_md;
    ble_gatts_attr_md_t cccd_md;
    ble_gatts_attr_t    attr_char_value;
    ble_uuid_t          ble_uuid;
    ble_gatts_attr_md_t attr_md;
		int i=0;
	
		for(i=0;i&amp;lt;4;i++)
		{
			sernum[i]= i;
		}

    memset(&amp;amp;cccd_md, 0, sizeof(cccd_md));

    BLE_GAP_CONN_SEC_MODE_SET_OPEN(&amp;amp;cccd_md.read_perm);
    BLE_GAP_CONN_SEC_MODE_SET_OPEN(&amp;amp;cccd_md.write_perm);

    cccd_md.vloc = BLE_GATTS_VLOC_STACK;

    memset(&amp;amp;char_md, 0, sizeof(char_md));

    char_md.char_props.notify = 1;
    char_md.p_char_user_desc  = NULL;
    char_md.p_char_pf         = NULL;
    char_md.p_user_desc_md    = NULL;
    char_md.p_cccd_md         = &amp;amp;cccd_md;
    char_md.p_sccd_md         = NULL;

    ble_uuid.type = p_dev-&amp;gt;uuid_type;
    ble_uuid.uuid = BLE_UUID_DEV_SERNUM_CHARACTERISTIC;

    memset(&amp;amp;attr_md, 0, sizeof(attr_md));

    BLE_GAP_CONN_SEC_MODE_SET_OPEN(&amp;amp;attr_md.read_perm);
    BLE_GAP_CONN_SEC_MODE_SET_OPEN(&amp;amp;attr_md.write_perm);

    attr_md.vloc    = BLE_GATTS_VLOC_STACK;
    attr_md.rd_auth = 0;
    attr_md.wr_auth = 0;
    attr_md.vlen    = 1;

    memset(&amp;amp;attr_char_value, 0, sizeof(attr_char_value));

    attr_char_value.p_uuid    = &amp;amp;ble_uuid;
    attr_char_value.p_attr_md = &amp;amp;attr_md;
    attr_char_value.init_len  = (4*sizeof(uint8_t));
    attr_char_value.init_offs = 0;
    attr_char_value.max_len   = BLE_DEVICE_MAX_SERNUM_LEN;
		attr_char_value.p_value = sernum;

    return sd_ble_gatts_characteristic_add(p_dev-&amp;gt;service_handle,
                                           &amp;amp;char_md,
                                           &amp;amp;attr_char_value,
                                           &amp;amp;p_dev-&amp;gt;sernum_handles);
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;}&lt;/p&gt;
&lt;p&gt;sernum is a global array variable. So for my understanding attr_char_value.p_value points to the content of the array (filled with 0, 1, 2, 3).
But if I try to read this characteristic with the android Master Control Panel, I only get: &amp;quot;Value: Notifications enabled&amp;quot;. Where is my mistake!&lt;/p&gt;
&lt;p&gt;Regards!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to handle characteristic data?</title><link>https://devzone.nordicsemi.com/thread/26002?ContentTypeID=1</link><pubDate>Tue, 09 Jun 2015 07:30:52 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:eec571bb-c18e-4fbb-b022-7047ae98229a</guid><dc:creator>Ulrich Myhre</dc:creator><description>&lt;p&gt;The &lt;em&gt;p_handles&lt;/em&gt; field in characteristic_add() is an output parameter. All the handles that are assigned will be stored in this struct for you to use later.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to handle characteristic data?</title><link>https://devzone.nordicsemi.com/thread/26001?ContentTypeID=1</link><pubDate>Tue, 09 Jun 2015 06:53:21 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:bcd336f1-4671-4fb5-8add-788c68e58742</guid><dc:creator>Faizan</dc:creator><description>&lt;p&gt;I cannot understand this part of your answer Sir  Ulrich
&amp;quot;value handle that is returned from the characteristic_add() call. &amp;quot;
Since, These are the Return values of sd_ble_gatts_characteristic_add() call
NRF_SUCCESS	Successfully added a characteristic.
NRF_ERROR_INVALID_ADDR	Invalid pointer supplied.
NRF_ERROR_INVALID_PARAM	Invalid parameter(s) supplied, service handle, Vendor Specific UUIDs, lengths, and permissions need to adhere to the constraints.
NRF_ERROR_INVALID_STATE	Invalid state to perform operation, a service context is required.
NRF_ERROR_FORBIDDEN	Forbidden value supplied, certain UUIDs are reserved for the stack.
NRF_ERROR_NO_MEM	Not enough memory to complete operation.
NRF_ERROR_DATA_SIZE	Invalid data size(s) supplied, attribute lengths are restricted by Maximum attribute lengths.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to handle characteristic data?</title><link>https://devzone.nordicsemi.com/thread/26000?ContentTypeID=1</link><pubDate>Fri, 29 May 2015 12:39:05 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:33ccbac2-3c8f-444a-b8cb-cd9bd1e54e49</guid><dc:creator>Ulrich Myhre</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;When you add the characteristic with &lt;strong&gt;sd_ble_gatts_characteristic_add()&lt;/strong&gt;, the &lt;strong&gt;p_attr_char_value&lt;/strong&gt; argument points to  a &lt;strong&gt;ble_gatts_attr_t&lt;/strong&gt;. This type has the initial data, UUID, lengths and such for the characteristic. If you want to set your read-only data, you will set it here initially and save the value handle that is returned from the characteristic_add() call. After that you update it during run-time with &lt;strong&gt;sd_ble_gatts_value_set()&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;For writable characteristics, &lt;a href="https://developer.nordicsemi.com/nRF51_SDK/nRF51_SDK_v8.x.x/doc/8.1.0/s110/html/a01115.html"&gt;as you can see here&lt;/a&gt;, the stack will automatically receive and store any writes to the database for you. You will then receive an event that it happened, with a copy of the data. (This is only if you haven&amp;#39;t enabled write authorization, which will prompt you to accept or deny the write). If you want to have a look at it at a later point, you can use &lt;strong&gt;sd_ble_gatts_value_get()&lt;/strong&gt; to fetch the current value.&lt;/p&gt;
&lt;p&gt;Please read &lt;a href="https://developer.nordicsemi.com/nRF51_SDK/doc/"&gt;the documentation&lt;/a&gt; for any of the API calls I mentioned to see their usage and limitations, or look at the simpler SDK examples and see how they solve this.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>