<?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 write/read GATT attribute values?</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/75014/how-to-write-read-gatt-attribute-values</link><description>Hi, 
 
 I am trying to implement BLE on nRF52840 using Zephyr APIs. I am wondering if anyone can elaborate how to use bt_gatt_write() and bt_gatt_read(). As of now, I am able to see the definition and description of these function in gatt.h, but there</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Fri, 14 May 2021 13:26:40 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/75014/how-to-write-read-gatt-attribute-values" /><item><title>RE: How to write/read GATT attribute values?</title><link>https://devzone.nordicsemi.com/thread/309798?ContentTypeID=1</link><pubDate>Fri, 14 May 2021 13:26:40 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:bf784ae2-538e-4d0a-acb0-3e379a356170</guid><dc:creator>Simon</dc:creator><description>&lt;p&gt;It&amp;#39;s a long time since I&amp;#39;ve worked with the nRF5 SDK (I mostly work with the nRF Connect SDK), would you be able to open a new ticket and ask your question there? Then it will get assigned to an engineer with knowledge about this and you will get help.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to write/read GATT attribute values?</title><link>https://devzone.nordicsemi.com/thread/309676?ContentTypeID=1</link><pubDate>Thu, 13 May 2021 17:12:48 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b9963e15-bca6-4ace-a0eb-e2dae17289ea</guid><dc:creator>Shivek</dc:creator><description>&lt;p&gt;Hi Simon,&lt;/p&gt;
&lt;p&gt;Thanks for your efforts. I am using Softdevice S140 now rather than using Zephyr APIs. I am wondering how can I implement my custom service as stated earlier. I am following &lt;a href="https://devzone.nordicsemi.com/nordic/short-range-guides/b/bluetooth-low-energy/posts/ble-services-a-beginners-tutorial"&gt;this tutorial&lt;/a&gt;. The problem is I have UUIDs for Service and Characteristic unrelated (Characteristic UUIDs are not related to the Primary service UUID).&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I tried using&amp;nbsp;&lt;strong&gt;sd_ble_gatts_service_add()&lt;/strong&gt; API, to add custom service&amp;nbsp;without using&amp;nbsp;&lt;strong&gt;sd_ble_uuid_vs_add()&lt;/strong&gt; as I was trying to avoid supplying BASE UUID and 16 bit UUID separately. But I guess we need to use &lt;strong&gt;sd_ble_uuid_vs_add()&lt;/strong&gt;&amp;nbsp;to add vendor specific UUID to ATT table. In my case, SERVICE_UUID (refer to my first post), DEV_ID_UUID, DEV_TYPE_UUID,.. all are different.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Can you please tell me how to implement custom services using proprietary UUIDs for service and cahracteristics?&lt;/p&gt;
&lt;p&gt;In a nutshell, I want to implement what I am doing in the second part of my earlier post using Softdevice S140 APIs. FYI this would be the structure for my service:&lt;/p&gt;
&lt;p&gt;Primary Service with UUID =&amp;nbsp;f3800767-c8a6-4857-9049-896521c7379e&lt;/p&gt;
&lt;p&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; DEV_ID Characteristic with UUID =&amp;nbsp;22d7b64e-9bd3-4f30-b1ea-8eb3445c9877&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; DEV_TYPE Characteristic with UUID = 89&lt;/span&gt;&lt;span&gt;d7c21e-5be3-6d60-c3ea-7be1236b1410&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to write/read GATT attribute values?</title><link>https://devzone.nordicsemi.com/thread/309616?ContentTypeID=1</link><pubDate>Wed, 12 May 2021 23:53:07 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b2943a2c-884e-461d-a122-46f5c90e2d14</guid><dc:creator>Simon</dc:creator><description>&lt;p&gt;I recommend you to study the samples &lt;a href="https://github.com/nrfconnect/sdk-nrf/tree/v1.5.1/samples/bluetooth/peripheral_cts_client"&gt;peripheral_cts_client&lt;/a&gt;&amp;nbsp;and &lt;a href="https://github.com/nrfconnect/sdk-nrf/tree/v1.5.1/samples/bluetooth/central_uart"&gt;central_uart&lt;/a&gt;&amp;nbsp;and&amp;nbsp;their associated service libraries &lt;a href="https://github.com/nrfconnect/sdk-nrf/blob/v1.5.1/subsys/bluetooth/services/cts_client.c"&gt;cts_client.c&lt;/a&gt;&amp;nbsp;and &lt;a href="https://github.com/nrfconnect/sdk-nrf/blob/v1.5.1/subsys/bluetooth/services/nus_client.c"&gt;nus_client.c&lt;/a&gt;, where you can see examples of how to use the functions &lt;a href="https://github.com/nrfconnect/sdk-nrf/blob/v1.5.1/subsys/bluetooth/services/nus_client.c#L105"&gt;bt_gatt_write()&lt;/a&gt;&lt;span&gt;&amp;nbsp;and &lt;a href="https://github.com/nrfconnect/sdk-nrf/blob/v1.5.1/subsys/bluetooth/services/cts_client.c#L254"&gt;bt_gatt_read()&lt;/a&gt;.&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Regarding the offset field, It was hard to find information about it. All the other bluetooth samples are just setting it to 0. I looked at&amp;nbsp;zephyr\subsys\bluetooth\host\gatt.c and saw that it would trigger &lt;a href="https://github.com/nrfconnect/sdk-zephyr/blob/v2.4.99-ncs2/subsys/bluetooth/host/gatt.c#L3942"&gt;bt_gatt_prepare_write()&lt;/a&gt; if the offset was set to a nonzero value, while &lt;a href="https://github.com/nrfconnect/sdk-zephyr/blob/v2.4.99-ncs2/subsys/bluetooth/host/gatt.c#L3963"&gt;gatt_send()&lt;/a&gt; would get triggered if the offset is set to zero (and the length is less than the MTU), you may look into these function to understand the offset field better. I think the prepare write function is used for long write situations, but I need to investigate this more to give you a certain answer.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;However, I think you should be fine just setting it to 0.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt; I will investigate this further on Friday or next Tuesday (There are national holidays on Thursday and Monday in Norway).&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Best regards,&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Simon&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>