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

BLE_NUS can only send integer, cannot send float values

I'm using nRF52 DK to send SAADC data to mobile app "nRF Connect" over BLE. 

I'm using this code to send the data, but the mobile app "nRF Connect" can only show integer values, cannot show float values. please help, thanks! 

int iii = 35;
float fff = 0.123456789;

uint8_t nus_string[50];
bytes_to_send = sprintf(nus_string, "int = %d, float = %f\r\n",iii,fff);

err_code = ble_nus_data_send(&m_nus, nus_string, &bytes_to_send, m_conn_handle);

if ((err_code != NRF_ERROR_INVALID_STATE) && (err_code != NRF_ERROR_NOT_FOUND))
{
    APP_ERROR_CHECK(err_code);
}

Parents
  • The bug is caused by sprintf() function.You may debug with printf("%s",nus_string);

    You will find that the string is the same with nRF connect display.

    If you want to fix the problems, you have to enable sprintf() & printf() float type(SES project option). or change the float type with integer and float parts.

    EX:

    float fff=3.141;

    int8_t fff_int;

    uint16_t fff_float;

    fff_int = (fff*1000)/1000;

    fff_float = (fff*1000)%1000;

    sprintf(nus_string, "float = %d.%03d \r\n",fff_int ,fff_float );

Reply
  • The bug is caused by sprintf() function.You may debug with printf("%s",nus_string);

    You will find that the string is the same with nRF connect display.

    If you want to fix the problems, you have to enable sprintf() & printf() float type(SES project option). or change the float type with integer and float parts.

    EX:

    float fff=3.141;

    int8_t fff_int;

    uint16_t fff_float;

    fff_int = (fff*1000)/1000;

    fff_float = (fff*1000)%1000;

    sprintf(nus_string, "float = %d.%03d \r\n",fff_int ,fff_float );

Children
No Data
Related