<?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>Board is restarting when trying to convert double to uint8_t*</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/95471/board-is-restarting-when-trying-to-convert-double-to-uint8_t</link><description>Hi 
 
 I am currently merging mqtt_simple and location example using my custom board based on nrf9160. Currently. I am able to connect to mqtt and also retrieving location using Cellular Service (maybe GNSS timeout because my friend test it at indoor</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 12 Jan 2023 14:35:05 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/95471/board-is-restarting-when-trying-to-convert-double-to-uint8_t" /><item><title>RE: Board is restarting when trying to convert double to uint8_t*</title><link>https://devzone.nordicsemi.com/thread/404597?ContentTypeID=1</link><pubDate>Thu, 12 Jan 2023 14:35:05 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:be795c23-6ddf-42c1-aacd-c3977c0a9355</guid><dc:creator>azwawe</dc:creator><description>&lt;p&gt;Hi guys,&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;I manage to convert double to char using sprintf. The issue is size is too big, now I change it to 32 now it works.&lt;/p&gt;
&lt;p&gt;But I got an issue, there is a time that my value result is 0.000000 I dont know why. When I print previous value, there is no issue, but when I double check the result, it is 0.00000. Also another thing, there is a time that I can convert value properly. So there is a time the value is weird, and also there is a time that looks correct.&lt;/p&gt;
&lt;p&gt;below is the code that I use&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;			printk(&amp;quot;cellular service.\n&amp;quot;);

			printk(&amp;quot;Publishing longitude %f &amp;quot;, event_data-&amp;gt;location.longitude);
			sprintf(temp_lon, &amp;quot; %f &amp;quot;, event_data-&amp;gt;location.longitude);
			printk(&amp;quot;value : %s &amp;quot;, temp_lon);
			err = data_publish(&amp;amp;client, MQTT_QOS_1_AT_LEAST_ONCE, temp_lon, sizeof(temp_lon), TOPIC_LOC_CELLULER_LON);
			if (err) {printk(&amp;quot;ERR data_publish (longitude) : %d&amp;quot;, err);} else {printk(&amp;quot; -- success.\n&amp;quot;);}

			printk(&amp;quot;Publishing latitude %f &amp;quot;, event_data-&amp;gt;location.latitude);
			sprintf(temp_lat, &amp;quot; %f &amp;quot;, event_data-&amp;gt;location.latitude);
			printk(&amp;quot;value : %s &amp;quot;, temp_lat);
			err = data_publish(&amp;amp;client, MQTT_QOS_1_AT_LEAST_ONCE, temp_lat, sizeof(temp_lat), TOPIC_LOC_CELLULER_LAT);
			if (err) {printk(&amp;quot;ERR data_publish (longitude) : %d&amp;quot;, err);} else {printk(&amp;quot; -- success.\n&amp;quot;);}

			printk(&amp;quot;Publishing both information &amp;quot;);
			sprintf(temp_all, &amp;quot; %f,%f &amp;quot;, event_data-&amp;gt;location.latitude, event_data-&amp;gt;location.longitude);
			printk(&amp;quot;value : %s &amp;quot;, temp_all);
			err = data_publish(&amp;amp;client, MQTT_QOS_1_AT_LEAST_ONCE, temp_all, sizeof(temp_all), TOPIC_LOC_CELLULER);
			if (err) {printk(&amp;quot;ERR data_publish (both) : %d&amp;quot;, err);} else {printk(&amp;quot; -- success.\n&amp;quot;);}	&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;And below is the result. You can see there is a time that I got 0.000000 and also there is a time that I got a right value.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;Publishing Location using cellular service.
Publishing longitude 46.693770 value :  0.000000   -- success.
Publishing latitude  24.791375 value :  0.000000   -- success.
Publishing both information value :  0.000000,46.693370   -- success.
Requesting location with the default configuration...&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Anybody have idea about this? thank you so much for your help.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Board is restarting when trying to convert double to uint8_t*</title><link>https://devzone.nordicsemi.com/thread/404592?ContentTypeID=1</link><pubDate>Thu, 12 Jan 2023 14:26:01 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:917366fc-91d9-43b1-a07a-3e510635c459</guid><dc:creator>Hakon</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;can you share the prj.conf file?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Board is restarting when trying to convert double to uint8_t*</title><link>https://devzone.nordicsemi.com/thread/403942?ContentTypeID=1</link><pubDate>Mon, 09 Jan 2023 23:26:18 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2e107001-f4ad-4116-b4bb-878a52bedd0b</guid><dc:creator>azwawe</dc:creator><description>&lt;p&gt;Thanks for your contribution. For CONFIG_MQTT_MESSAGE_BUFFER_SIZE, I set it as 128 bytes, it is larger than the message. So not sure if that is the issue.&lt;/p&gt;
&lt;p&gt;Yes, probably it is a memory fail.&lt;/p&gt;
&lt;p&gt;For lattitude, yes it is like that, no issue with typo.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Anyway, thanks for the solution, really appreciate it, but still doesnt work. Looks like it is restarting when executing sprintf.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Board is restarting when trying to convert double to uint8_t*</title><link>https://devzone.nordicsemi.com/thread/403803?ContentTypeID=1</link><pubDate>Mon, 09 Jan 2023 10:49:07 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:03e33ce7-3f65-40c6-9a10-d956589c8cc6</guid><dc:creator>Daniel Chisholm</dc:creator><description>&lt;p&gt;&amp;quot;%.06f&amp;quot; is for a single precision (&amp;quot;float&amp;quot;) type, you&amp;#39;ll want &amp;quot;%.06lf&amp;quot; for a double.&amp;nbsp; Not sure if this could possibly cause a fault or exception.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Board is restarting when trying to convert double to uint8_t*</title><link>https://devzone.nordicsemi.com/thread/403782?ContentTypeID=1</link><pubDate>Mon, 09 Jan 2023 09:30:32 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c8191b4c-799e-420b-87af-2396f497ede2</guid><dc:creator>Torje</dc:creator><description>&lt;p&gt;Hi,&lt;br /&gt;Are you sure&amp;nbsp;CONFIG_MQTT_MESSAGE_BUFFER_SIZE is big enough? Can&amp;#39;t see any other obvious reasons why it should fail based on these lines. Do you not have to convert the message after filling the buffer_lattitude? My memory might fail me, but it could be a hint. Maybe its failing on the next line? Try this:&lt;/p&gt;
&lt;div&gt;
&lt;div&gt;
&lt;div&gt;
&lt;div&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;pre class="ui-code" data-mode="text"&gt;char buffer_lattitude[CONFIG_MQTT_MESSAGE_BUFFER_SIZE];
sprintf(buffer_lattitude, &amp;quot;%.06f&amp;quot;, event_data-&amp;gt;location.lattitude);
struct mqtt_utf8 message;
message.utf8 = (uint8_t *)buffer_lattitude;
message.size = (uint32_t)strlen(buffer_lattitude)
data_publish(&amp;amp;client, MQTT_QOS_1_AT_LEAST_ONCE, message.utf8, message.size, TOPIC_LOC_CELLULER_LAT);&lt;/pre&gt;&lt;/div&gt;
&lt;div&gt;&lt;/div&gt;
&lt;div&gt;Edit: Its not just a typo? &amp;quot;location.lattitude&amp;quot; should be &amp;quot;location.latitude&amp;quot;?&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>