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

float to string in Printf() + ble_nus()

Hi

I am trying to send the float value to mobile through ble_nus()

respective code:

 float accelX = ((((float)accel.x) / G_TO_LSB) * 9.80655); // in m/s^2

      length1 = sprintf(str, "AccX = %5d  AccY = %5d  AccZ = %5d \n", accel.x, accel.y, accel.z);

      rsltb = ble_nus_data_send(&m_nus, str, &length1, m_conn_handle);
      //APP_ERROR_CHECK(rsltb);
      
      length1 = sprintf(str, "AccX = %d.%02d \n", accelX);

      rsltb = ble_nus_data_send(&m_nus, str, &length1, m_conn_handle);
      //APP_ERROR_CHECK(rsltb);
       NRF_LOG_INFO("Data send...");
        NRF_LOG_FLUSH();
       printf("AccX = %5d  AccY = %5d  AccZ = %5d \r\n", accel.x, accel.y, accel.z);
       printf("%s%d.%02d \n",accelX);
        printf("Data send.. \r\n");

i tried ("%s%d.02%d") but i got the result as:

AccX =  4868  AccY = -3942  AccZ = 15463 
(null)536870912.1074220873 Data send.. 
AccX =  5065  AccY = -3761  AccZ = 15443 
(null)-1610612736.1074282693 Data send.. 
AccX =  5030  AccY = -3701  AccZ = 15703 
(null)1073741824.1074271710 Data send.. 
AccX =  5010  AccY = -3867  AccZ = 15409 
(null)536870912.1074265434 Data send.. 
AccX =  5170  AccY = -3731  AccZ = 15177 
(null)-1610612736.1074315643 Data send.. 
AccX =  5829  AccY = -3704  AccZ = 15774 
(null)536870912.1074522444 Data send.. 
AccX =  5267  AccY = -4329  AccZ = 15079 
(null)536870912.1074346083 Data send.. 

in app

Parents Reply Children
No Data
Related