This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

sprintf not working when converting float to string

Hi,

I am using sprintf to copy floating sensor data to a string and later copy that string in payload.

But when I do so, floating number is not copied, but rest of the numbers are copied.

I used the same code to copy floating numbers to string in nRF_SDK_Thread.

But in nRF_Connect_SDK this is not working.

Below is the code snippet:

	#define HEALTH_DATA_MESSAGE_FORMAT  "i=1&1=%d&i=5&1=%u&i=6&1=%0.2f&i=8&1=%d&i=11&1=%0.2f"

	float bat = 2.54;
	float chip_temp = 25.79;
    sprintf(buff, HEALTH_DATA_MESSAGE_FORMAT, -78, 1, bat, 3, chip_temp);
    

Output:

i=1&1=-78&i=5&1=1&i=6&1=&i=8&1=3&i=11&1=

Parents Reply Children
No Data
Related