<?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>Send a float</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/6962/send-a-float</link><description>I want to send a float as a value of a characteristic. 
 As I know is this all what I have to change to send a float... 
 float temperature;

uint16_t len = 20;

attr_char_value.init_len = 4;
attr_char_value.init_offs = 0;
attr_char_value.max_len</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 12 May 2015 08:47:41 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/6962/send-a-float" /><item><title>RE: Send a float</title><link>https://devzone.nordicsemi.com/thread/24538?ContentTypeID=1</link><pubDate>Tue, 12 May 2015 08:47:41 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:dfea5e35-33d4-4d3b-a577-f8e4da80d762</guid><dc:creator>Inspectron</dc:creator><description>&lt;p&gt;Offset is 0; and I changed the length to 4 bytes. Now I send 0x00002710 but on the MCP I will recieve Value:10-00-00-00. I will open a new case for this problem&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Send a float</title><link>https://devzone.nordicsemi.com/thread/24547?ContentTypeID=1</link><pubDate>Tue, 12 May 2015 07:44:38 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:46c68406-4a89-49a2-a7fa-44c600483816</guid><dc:creator>RK</dc:creator><description>&lt;p&gt;I&amp;#39;m not familiar with the master control panel so I don&amp;#39;t know what to expect, that doesn&amp;#39;t look right however. I&amp;#39;d probably check the offset, check the length, temporarily change it to sending all 4 bytes instead of 2 and send a known value like 0x12345678 to see if you can see a pattern in what&amp;#39;s going to the other side&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Send a float</title><link>https://devzone.nordicsemi.com/thread/24546?ContentTypeID=1</link><pubDate>Tue, 12 May 2015 07:03:59 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f09af839-4826-4407-be68-9379e7a74db2</guid><dc:creator>Inspectron</dc:creator><description>&lt;p&gt;@RK Now I do like you suggest. I will send the raw value as integer. My temperature has the value 0x00000A38 = 26.16°C. But on the Master Control Panel I will recieve Value:38-00. Why is the A missing?
It looks like the value is &amp;lt;&amp;lt;2. But I dont know why it should be shifted...&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Send a float</title><link>https://devzone.nordicsemi.com/thread/24545?ContentTypeID=1</link><pubDate>Mon, 11 May 2015 11:35:14 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8b489c5e-1f16-4438-9e52-0dd148aee720</guid><dc:creator>RK</dc:creator><description>&lt;p&gt;1853 only requires 2 bytes, not 3. 2 bytes gives you everything from 0 - 65535. 18.53 as a string would be 5 bytes, one for each character (if you didn&amp;#39;t send the final \0 which you don&amp;#39;t really need).&lt;/p&gt;
&lt;p&gt;But all of that requires converting things on the nrf51822 chip to float, then &amp;#39;printing&amp;#39; it to a string, all of which it can do but it&amp;#39;s lots of library code, lots of floating point emulation and all on the low power device. Why don&amp;#39;t you just send the raw value you read from the sensor, which is probably a 16 or 32 bit integer and do all the work on the receiving end? Your code will be smaller, will run quicker and use less power.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Send a float</title><link>https://devzone.nordicsemi.com/thread/24544?ContentTypeID=1</link><pubDate>Mon, 11 May 2015 11:28:48 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d1cf9eb3-845c-4d13-8751-53fb8e1ecd99</guid><dc:creator>Inspectron</dc:creator><description>&lt;p&gt;My first idea was to convert the float to an integer. And then do divide by 100 on the side of the host. But send the value as string is also a good solution! If the temp has the value 18.53°C. This would be 1853 as integer. So I would need 3 Bytes. But I need reserve for higher temperature so that would be 4 Bytes. Is my calculation right? How many Bytes would I have to send for 18.53 as string?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Send a float</title><link>https://devzone.nordicsemi.com/thread/24543?ContentTypeID=1</link><pubDate>Mon, 11 May 2015 09:54:27 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a7184f21-025a-479d-8c8c-d95e53a44da1</guid><dc:creator>Alex</dc:creator><description>&lt;p&gt;You need to choose the format to send depending on the max value. Either send float and don&amp;#39;t do any conversion in nRF51 but you may need to do the conversion on host side. Or convert your float to integer. for example 13.273 will become 1327, then you just /100 on the host to display result. You can also choose to send string &amp;quot;13.273&amp;quot; if you want. In that case nRF51 will do sprintf and host will just display the string. In any case sd_ble_gatts_value_set will set new array of bytes in characteristic, it is up to you how to represent data and number of bytes you will use in the end.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Send a float</title><link>https://devzone.nordicsemi.com/thread/24542?ContentTypeID=1</link><pubDate>Mon, 11 May 2015 09:47:00 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:bb9ae7eb-4724-460d-902e-ccade948477a</guid><dc:creator>Inspectron</dc:creator><description>&lt;p&gt;If I choose the way with sd_ble_gatts_value_set(). How can I send a float with 2 dots after the comma? I mean do I have to split the value in Bytes or will the sd_ble_gatts_value_set function do that for me. It doesnt have to be exatcly 2 dots after the comma. It can be also the hole float. But 2 dots after the comma are minimum.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Send a float</title><link>https://devzone.nordicsemi.com/thread/24541?ContentTypeID=1</link><pubDate>Mon, 11 May 2015 08:24:37 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:dba8099d-c87f-40b7-ad34-f020667ab137</guid><dc:creator>Alex</dc:creator><description>&lt;p&gt;Correct. The only small differences can be depending on your code in nRF51. For example if notification is not enabled and nRF51 tries to send data you may see call of APP_ERROR_CHECK() in some examples which may reset the chip in debug mode.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Send a float</title><link>https://devzone.nordicsemi.com/thread/24540?ContentTypeID=1</link><pubDate>Mon, 11 May 2015 08:03:29 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f52098eb-fad4-4153-9309-1aa1a0af4828</guid><dc:creator>Inspectron</dc:creator><description>&lt;p&gt;Oh very interesting! I didnt know that!! So there are two ways to send information from nRF51 to host. One way is to recieve a READ from the host. In this case the host reads the value of the Characterstic. The value of the characteristic will only be changed if I set a new value with sd_ble_gatts_value_set().&lt;/p&gt;
&lt;p&gt;But there is another way if I want that the value of the characteristic is automatically updated. The nRF51 will send the value of the Characteristic all the time. But the host will only recieve the value of the characteristic when the nRF51 recieves a notification or indication from the host.&lt;/p&gt;
&lt;p&gt;Do I understand something wrong?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Send a float</title><link>https://devzone.nordicsemi.com/thread/24548?ContentTypeID=1</link><pubDate>Mon, 11 May 2015 07:42:16 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a658a2ce-48ad-483a-a822-08903f02023d</guid><dc:creator>Alex</dc:creator><description>&lt;p&gt;Regarding the size, in your case &amp;quot;len&amp;quot; is the number of bytes you are sending, so set to 4. Regarding notification, there are two way of exchanging data between nRF51 and the host(for example android device). One is to change temperature inside nRF51 but the host won&amp;#39;t know about it. In this case host has to read data periodically but you don&amp;#39;t use sd_ble_gatts_hvx() in nRF51. Instead you update value by sd_ble_gatts_value_set(). Another way is to use sd_ble_gatts_hvx() in nRF51 and data will be sent automatically to the host so host doesn&amp;#39;t need to read it. But host has to enable notification or indication of that characteristics before nRF51 send data.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Send a float</title><link>https://devzone.nordicsemi.com/thread/24539?ContentTypeID=1</link><pubDate>Mon, 11 May 2015 06:28:04 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:06337ec2-8d93-4ffc-bcf2-cb178ef9d30b</guid><dc:creator>Inspectron</dc:creator><description>&lt;p&gt;Should I change the size to maximum? I dont understand what you mean with &lt;em&gt;the host didn&amp;#39;t enable notification for that characteristic after connection and before you send data by sd_ble_gatts_hvx()&lt;/em&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Send a float</title><link>https://devzone.nordicsemi.com/thread/24537?ContentTypeID=1</link><pubDate>Fri, 08 May 2015 15:09:55 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ef14d429-9d82-4060-b7a6-440e3cfcc97e</guid><dc:creator>Alex</dc:creator><description>&lt;p&gt;First of all you are adding characteristic with exact size 4. It means that you have to set len = 4 while sending data. But your original problem most likely in the fact that the host didn&amp;#39;t enable notification for that characteristic after connection and before you send data by sd_ble_gatts_hvx()&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>