Append uint32 to string for BLE local name
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2022-01-03 8:52 AM
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"
Solved! Go to Solution.
- Labels:
-
STM32WB series
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2022-01-03 11:22 AM
This should do it:
sprintf(name, "TEST %04X", id);
The length of the resulting string can be calculated with strlen(name).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2022-01-03 11:11 AM
char name[32]; //or how is max name len
sprintf(name, "TEST %x", id);
or
sprintf(name, "TEST %08x", id);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2022-01-03 11:22 AM
This should do it:
sprintf(name, "TEST %04X", id);
The length of the resulting string can be calculated with strlen(name).
