<?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>Display float data in nRF Connect</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/108696/display-float-data-in-nrf-connect</link><description>Hi. 
 I transmit latitude and longitude data via bluetooth to my smartphone. 
 But in nRF Connect the data are displayed in HEX format (see screenshot), although in the terminal output the latitude and longitude are displayed correctly in float format</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 29 Feb 2024 08:27:05 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/108696/display-float-data-in-nrf-connect" /><item><title>RE: Display float data in nRF Connect</title><link>https://devzone.nordicsemi.com/thread/471470?ContentTypeID=1</link><pubDate>Thu, 29 Feb 2024 08:27:05 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a01f40a4-0e63-4650-8679-ee4f59ae851e</guid><dc:creator>backstreet.devisor</dc:creator><description>&lt;p&gt;Thank you very much Jorgen for your time in solving this problem!&lt;/p&gt;
&lt;p&gt;Now everything works as it should.&lt;/p&gt;
&lt;p&gt;You helped me a lot with my project, thanks again!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Display float data in nRF Connect</title><link>https://devzone.nordicsemi.com/thread/471418?ContentTypeID=1</link><pubDate>Wed, 28 Feb 2024 20:41:58 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f46089e7-2825-4741-afc6-ebacfd7186ca</guid><dc:creator>J&amp;#248;rgen Holmefjord</dc:creator><description>&lt;p&gt;This code must certainly generate warnings in your build, does it not?&lt;/p&gt;
&lt;p&gt;You are trying to pass a char array to a uint32_t parameter. &amp;quot;&lt;span&gt;mybuf&amp;quot; will contain a pointer to the RAM location where the data is stored. In&amp;nbsp;&lt;/span&gt;my_lbs_send_latitude_notify(), you have one input variable, which is not a pointer. The value assigned to this parameter will be stored in a new local variable inside the function, not a reference to the external data. When you pass the mybuf variable to this funtion, it will copy the RAM address where the buffer i stored into&amp;nbsp;latitude_value, not the data stored in mybuf. When you try to pass the reference to&amp;nbsp;latitude_value (&amp;amp;latitude_value) to&amp;nbsp;bt_gatt_notify, this will be the address of the local variable. The sizeof function will also just report the size of an uint32_t, not the size of the buffer, since it is not aware that a buffer was passed to the variable.&lt;/p&gt;
&lt;p&gt;If you print the values, it should look something like this:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;mybuf=0x20005244
&amp;amp;mybuf=0x20005244
sizeof(mybuf)=8

latitude_value=0x20005244
&amp;amp;latitude_value=0x2000522c
sizeof(latitude_value)=4&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;You should modify the&amp;nbsp;my_lbs_send_latitude_notify() function to take a pointer and buffer length as input, and pass this further to the&amp;nbsp;bt_gatt_notify() function:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;int my_lbs_send_latitude_notify(uint32_t *latitude_value_string, uint32_t latitude_string_length)
{
	if (!notify_latitude_enabled) {
		return -EACCES;
	}

	return bt_gatt_notify(NULL, &amp;amp;my_lbs_svc.attrs[10], latitude_value_string, latitude_string_length);
}

void send_data(void)
{
    float x = 35.120275;
    char mybuf[8] = {0};
    
    gcvt(x, 8, mybuf);
    my_lbs_send_latitude_notify(mybuf, sizeof(mybuf));
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Best regards,&lt;br /&gt;Jørgen&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Display float data in nRF Connect</title><link>https://devzone.nordicsemi.com/thread/471373?ContentTypeID=1</link><pubDate>Wed, 28 Feb 2024 15:22:51 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:abb6cd37-8c07-447b-951f-18d0340cd90a</guid><dc:creator>backstreet.devisor</dc:creator><description>&lt;p&gt;Function&amp;nbsp;&lt;span&gt;my_lbs_send_latitude_notify():&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;pre class="ui-code" data-mode="text"&gt;int my_lbs_send_latitude_notify(uint32_t latitude_value)
{
	if (!notify_latitude_enabled) {
		return -EACCES;
	}

	return bt_gatt_notify(NULL, &amp;amp;my_lbs_svc.attrs[10], &amp;amp;latitude_value, sizeof(latitude_value));
}&lt;/pre&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Debug:&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;img style="max-height:240px;max-width:320px;" alt=" " src="https://devzone.nordicsemi.com/resized-image/__size/640x480/__key/communityserver-discussions-components-files/4/2845.Debug.jpg" /&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;In the code I wrote both options:&lt;br /&gt;1. my_lbs_send_latitude_notify(mybuf);&lt;br /&gt;2. my_lbs_send_latitude_notify(&amp;amp;mybuf);&lt;/p&gt;
&lt;p&gt;In text format both variants were printed incorrectly&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: Display float data in nRF Connect</title><link>https://devzone.nordicsemi.com/thread/471369?ContentTypeID=1</link><pubDate>Wed, 28 Feb 2024 14:58:33 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d46119fd-c7d5-4cba-9941-2b6e9011305c</guid><dc:creator>J&amp;#248;rgen Holmefjord</dc:creator><description>&lt;p&gt;How is the function&amp;nbsp;my_lbs_send_latitude_notify() implemented?&lt;/p&gt;
&lt;p&gt;The HEX data in nRF Connect looks suspiciously similar to a RAM address (0x20008308). Are you sure you are sending the data and not the address of the buffer?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Display float data in nRF Connect</title><link>https://devzone.nordicsemi.com/thread/471361?ContentTypeID=1</link><pubDate>Wed, 28 Feb 2024 14:45:15 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c21d09fc-e2b9-4378-9b87-d04d69f970cb</guid><dc:creator>backstreet.devisor</dc:creator><description>&lt;p&gt;Hi.&lt;/p&gt;
&lt;p&gt;I tried to implement this task through the gcvt() function, but the result is not displayed correctly.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;float x = 35.120275;
char mybuf[8] = {0};

gcvt(x, 8, mybuf);
my_lbs_send_latitude_notify(mybuf);&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;img style="max-height:240px;max-width:320px;" alt=" " src="https://devzone.nordicsemi.com/resized-image/__size/640x480/__key/communityserver-discussions-components-files/4/1_5F00_Screen_5F00_nRF-Connect.jpg" /&gt;&lt;/p&gt;
&lt;p&gt;But when I try to send just a single character, it displays correctly.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;char x = &amp;#39;A&amp;#39;;
my_lbs_send_latitude_notify(x);&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Can you please tell me where I am making a mistake?&lt;/p&gt;
&lt;p&gt;Thanks.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Display float data in nRF Connect</title><link>https://devzone.nordicsemi.com/thread/471252?ContentTypeID=1</link><pubDate>Wed, 28 Feb 2024 11:04:45 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f97dae08-f431-4b68-96eb-cdd36fa5b57a</guid><dc:creator>J&amp;#248;rgen Holmefjord</dc:creator><description>[quote user="backstreet.devisor"]Can you please tell me if it is possible to convert a floating point number to a string in the program and then transmit this string to the phone and display it in text format in nRF Connect?[/quote]
&lt;p&gt;Yes, you can use C library function &lt;a href="https://www.tutorialspoint.com/c_standard_library/c_function_sprintf.htm"&gt;sprintf&lt;/a&gt;() with %f format to convert the float to a string and send the string. If you do not see the float being converted correctly, you might need to build the application with float support for printf. Note that the size of the string might exceed the size of the float once converted.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;To change the display type in nRF Connect, long press the characteristic, press the &amp;quot;edit&amp;quot; button on the top (pencil), and select TEXT in the dialog that show up.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Display float data in nRF Connect</title><link>https://devzone.nordicsemi.com/thread/471115?ContentTypeID=1</link><pubDate>Tue, 27 Feb 2024 17:23:47 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d961d156-a8ad-4630-8b2d-ca82468fd3d0</guid><dc:creator>backstreet.devisor</dc:creator><description>&lt;p&gt;Hi, Jorgen.&amp;nbsp;Thank you for your response.&lt;/p&gt;
&lt;p&gt;I don&amp;#39;t plan to write a new phone app yet. I need to display coordinates in nRF Connect Mobile in some way.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Can you please tell me if it is possible to convert a floating point number to a string in the program and then transmit this string to the phone and display it in text format in nRF Connect?&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;Or is it still not possible to display the coordinates correctly in this way?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Display float data in nRF Connect</title><link>https://devzone.nordicsemi.com/thread/471110?ContentTypeID=1</link><pubDate>Tue, 27 Feb 2024 17:08:54 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1e13553e-87b9-4f76-bc01-3cb267bf23ce</guid><dc:creator>J&amp;#248;rgen Holmefjord</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;As far as I can see, nRF Connect for Mobile supports only HEX and ASCII (Text) as value field. If you want other data type, you need to write your own application or convert it manually on the phone.&lt;/p&gt;
&lt;p&gt;Best regards,&lt;br /&gt;Jørgen&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>