Skip to main content
kcire L.
Associate III
Jan 3, 2022 4:52 PM UTC
Solved

Append uint32 to string for BLE local name

I think this is more of a c programming question rather than a MCU question, but I figured I would ask anyway. I am trying to append the chip ID from an STM32WB onto the BLE local name for my application and am having trouble figuring out how to do this.

my local name is a const char *name = TEST

My chip id is a uint32_t Device_ID which was read from the device register (0x1FFF7580).

lets say the Device_ID = 0x8BE4...

How can I combine these two such that my local name ends up being "TEST 8BE4"

This topic has been closed for replies.
TDK
TDKBest answer
Jan 3, 2022 7:22 PM UTC

This should do it:

sprintf(name, "TEST %04X", id);

The length of the resulting string can be calculated with strlen(name).

"If you feel a post has answered your question, please click ""Accept as Solution""."

2 replies

MM..1
Super User
Jan 3, 2022 7:11 PM UTC
 char name[32]; //or how is max name len
 
 sprintf(name, "TEST %x", id);
or
 sprintf(name, "TEST %08x", id);
 

TDK
TDKBest answer
Jan 3, 2022 7:22 PM UTC

This should do it:

sprintf(name, "TEST %04X", id);

The length of the resulting string can be calculated with strlen(name).

"If you feel a post has answered your question, please click ""Accept as Solution""."