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

sprintf - Not displaying leading Zero of MAC address (SDK15.2 SEGGER)

Just need a little help on something that is probably very simple. I am sure I will be embarrassed at how simple this is.

I get the nr52 device MAC address and append 4 digits of it to the end of our device name to make the device name (kind of) unique.

Here is the code that kind of works now:

    ble_gap_addr_t addr;
    err_code = sd_ble_gap_addr_get(&addr);
    char device_name[DEVICE_NAME_MAX_SIZE];
    uint8_t name_size = strlen(DEVICE_NAME);
    memcpy(device_name, DEVICE_NAME, name_size);
    // Encode the BLE address as a String and set the advertising name
    sprintf(&device_name[name_size], " %X%X", addr.addr[BLE_GAP_ADDR_LEN - 5], addr.addr[BLE_GAP_ADDR_LEN - 6]);
    err_code= sd_ble_gap_device_name_set(&sec_mode, (const uint8_t *) device_name, name_size + 5);
    APP_ERROR_CHECK(err_code);

This works fine if there are no zeros in the MAC address.

The issue I am running into is that if there is a leading zero in the MAC address, it just puts a space in the place of the leading zero.

I want it to show the leading zero but can't figure this simple thing out.

I appreciate any help you can give!

Parents Reply Children
No Data
Related