<?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>ble data transfer</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/14818/ble-data-transfer</link><description>Hi, 
 I am using the following statements for send a string data over BLE. 
 static uint8_t Name3[BLE_NUS_MAX_DATA_LEN]= &amp;quot;xxxxxxxx&amp;quot;;
	err_code = ble_nus_string_send(&amp;amp;m_nus, Name3, 20);	
	if (err_code != NRF_ERROR_INVALID_STATE)
	{
 APP_ERROR_CHECK</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 29 Jun 2016 11:38:24 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/14818/ble-data-transfer" /><item><title>RE: ble data transfer</title><link>https://devzone.nordicsemi.com/thread/56568?ContentTypeID=1</link><pubDate>Wed, 29 Jun 2016 11:38:24 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9859aa8a-3113-4780-a3f2-44173a747d0a</guid><dc:creator>tesc</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;Fist we must distinguish BLE and the Nordic UART Service (NUS).&lt;/p&gt;
&lt;p&gt;NUS is only a service, which provides UART over BLE. Since it works as UART, it can be used as UART. Basically you send and receive a series of bytes.&lt;/p&gt;
&lt;p&gt;There are several other BLE services. Some are specified by the Bluetooth SIG, others are custom made. So in theory you could make your own service, or select an existing one, that fits with your use case. See &lt;a href="https://devzone.nordicsemi.com/tutorials/8/"&gt;BLE Services, a beginner&amp;#39;s tutorial&lt;/a&gt; for an introduction to services.&lt;/p&gt;
&lt;p&gt;If you want to use the Nordic UART Service, i.e. UART communication, you must decide how to encode your numbers. You may send integers and floats by just using their binary values, splitting them up into a series of bytes as suggested by RichieJH. Another solution is to use &lt;code&gt;sprintf()&lt;/code&gt; to create a string from the numeral value and transmit that string.&lt;/p&gt;
&lt;p&gt;Regards, Terje&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: ble data transfer</title><link>https://devzone.nordicsemi.com/thread/56557?ContentTypeID=1</link><pubDate>Wed, 29 Jun 2016 10:09:06 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0fc34957-d9e0-4032-8ae0-954c1ed9876a</guid><dc:creator>awneil</dc:creator><description>&lt;p&gt;Look at the function prototype, and read the documentation!&lt;/p&gt;
&lt;p&gt;The 2nd parameter must be a &lt;strong&gt;pointer&lt;/strong&gt;, and the third is the &lt;strong&gt;length&lt;/strong&gt; of the data that you are sending - isn&amp;#39;t it?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: ble data transfer</title><link>https://devzone.nordicsemi.com/thread/56556?ContentTypeID=1</link><pubDate>Wed, 29 Jun 2016 09:59:37 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6070530f-adc6-4924-84a2-41f726842adc</guid><dc:creator>Siva</dc:creator><description>&lt;p&gt;Suppose if I want to send the variable on ble
(float Temp = 12.345;)
Can I still use (error_Code = ble_nus_string_send(&amp;amp;m_nus,Temp,20);) ? I presume it should be a different function.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: ble data transfer</title><link>https://devzone.nordicsemi.com/thread/56567?ContentTypeID=1</link><pubDate>Wed, 29 Jun 2016 09:36:56 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7f673423-4a25-4e9b-b3d2-c08179cddafc</guid><dc:creator>awneil</dc:creator><description>&lt;p&gt;Of course, this all assumes that the OP is OK with &lt;strong&gt;binary&lt;/strong&gt; data...&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: ble data transfer</title><link>https://devzone.nordicsemi.com/thread/56561?ContentTypeID=1</link><pubDate>Wed, 29 Jun 2016 08:56:16 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:fef31b17-cb34-4a1c-8673-047b7d872e62</guid><dc:creator>awneil</dc:creator><description>&lt;p&gt;That&amp;#39;s better!&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.ibm.com/support/knowledgecenter/SSB27U_6.2.0/com.ibm.zos.r12.cbclx01/cplr068.htm"&gt;www.ibm.com/.../cplr068.htm&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: ble data transfer</title><link>https://devzone.nordicsemi.com/thread/56560?ContentTypeID=1</link><pubDate>Wed, 29 Jun 2016 08:53:41 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4b992637-3769-47e5-93df-b23083eb1789</guid><dc:creator>RichieJH</dc:creator><description>&lt;p&gt;Amended the answer above to apply bit masking and shifting.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: ble data transfer</title><link>https://devzone.nordicsemi.com/thread/56559?ContentTypeID=1</link><pubDate>Wed, 29 Jun 2016 08:34:28 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e0edcedb-0b63-41ec-b177-8d410ce382fe</guid><dc:creator>awneil</dc:creator><description>&lt;p&gt;Of course it does!!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: ble data transfer</title><link>https://devzone.nordicsemi.com/thread/56566?ContentTypeID=1</link><pubDate>Wed, 29 Jun 2016 08:21:20 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:33a991ca-1e19-401b-a729-06d6a3560168</guid><dc:creator>RichieJH</dc:creator><description>&lt;p&gt;Actually, you might be right.  I&amp;#39;ve just noticed my values never been larger than one byte so while it compiles fine and appears to work, what is happening is the value is being assigned to that array element and when putting in a value greater than one byte it is being lost.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: ble data transfer</title><link>https://devzone.nordicsemi.com/thread/56565?ContentTypeID=1</link><pubDate>Wed, 29 Jun 2016 07:43:23 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7f9a5428-4bad-4708-b7aa-b08fcb9ffb18</guid><dc:creator>RichieJH</dc:creator><description>&lt;p&gt;Of course it does, have you actually tried it?  I have and it works.  So unless my compiler and SDK has magical powers I&amp;#39;m not sure why you are insisting it doesn&amp;#39;t.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: ble data transfer</title><link>https://devzone.nordicsemi.com/thread/56564?ContentTypeID=1</link><pubDate>Wed, 29 Jun 2016 07:41:12 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e79ac742-fc7d-4559-8dfd-aa81eac222dd</guid><dc:creator>awneil</dc:creator><description>&lt;p&gt;&lt;strong&gt;No! that is &lt;em&gt;not&lt;/em&gt; the way &amp;#39;C&amp;#39; works!!&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;When you assign to Name3[x] you are just assigning to that one element - using the standard &amp;#39;C&amp;#39; conversion rules if the RHS of the assignment is not the same type as the LHS.&lt;/p&gt;
&lt;p&gt;It does &lt;strong&gt;&lt;em&gt;not&lt;/em&gt;&lt;/strong&gt; run-on to subsequent elements in the array!!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: ble data transfer</title><link>https://devzone.nordicsemi.com/thread/56563?ContentTypeID=1</link><pubDate>Wed, 29 Jun 2016 07:24:15 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1e7d44b4-1530-4e48-92a6-b4077d101fce</guid><dc:creator>RichieJH</dc:creator><description>&lt;p&gt;You &lt;strong&gt;do not&lt;/strong&gt; have to copy each byte individually and this does work.&lt;/p&gt;
&lt;p&gt;unint32_t some_int = 100;
Name3[0] = some_int;&lt;/p&gt;
&lt;p&gt;The next 4 bytes in the array will be taken up with some_int with the value of 100.  Not the most efficient way to store the value of 100, but the principle works.  Remember Name3 is a Uint8_t array.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: ble data transfer</title><link>https://devzone.nordicsemi.com/thread/56562?ContentTypeID=1</link><pubDate>Wed, 29 Jun 2016 07:00:56 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d71003e2-58e0-4fa3-a504-4a945beb8ba0</guid><dc:creator>awneil</dc:creator><description>&lt;p&gt;That won&amp;#39;t work - you can&amp;#39;t just do&lt;/p&gt;
&lt;pre&gt;&lt;code&gt; Name3[1] = uint32_t some_int; 
 Name3[5] = uint16_t something_else; 
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;You have to copy each byte individually&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: ble data transfer</title><link>https://devzone.nordicsemi.com/thread/56558?ContentTypeID=1</link><pubDate>Tue, 28 Jun 2016 23:16:08 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8d7c73c7-eba2-45aa-bb54-567839b39531</guid><dc:creator>RichieJH</dc:creator><description>&lt;p&gt;So assume you want to send a uint16_t value of say 10000.  This is of course two bytes and you must assign each byte of value to each element of the array Name3.  One fairly easy way to do this is bit masking and shifting.  So do this:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;Name3[0] = (value &amp;amp; 0xFF00) &amp;gt;&amp;gt; 8;
Name3[1] = (value &amp;amp; 0x00FF);
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Now say value was a unit32_t, which is 4 bytes long, then do this&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;Name3[0] = (value &amp;amp; 0xFF000000) &amp;gt;&amp;gt; 24;
Name3[1] = (value &amp;amp; 0x00FF0000) &amp;gt;&amp;gt; 16;
Name3[2] = (value &amp;amp; 0x0000FF00) &amp;gt;&amp;gt; 8;
Name3[3] = (value &amp;amp; 0x000000FF);
&lt;/code&gt;&lt;/pre&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: ble data transfer</title><link>https://devzone.nordicsemi.com/thread/56555?ContentTypeID=1</link><pubDate>Tue, 28 Jun 2016 19:44:35 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:785a1862-d3cc-4167-bd9b-a7cc897d527a</guid><dc:creator>awneil</dc:creator><description>&lt;blockquote&gt;
&lt;p&gt;I am unable to send integers and floating values&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;What did you actually try?&lt;/p&gt;
&lt;p&gt;The &lt;strong&gt;Nordic UART Service&lt;/strong&gt; - like a real UART - actually just sends bytes:  it neither knows nor cares whether those bytes are to be interpreted as a string, an &amp;quot;integer&amp;quot; (whatever that might mean), a &amp;quot;floating value&amp;quot; or whatever.&lt;/p&gt;
&lt;p&gt;The documentation is here:&lt;/p&gt;
&lt;p&gt;&lt;a href="https://developer.nordicsemi.com/nRF5_SDK/nRF51_SDK_v8.x.x/doc/8.0.0/s110/html/a01011.html#gacaf254f54b8edc3d2558845b89a93e4c"&gt;developer.nordicsemi.com/.../a01011.html&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;You just tell it where the data starts (that&amp;#39;s the pointer), and how many bytes to send ...&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>