<?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>Sending data array over ble nus</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/89244/sending-data-array-over-ble-nus</link><description>Hi, 
 I&amp;#39;m trying to send an data array over ble nus. 
 
 This didn&amp;#39;t work. 
 I&amp;#39;m also getting this warning. 
 
 I&amp;#39;m doing something wrong, but I don&amp;#39;t know what. Do I also have to change the receiving part of the central device to receive the data array</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Fri, 24 Jun 2022 12:49:59 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/89244/sending-data-array-over-ble-nus" /><item><title>RE: Sending data array over ble nus</title><link>https://devzone.nordicsemi.com/thread/374157?ContentTypeID=1</link><pubDate>Fri, 24 Jun 2022 12:49:59 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e832ab28-463f-4605-8ac8-b574b7a4935d</guid><dc:creator>AHaug</dc:creator><description>&lt;p&gt;Hi Ahmed,&lt;br /&gt;&lt;br /&gt;Edvin will be out of office for a few weeks and I will be handling this case in the meanwhile.&lt;/p&gt;
[quote user="Edvin Holmseth"]&lt;p&gt;Try to print the content of the&amp;nbsp;data_array[] array in your log, or look at it in a debug session.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;What do you expect the data_array to look like? What should be in data_array[0], data_array[1], data_array[2] and data_array[3]? Hint: It only holds a single uint8_t value in each of the elements, since it is a uint8_t array.&lt;/p&gt;[/quote]
&lt;p&gt;Did you try to print the contents in a log or in a debug session? Did they look as expected? If you are not too familiar with pointers and arrays in C, I would recommend you follow some online resources such as&amp;nbsp;&lt;a href="https://www.programiz.com/c-programming/c-pointers-arrays"&gt;this one&lt;/a&gt;&amp;nbsp;or similar to get some ideas on how they should work. Then as a second step, I would try to create a simple script in C where you can try to add, remove, read, change and print the arrays to see if they behave as you expected them to.&lt;/p&gt;
&lt;p&gt;Try the abovementioned before you add the saadc and ble_nus functionalities.&amp;nbsp;If you are using nRF5 SDK, the &lt;a href="https://infocenter.nordicsemi.com/index.jsp"&gt;&amp;nbsp;logging module&lt;/a&gt;&amp;nbsp;(and this&amp;nbsp;&lt;a href="https://www.youtube.com/watch?v=aumm2aQ9Xeg&amp;amp;ab_channel=Sumair%27sEmbeddedEngineering"&gt;video tutorial example created by external people&lt;/a&gt;)&amp;nbsp;might be of help with trying to examine the input of your data array.&lt;/p&gt;
&lt;p&gt;Kind regards,&lt;br /&gt;Andreas&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Sending data array over ble nus</title><link>https://devzone.nordicsemi.com/thread/373953?ContentTypeID=1</link><pubDate>Thu, 23 Jun 2022 13:06:25 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f226c77c-a41e-4cc7-9f75-0a9235ef1a07</guid><dc:creator>Juniorprogrammer</dc:creator><description>&lt;p&gt;Hi Edvin,&lt;/p&gt;
&lt;p&gt;I did tried in the way you suggest:&lt;/p&gt;
[quote userid="26071" url="~/f/nordic-q-a/89244/sending-data-array-over-ble-nus/373914"]I suggest you either create one large array, data[80], and then you sprintf to the 0th, 20th, 40th and 60th element, and then you just pass the entire array through ble_nus_data_send(). Remember to set the length to 80, and not 4.&amp;nbsp;[/quote]
&lt;p&gt;but I only get once a random value see:&lt;/p&gt;
&lt;p&gt;&lt;img style="max-height:240px;max-width:320px;" src="https://devzone.nordicsemi.com/resized-image/__size/640x480/__key/communityserver-discussions-components-files/4/pastedimage1655989488304v1.png" alt=" " /&gt;&lt;/p&gt;
&lt;p&gt;This are the changes I did made&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;static void app_timer_handler(void * p_context)
{
  if(m_conn_handle != BLE_CONN_HANDLE_INVALID)
  {
    uint8_t data_array[80];

    float val0;
    float val1;
    float val2;
    float val3;

    uint8_t data0[20];
    uint8_t data1[20];
    uint8_t data2[20];
    uint8_t data3[20];

    ret_code_t err_code;

    err_code = nrfx_saadc_sample_convert(0, &amp;amp;m_sample);
    APP_ERROR_CHECK(err_code);

    val0 = m_sample * 3.3 / 4096;
    sprintf((char*)data0, &amp;quot;%.2f&amp;quot;, val0);
    data_array[0] = data0; 

    err_code = nrfx_saadc_sample_convert(1, &amp;amp;m_sample);
    APP_ERROR_CHECK(err_code);

    val1 = m_sample * 3.3 / 4096;
    sprintf((char*)data1, &amp;quot;%.2f&amp;quot;, val1);
    data_array[20] = data1; 

    err_code = nrfx_saadc_sample_convert(2, &amp;amp;m_sample);
    APP_ERROR_CHECK(err_code);

    val2 = m_sample * 3.3 / 4096;
    sprintf((char*)data2, &amp;quot;%.2f&amp;quot;, val2);
    data_array[40] = data2;

    err_code = nrfx_saadc_sample_convert(3, &amp;amp;m_sample);
    APP_ERROR_CHECK(err_code);

    val3 = m_sample * 3.3 / 4096;
    sprintf((char*)data3, &amp;quot;%.2f&amp;quot;, val3);
    data_array[60] = data3;
  
    uint16_t d_len = sizeof(data_array)-1;
    
    err_code = ble_nus_data_send(&amp;amp;m_nus, data_array, &amp;amp;d_len, m_conn_handle); 
    APP_ERROR_CHECK(err_code);
  }
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;I still don&amp;#39;t know where it exactly goes wrong. Can you help me out?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Sending data array over ble nus</title><link>https://devzone.nordicsemi.com/thread/373925?ContentTypeID=1</link><pubDate>Thu, 23 Jun 2022 11:38:11 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:15d45fb3-acec-4af7-b19b-b22bd94ce02e</guid><dc:creator>Juniorprogrammer</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;Thank you I will try this.&lt;/p&gt;
&lt;p&gt;Is it possible to send an array of size data[80] over ble_nus without any change?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Sending data array over ble nus</title><link>https://devzone.nordicsemi.com/thread/373914?ContentTypeID=1</link><pubDate>Thu, 23 Jun 2022 11:25:49 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:12a84128-f406-4e43-be39-c364349aa6ed</guid><dc:creator>Edvin</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;I think you need to look at the pointer - array side of this application.&lt;/p&gt;
&lt;p&gt;Try to print the content of the&amp;nbsp;data_array[] array in your log, or look at it in a debug session.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;What do you expect the data_array to look like? What should be in data_array[0], data_array[1], data_array[2] and data_array[3]? Hint: It only holds a single uint8_t value in each of the elements, since it is a uint8_t array.&lt;/p&gt;
&lt;p&gt;Then you try to set each of these uin8_t parameters equal to the address (pointer) of each of the 20 byte arrays, so what the data_array[] values actually are after e.g.&lt;/p&gt;
&lt;p&gt;data_array[3] = data3;&lt;/p&gt;
&lt;p&gt;I am not sure. data_array[3} has 8 bits, and the data3 array pointer has 32 bits. So I guess it will be either the first 8 or last 8 bits. It is not really specified in C and hence, you get the warnings that you see.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;So how to actually send the data you want to send:&lt;/p&gt;
&lt;p&gt;I suggest you either create one large array, data[80], and then you sprintf to the 0th, 20th, 40th and 60th element, and then you just pass the entire array through ble_nus_data_send(). Remember to set the length to 80, and not 4.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Edvin&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>