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

Can the app handle the float value sent to the app using nus_data_send?

Hello

I am using SDK v17 and sending the value of acceleration sensor to the app.

I want to use this value to process some action in the app.  For example, if the transmitted acceleration sensor X axis has a value greater than 1.5, the app will output a notification.

(Firmware might be able to specify the sensor's range of values and send data to the app within a certain range. However, the requirements that I received are to send only the sensor value from the firmware and to be processed by the app.)

So I saved the sensor value in the float array and sent it to the app via nus_data_send.

    //Send to App float value
    float array_x2[20]; 
    //uint16_t length = sizeof(array); //Problems occur because it prints out even empty spaces in the array.
    sprintf(array_x2, "%.2f", accel_x); //Store values in array, float -> char
    uint16_t length_x2 = strlen(array_x2); //length measurement of string
  
    float array_y2[20]; 
    sprintf(array_y2, "%.2f", accel_y); //Store values in array.
    uint16_t length_y2 = strlen(array_y2); //length measurement of string

    float array_z2[20]; 
    sprintf(array_z2, "%.2f", accel_z); //Store values in array.
    uint16_t length_z2 = strlen(array_z2); //length measurement of string    


    err_code = ble_nus_data_send(&m_nus, &array_x2, &length_x2, m_conn_handle);
    if ((err_code != NRF_ERROR_INVALID_STATE) &&// 
                            (err_code != NRF_ERROR_RESOURCES) &&
                            (err_code != NRF_ERROR_NOT_FOUND))
                        {
                            APP_ERROR_CHECK(err_code);
                        }

    err_code = ble_nus_data_send(&m_nus, &array_y2, &length_y2, m_conn_handle);
    if ((err_code != NRF_ERROR_INVALID_STATE) &&// 
                            (err_code != NRF_ERROR_RESOURCES) &&
                            (err_code != NRF_ERROR_NOT_FOUND))
                        {
                            APP_ERROR_CHECK(err_code);
                        }

    err_code = ble_nus_data_send(&m_nus, &array_z2, &length_z2, m_conn_handle);
    if ((err_code != NRF_ERROR_INVALID_STATE) &&// 
                            (err_code != NRF_ERROR_RESOURCES) &&
                            (err_code != NRF_ERROR_NOT_FOUND))
                        {
                            APP_ERROR_CHECK(err_code);
                        }

Can the app developer use this float value in the app?

Thank you in advance!
Parents Reply Children
No Data
Related