This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Problem sending data array using BLE_NUS_DATA_SEND

Hi,

I am simply trying to send a sample of data from a TWI sensor to smartphone via BLE with a 2 second delay between each send.

I've adapted the ble_app_uart and twi_sensor examples, and everything is working properly except one thing. The data is not received properly.

The BLE_NUS_DATA_SEND is sending and working correctly because I do see the "value" title appear in the NRF Connect app after enabling notifications, but there is just no value there (just empty space).

To check the data, I printed/logged the sensor value in the data_send function. M_sample prints correctly, but when I try to print the data array, it doesn't show. So I believe this problem is caused when m_sample is put into the data array. This tells me that m_sample is of the wrong type or form.

I have 2 questions:

1. What type/size/form does my data need to be in to be printed/logged, and why can't I print the data_array but can with the m_sample?

2. What changes need to be applied to send my number sample (m_sample) via BLE_NUS_DATA_SEND?

 

I'm sure these questions are obvious to someone. I may have missed some basic things in the documentation, but I'd really appreciate if someone could point out my problem.

SDK15.3, SES

void data_send(uint8_t m_sample)
{
    static uint8_t data_array[BLE_NUS_MAX_DATA_LEN];
    static uint8_t index = 0;
    uint32_t       err_code;

    data_array[BLE_NUS_MAX_DATA_LEN - 1] = m_sample;


NRF_LOG_INFO("check msample: %d Celsius degrees.", m_sample);

       // NRF_LOG_INFO("Check array.", data_array); 
          NRF_LOG_INFO("Check array2.", m_sample); 
          
                    //NRF_LOG_DEBUG("Ready to send data over BLE NUS");
                    //NRF_LOG_HEXDUMP_DEBUG(data_array, index);

                   
                        uint16_t length = (uint16_t)index;
                        err_code = ble_nus_data_send(&m_nus, &data_array, &length, m_conn_handle);
  
 

   if ((err_code != NRF_ERROR_INVALID_STATE) &&// This part is right (saw another user do it).
                            (err_code != NRF_ERROR_RESOURCES) &&
                            (err_code != NRF_ERROR_NOT_FOUND))//different
                        {
                            APP_ERROR_CHECK(err_code);
                      }

}

Parents
  • Hi, from my experience of using ble_nus_data_send() I would say that the problem might be your data type. 
    BLE_NUS_DATA_SEND works with ASCII values only, if that helps.. Also, the nus_data_send() sometimes sends an array backwards, last byte first. 

    However the NRFConnect app does show the hex value of the sent array just on top of the "received string", you might want to check if you're getting the correct value there, it's just above the received line. 

Reply
  • Hi, from my experience of using ble_nus_data_send() I would say that the problem might be your data type. 
    BLE_NUS_DATA_SEND works with ASCII values only, if that helps.. Also, the nus_data_send() sometimes sends an array backwards, last byte first. 

    However the NRFConnect app does show the hex value of the sent array just on top of the "received string", you might want to check if you're getting the correct value there, it's just above the received line. 

Children
Related