<?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>Transmit number via ble</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/18147/transmit-number-via-ble</link><description>Hello!
I have
uint32_t adc_value (from external ADC converter)
And try to send it value through ble. My code: 
 main.c:
.... 
 for (;;)
 {
	Weighing();
 power_manage(); 
 if(adc_value) 
 {
 SEGGER_RTT_printf(0, &amp;quot;%d\n&amp;quot;, adc_value);
 ble_adc_send</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Mon, 05 Dec 2016 04:27:39 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/18147/transmit-number-via-ble" /><item><title>RE: Transmit number via ble</title><link>https://devzone.nordicsemi.com/thread/70041?ContentTypeID=1</link><pubDate>Mon, 05 Dec 2016 04:27:39 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c474dcd7-7faf-4e6e-8d32-7c005a430f93</guid><dc:creator>Stas</dc:creator><description>&lt;p&gt;This way works. Thank you so much.
PS I know transmit adc value (intead of changes rarely human readable value) over the air is not a good idea - but it&amp;#39;s just for learning)&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Transmit number via ble</title><link>https://devzone.nordicsemi.com/thread/70040?ContentTypeID=1</link><pubDate>Sun, 04 Dec 2016 14:09:52 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:cba3d815-5cbe-4ee3-a6a7-5a93232f5451</guid><dc:creator>AD1170</dc:creator><description>&lt;p&gt;Ok, than you can try to send the value as ASCII string.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;char buffer[10];

sprintf(buffer, &amp;quot;%d&amp;quot;, *adc_value);

uint16_t length = strlen(buffer);

 hvx_params.p_data = (uint8_t *) buffer;
 hvx_params.p_len  = &amp;amp;length;
  
...
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Now your app can receive the value as ASCII string.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Transmit number via ble</title><link>https://devzone.nordicsemi.com/thread/70039?ContentTypeID=1</link><pubDate>Sun, 04 Dec 2016 11:06:02 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e2331ce2-6e3f-4c1e-9b03-ee3d36594de3</guid><dc:creator>Stas</dc:creator><description>&lt;p&gt;Thanks for your example. Indeed I&amp;#39;ve only started to learn android programming (on Java by the way). Now I just make a simple app in probable the highest level way of android programming - &lt;a href="http://ble-test.appinventor.mit.edu"&gt;ble-test.appinventor.mit.edu&lt;/a&gt; . In that app I can get string value via ble and it work good with get/send string value (the same like in nrf connect app) Here&amp;#39;s my code :) &lt;a href="http://ybex.com/d/w1vcqz9gpumalqb10hqxroupa32vuhtmtew89hfv.html"&gt;ybex.com/.../w1vcqz9gpumalqb10hqxroupa32vuhtmtew89hfv.html&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Transmit number via ble</title><link>https://devzone.nordicsemi.com/thread/70038?ContentTypeID=1</link><pubDate>Sun, 04 Dec 2016 09:57:51 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:307678f9-3567-4492-9886-8bcc5d34ab47</guid><dc:creator>AD1170</dc:creator><description>&lt;p&gt;Ok, for example, i use the following code for received characteristiic data in an android app (written in c++ using Qt):&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;typedef union ui32u_i {
    uint32_t Value;     
    uint8_t  Byte[4];	
} UI32U;

//
// in the slot for &amp;quot;characteristic data chaged&amp;quot; 
//

void MainWindow::on_characteristicChanged(QLowEnergyCharacteristic ch, QByteArray data) // data is the array with the charaterisic data
{
UI32U u32;

  if(ch.uuid().toUInt32() == ADC_CHRACTERISTIC){
      u32.Value = 0;
      for(int i = 0; i &amp;lt; sizeof(uint32_t); i++) // or use memcpy()
          u32.Byte[i] = data[i];

        ADC_Value = u32.Value; // assign the ADC value here, the &amp;quot;ADC_Value&amp;quot; is global or part of &amp;quot;MainWindow&amp;quot; in this case 
                                            // the ADC value is now correct assigned and you can call utoa(), sprintf() or any other conversion fuction
                                            // or send the new value using a Qt event (next line)
        emit new_adc_value(u32.Value);
    }
}


   ...

//
// print the value on an GUI element (QLabel in this case)
//
void MainWindow::On_new_adc_value(uint32_t value)
{
  ui-&amp;gt;label-&amp;gt;setText(QString().sprintf(&amp;quot;%d&amp;quot;, value));
}
&lt;/code&gt;&lt;/pre&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Transmit number via ble</title><link>https://devzone.nordicsemi.com/thread/70037?ContentTypeID=1</link><pubDate>Sun, 04 Dec 2016 09:39:46 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0e02d63b-5e09-49fb-8fe0-7c5c9a6a5742</guid><dc:creator>Stas</dc:creator><description>&lt;p&gt;My receiver site is just read string characteristic from nus service. (Actually I think it&amp;#39;s the same as NRF connect app, Because in both of them the result is the same)&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Transmit number via ble</title><link>https://devzone.nordicsemi.com/thread/70036?ContentTypeID=1</link><pubDate>Sun, 04 Dec 2016 09:37:47 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0c2f7b88-8fc1-4883-82c9-45679d517f10</guid><dc:creator>Stas</dc:creator><description>&lt;p&gt;uint32_t ble_adc_send(ble_nus_t * p_nus, uint32_t *adc_value)
{
ble_gatts_hvx_params_t hvx_params;&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;    VERIFY_PARAM_NOT_NULL(p_nus);

    if ((p_nus-&amp;gt;conn_handle == BLE_CONN_HANDLE_INVALID) || (!p_nus-&amp;gt;is_notification_enabled))
    {
        return NRF_ERROR_INVALID_STATE;
    }
		uint8_t buffer[4];
		uint16_t length = uint32_encode(*adc_value, buffer);
    if (length &amp;gt; BLE_NUS_MAX_DATA_LEN)
    {
        return NRF_ERROR_INVALID_PARAM;
    }
		
    memset(&amp;amp;hvx_params, 0, sizeof(hvx_params));

    hvx_params.handle = p_nus-&amp;gt;rx_handles.value_handle;
    hvx_params.p_data = buffer;
    hvx_params.p_len  = &amp;amp;length;
    hvx_params.type   = BLE_GATT_HVX_NOTIFICATION;

    return sd_ble_gatts_hvx(p_nus-&amp;gt;conn_handle, &amp;amp;hvx_params);
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;just the same result.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Transmit number via ble</title><link>https://devzone.nordicsemi.com/thread/70035?ContentTypeID=1</link><pubDate>Sat, 03 Dec 2016 18:12:58 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0b2a79ed-87ab-4dc3-a2a7-c34abff4b79f</guid><dc:creator>AD1170</dc:creator><description>&lt;p&gt;Try the following:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;...
uint8_t buffer[4];

uint16_t length = uint32_encode(*adc_value, buffer);
...
hvx_params.p_data = buffer;
hvx_params.p_len  = &amp;amp;length;
...
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Take a look at uint32_encode() (app_util.h&amp;quot;) to see how the bytes are ordered. In this way, the byte order is defined and you can reorder the bytes on the receiver side. If you dont know how, just ask.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Transmit number via ble</title><link>https://devzone.nordicsemi.com/thread/70034?ContentTypeID=1</link><pubDate>Sat, 03 Dec 2016 17:47:01 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:99ee4210-59c1-4ffa-a709-b523db2eebf2</guid><dc:creator>Stas</dc:creator><description>&lt;p&gt;The receiver side is nrf connect app where I just read the characteristic value. Also I use my own simple android app just for read/write characteristics from ble. Both of them work properly with getting string like e.g via UART, but with number I&amp;#39;ve met some issues.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Transmit number via ble</title><link>https://devzone.nordicsemi.com/thread/70033?ContentTypeID=1</link><pubDate>Sat, 03 Dec 2016 17:38:19 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2e78cc14-0142-48e5-a71a-32c0be302deb</guid><dc:creator>AD1170</dc:creator><description>&lt;p&gt;Can you provide a code snippet from the receiver side?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Transmit number via ble</title><link>https://devzone.nordicsemi.com/thread/70032?ContentTypeID=1</link><pubDate>Sat, 03 Dec 2016 15:34:46 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:71cfb4f5-6349-4ee6-a715-9d686cf43b5e</guid><dc:creator>Stas</dc:creator><description>&lt;p&gt;Thanks for answer. Actually I used length equals 4 , but the result was the same&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Transmit number via ble</title><link>https://devzone.nordicsemi.com/thread/70031?ContentTypeID=1</link><pubDate>Sat, 03 Dec 2016 14:51:04 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:97155ebc-6625-4547-9df3-671b3b97aba7</guid><dc:creator>AD1170</dc:creator><description>&lt;p&gt;Hello,
the length of an uint32_t is 4 not 10. So you should use sizeof(uint32_t) to initialize the &amp;quot;length&amp;quot; variable. I think you want to convert the uint32_t ADC value on the receiver side. If you correct the length, your conversion with ultoa() should also work.&lt;/p&gt;
&lt;p&gt;Regards&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>