<?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>Changing UUID in Bluetooth: Peripheral HT sample</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/94060/changing-uuid-in-bluetooth-peripheral-ht-sample</link><description>Hi, 
 I have successfully flashed the Zephyr Bluetooth: Peripheral HT sample to my nRF52833 DK. 
 I would like to change the service used for temperature indications from the currently used Health Thermometer service to the Environmental Sensing Service</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Fri, 25 Nov 2022 11:30:25 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/94060/changing-uuid-in-bluetooth-peripheral-ht-sample" /><item><title>RE: Changing UUID in Bluetooth: Peripheral HT sample</title><link>https://devzone.nordicsemi.com/thread/397614?ContentTypeID=1</link><pubDate>Fri, 25 Nov 2022 11:30:25 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f02daf59-23b4-4acd-b7b7-daf4b8c82576</guid><dc:creator>Naeem Maroof</dc:creator><description>&lt;p&gt;Hi Adam,&lt;/p&gt;
&lt;p&gt;Thank you for your patience.&lt;/p&gt;
&lt;p&gt;In the &lt;strong&gt;&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;peripheral_esp&lt;/span&gt; &lt;/strong&gt;sample, there is main.c and in the &lt;strong&gt;&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;peripheral_ht&lt;/span&gt; &lt;/strong&gt;there is hts.c that we need to see / compare to get how to modify / update.&lt;/p&gt;
&lt;p&gt;In the &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;main.c&lt;/span&gt; file, in the service define, we have:&lt;br /&gt;&lt;pre class="ui-code" data-mode="text"&gt;BT_GATT_CHARACTERISTIC(BT_UUID_TEMPERATURE, 
                        BT_GATT_CHRC_READ | BT_GATT_CHRC_NOTIFY, BT_GATT_PERM_READ,
                        read_u16, NULL, &amp;amp;sensor_1.temp_value)&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;while in the &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;hts.c&lt;/span&gt; file, in the service define, we have:&lt;br /&gt;&lt;pre class="ui-code" data-mode="text"&gt;BT_GATT_CHARACTERISTIC(BT_UUID_TEMPERATURE, BT_GATT_CHRC_INDICATE,
                        BT_GATT_PERM_NONE, NULL, NULL, NULL)&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;In the first case (&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;main.c&lt;/span&gt;), there is a function &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;read_u16&lt;/span&gt; associated with the characteristic to do the operation, while in the second case (hts.c), that kind of operation is done at the end of the file (in the code you have pointed out).&lt;/p&gt;
&lt;p&gt;Now lets see inside &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;read_u16&lt;/span&gt;:&lt;br /&gt;&lt;pre class="ui-code" data-mode="text"&gt;static ssize_t read_u16(struct bt_conn *conn, const struct bt_gatt_attr *attr,
                        void *buf, uint16_t len, uint16_t offset)
{
    const uint16_t *u16 = attr-&amp;gt;user_data;
    uint16_t value = sys_cpu_to_le16(*u16);
    return bt_gatt_attr_read(conn, attr, buf, len, offset, &amp;amp;value, sizeof(value));
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;And in case of &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;hts.c&lt;/span&gt;:&lt;br /&gt; &lt;pre class="ui-code" data-mode="text"&gt;mantissa = (uint32_t)(temperature * 100);
exponent = (uint8_t)-2;
htm[0] = 0; /* temperature in celsius */

sys_put_le24(mantissa, (uint8_t *)&amp;amp;htm[1]);
htm[4] = exponent;&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;using &amp;quot;Temperature&amp;quot; characteristic, we need a single value (please see GATT Specifications for details), and that of the type int (16 bit). Now relate it to &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;read_u16&lt;/span&gt; function: we have u16 that is integer pointer, and we are arranging in Little Endian format using &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;sys_cpu_to_le16&lt;/span&gt;.&lt;/p&gt;
&lt;p&gt;using &amp;quot;Temperature Measurement&amp;quot; characteristic, we need variable length structure containing flags, values and other fields. You can see in hts.c that we have htm array to store multiple values; for example &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;htm[0]=0&lt;/span&gt; was to set the flag that the temperature is in Centigrade units.&lt;/p&gt;
&lt;p&gt;As you want to use &amp;quot;Temperature&amp;quot; characteristic with ESS service, you will need only one value.&lt;/p&gt;
&lt;p&gt;Hope it helps.&lt;br /&gt;Regards,&lt;br /&gt;Naeem&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Changing UUID in Bluetooth: Peripheral HT sample</title><link>https://devzone.nordicsemi.com/thread/397036?ContentTypeID=1</link><pubDate>Wed, 23 Nov 2022 00:58:30 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:817372f9-50d2-43ce-9512-8d87c13f89a9</guid><dc:creator>adam_atmo</dc:creator><description>&lt;p&gt;Thank you Naeem,&lt;/p&gt;
&lt;p&gt;I had a loom at the &lt;a href="https://github.com/zephyrproject-rtos/zephyr/blob/v2.6.1-rc2/samples/bluetooth/peripheral_esp/src/main.c"&gt;peripheral ESP sample&lt;/a&gt;. I am still not sure how I should change the formatting so that it prints temperature values correctly. Also, the &lt;a href="https://www.bluetooth.com/specifications/specs/environmental-sensing-service-1-0/"&gt;SIG specification on the environmental service&lt;/a&gt; doesn&amp;#39;t seem to explain how temperature values must be formatted either. Any suggestions as to how I should format the data?&lt;/p&gt;
&lt;p&gt;It looks like these lines are being used in the hts.c file for formatting the hts temperature data:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;mantissa = (uint32_t)(temperature * 100);
exponent = (uint8_t)-2;

htm[0] = 0; /* temperature in celcius */
sys_put_le24(mantissa, (uint8_t *)&amp;amp;htm[1]);
htm[4] = exponent;&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Regards,&lt;/p&gt;
&lt;p&gt;Adam&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Changing UUID in Bluetooth: Peripheral HT sample</title><link>https://devzone.nordicsemi.com/thread/397023?ContentTypeID=1</link><pubDate>Tue, 22 Nov 2022 21:21:23 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:630bc059-3382-40c3-adc0-7b3691c20373</guid><dc:creator>Naeem Maroof</dc:creator><description>&lt;p&gt;Hi Adam,&lt;/p&gt;
&lt;p&gt;Thank you for your patience.&lt;/p&gt;
&lt;p&gt;So basically you wanted to use &lt;strong&gt;ESS&lt;/strong&gt; service for temperature indication. You started with &lt;strong&gt;Peripheral_HT&lt;/strong&gt; sample, as a starting point. This sample uses &lt;strong&gt;HTS&lt;/strong&gt; service for temperature indication, and as per your provided code I could see your modifications.&lt;/p&gt;
&lt;p&gt;&lt;span style="text-decoration:underline;"&gt;The modifications you have done are:&lt;/span&gt;&lt;br /&gt;&lt;strong&gt;1)&lt;/strong&gt; Updating the name of service (from &lt;strong&gt;hts_svc&lt;/strong&gt; to &lt;strong&gt;ess_svc&lt;/strong&gt;). Two things here: either this is not required as it is just a name of your service defination, or you need to update the name in all instances (for example see the &lt;strong&gt;gatt_indicate&lt;/strong&gt; section of the code in &lt;strong&gt;hts.c&lt;/strong&gt;)&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;2)&lt;/strong&gt; Modifying the primary service from &lt;strong&gt;BT_UUID_HTS&lt;/strong&gt; to &lt;strong&gt;BT_UUID_ESS&lt;/strong&gt;. That is how we intend to use a different service. In this case Environment Sensing Service. Thats fine.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;3)&lt;/strong&gt; Modifying Gatt Characteristic by using &lt;strong&gt;BT_UUID_TEMPERATURE&lt;/strong&gt; instead of &lt;strong&gt;BT_UUID_HTS_MEASUREMENT&lt;/strong&gt;. Here, &lt;strong&gt;HTS_MEASUREMENT&lt;/strong&gt; is a &amp;quot;Temperature Measurement&amp;quot; characteristics and TEMPERATURE is &amp;quot;Temperature&amp;quot; characteristics. There is difference between their structure. I recommend&amp;nbsp;going through the details in GATT Specifications.&lt;/p&gt;
&lt;p&gt;Temperature characteristic is single (fixed length) field containing temperature value field while the Temperature Measurement characteristic is variable length structure containing flags, values, and other fields. Also, their data types (of temperature values) are different (&lt;strong&gt;int&lt;/strong&gt; vs &lt;strong&gt;float&lt;/strong&gt;).&lt;/p&gt;
&lt;p&gt;Therefore, just changing the characteristic from &lt;strong&gt;BT_UUID_HTS_MEASUREMENT&lt;/strong&gt; to &lt;strong&gt;BT_UUID_TEMPERATURE&lt;/strong&gt; would not suffice.&lt;/p&gt;
&lt;p&gt;Have at look at the &lt;strong&gt;gatt_indicate&lt;/strong&gt; section at the bottom of the &lt;strong&gt;hts.c&lt;/strong&gt;. You can see some data/value manipulations / packing. There are related to the &lt;strong&gt;HTS_MEASUREMENT&lt;/strong&gt; characteristic. You will have to modify/update this section to incorporate your proffered characteristic.&lt;/p&gt;
&lt;p&gt;I would also recommend to have a look at &lt;strong&gt;peripheral_esp&lt;/strong&gt; sample that uses ESS service along with temperature characteristic. That can also help in understanding the required modifications.&lt;/p&gt;
&lt;p&gt;Hope it helps.&lt;/p&gt;
&lt;p&gt;Regards, &lt;br /&gt;Naeem&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Changing UUID in Bluetooth: Peripheral HT sample</title><link>https://devzone.nordicsemi.com/thread/396819?ContentTypeID=1</link><pubDate>Tue, 22 Nov 2022 08:51:42 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a8e026a2-1c76-49de-8664-b5f33d3d7838</guid><dc:creator>adam_atmo</dc:creator><description>&lt;p&gt;Thank you, Naseem.&lt;/p&gt;
&lt;p&gt;Please let me know.&lt;/p&gt;
&lt;p&gt;Adam&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Changing UUID in Bluetooth: Peripheral HT sample</title><link>https://devzone.nordicsemi.com/thread/396737?ContentTypeID=1</link><pubDate>Mon, 21 Nov 2022 16:23:16 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:bc0b7172-b9f4-4de8-a558-a6e7bfc0fbf6</guid><dc:creator>Naeem Maroof</dc:creator><description>&lt;p&gt;Hi Adam,&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;I have been assigned this ticket. I will have a look into the case and come back to you.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Regards,&lt;/p&gt;
&lt;p&gt;Naeem&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>