Skip to main content
kcire L.
Associate III
January 3, 2022
Solved

Append uint32 to string for BLE local name

  • January 3, 2022
  • 2 replies
  • 923 views

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.
Best answer by TDK

This should do it:

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

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

2 replies

MM..1
Chief III
January 3, 2022
 char name[32]; //or how is max name len
 
 sprintf(name, "TEST %x", id);
or
 sprintf(name, "TEST %08x", id);
 

TDK
TDKBest answer
Super User
January 3, 2022

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""."