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

how to send the float to string over ble_nus

hi, 

 I am working on temperature sensor i merged the uart and twi sensor , using nrf52832 + Max30205 (temperature sensor) . i am getting  the temperature in float which is printing in debug terminal , how to send the float over ble_nus _send . for that i need to convert into string right . i have done i have converted into string but i am no t receiving any data in nrf toolbox 

       while (m_xfer_done == false);
{
         m_xfer_done = false;
                
		uint8_t reg[2] = {0x00U};
        err_code = nrf_drv_twi_tx(&m_twi,LM75B_ADDR, reg, sizeof(reg), true);
		APP_ERROR_CHECK(err_code);
		while (m_xfer_done == false);
		nrf_delay_ms(5);
		
	        m_xfer_done = false;
		ret_code_t err_code1 = nrf_drv_twi_rx(&m_twi,LM75B_ADDR, &m_sample, sizeof(m_sample));
		APP_ERROR_CHECK(err_code1);
             
     uint16_t tempVal = (m_sample[0] <<  8) | m_sample[1];
          float tempC = tempVal * (0.0390625)/10;
           
      
    threshold= 28;

 if(tempC> threshold )
            {
             length1 = sprintf(str,"%.2f", tempC);
             ble_nus_data_send(&m_nus,str,sizeof(tempC), m_conn_handle);
              NRF_LOG_INFO("Temperature: " "%s%d.%01d", NRF_LOG_FLOAT(tempC));
                     
       
             
                            
  }
     
       
       }
       }
       

Parents
  • for that i need to convert into string right

    Not necessarily.

    ble_nus_data_send() just sends bytes - it neither knows nor cares what those bytes represent.

    So you could just send the raw bytes of the float value.

    The downside of that, of course, is that you won't be able to just view it on a plain terminal - you will need to software on the receiving end which does understand the format, and can re-assemble those bytes into a float value (and, if required, display them in a meaningful, human-readable form).

    This applies to any form of communication - not specific to Nordic or BLE.

    i have done i have converted into string

    This:

    length1 = sprintf(str,"%.2f", tempC);

    Have you checked that the conversion is actually working?

    The following code is still using the length of the original float - not the length of your converted string!

                 ble_nus_data_send(&m_nus,str,sizeof(tempC), m_conn_handle);
                 NRF_LOG_INFO("Temperature: " "%s%d.%01d", NRF_LOG_FLOAT(tempC));

  • even i have tried to send the raw bytes of the float value . i am getting error , incompatible type of argument 2 in ble_nus_send()

  • incompatible type of argument 2 in ble_nus_send

    That's a standard 'C' language error - nothing specific to Nordic or BLE.

    See your 'C' textbook for the 'C' language rules about types and their "compatibility" - and how to use a so-called "cast" to get around them ...

Reply Children
No Data
Related