Change device name

Hello Nordic Engineer,

I know that I can modify #define DEVICE_NAME "device001" in sdk_config.h, but it takes a lot of time to compile and flash the program every time. It seems like there should be another way to quickly solve this.

【1】Is it possible to modify it through the iOS nRF Connect app, but with a prerequisite? Do I need to add some code in the 52811 program? (My product uses nRF52811)

【2】Can it be solved through the command line with J-Link? But I've never used the command line before...

【3】Are there any other methods? I just want to solve the problem quickly, and I don't mind how many methods there are.

Thanks

Parents
  • Hello,

    I know that I can modify #define DEVICE_NAME "device001" in sdk_config.h, but it takes a lot of time to compile and flash the program every time. It seems like there should be another way to quickly solve this.

    You can re-init the advertising and provide a new name as the device name parameter instead of DEVICE_NAME. Please see the section of main.c where DEVICE_NAME is used as the parameter to configure the name of the device in the GAP initialization.

    This approach will also let you do so at runtime, so if you first receive the new name over BLE you can then re-init and start advertising with this new name.
    Just out of curiosity, which use-case are you targeting where you would need to change the advertising name after you have already established connection with the central device?

    Best regards,
    Karl

  • Hello Ylvisaker ,

    Thank you for your reply.

    You can re-init the advertising

    I still don't quite understand how to initialize advertising separately. My previous approach was to modify the DEVICE_NAME, then build, wait for more than 1 minute until the hex file was generated, and then download it to the chip. However, the build time is too long.

    Whether it's central or peripheral, it's ble_app_multirole_lesc.

    I used this example to establish a mesh network with 1-to-1-to-1 connections, extending continuously. Therefore, all devices include both central and peripheral roles.

  • Hello,

    tony55723 said:
    Thank you for your reply.

    No problem at all, I am happy to help!

    tony55723 said:
    I still don't quite understand how to initialize advertising separately. My previous approach was to modify the DEVICE_NAME, then build, wait for more than 1 minute until the hex file was generated, and then download it to the chip. However, the build time is too long.

    Yes, please see the gap_params_init function in the example. Here you can change away from using the DEVICE_NAME define to instead use a variable you can change throughout the lifetime if your application.

    Best regards,
    Karl

  • Hello Ylvisaker ,

    If I use variables, will the name revert back to its original one the next time I power cycle?

  • Hello,

    tony55723 said:
    If I use variables, will the name revert back to its original one the next time I power cycle?

    Yes, unless you store this name in FLASH it will revert back to the initial name upon resetting.

    Best regards,
    Karl

Reply Children
  • Hello Ylvisaker ,

    But I hope that after changing the name, the advertising will use the new name the next time the power is restarted. Do I have to modify the DEVICE_NAME every time I want to change the name and wait for the 1-minute build time?Sob

  • Hello,

    tony55723 said:
    But I hope that after changing the name, the advertising will use the new name the next time the power is restarted. Do I have to modify the DEVICE_NAME every time I want to change the name and wait for the 1-minute build time?

    If you use a variable instead of the compile-time DEVICE_NAME define then the device will start its advertising with whatever name you have provided in that variable, and so you will not have to recompile each time you want to change name, no.

    How you populate that variable name will be up to you - you could have a list of names stored in your FLASH (persistent memory), or you can receive the new name from a BLE connection, or you can push a button to make it go to a predetermined name.

    Best regards,
    Karl

  • Hello Ylvisaker ,

    you could have a list

    const char* DEVICE_NAMES[] = {"Device0001", "Device0002", ....... ,"Device9999"};

    nRF52811 Flash is so small

    I may not design it this way, but it should be achievable using the 'Device+xxx' approach.

    But I have a question, the BLE data reception (NUS), or buttons, and what I consider UART (PCB copper wires), these all belong to external signals, so I still need to store data (Flash), right?

    The next time the device boots up, it will first read from the Flash. For example, if it reads 0x0a, it will advertise as 'Device' + '0x0a', which is 'Device0010', right?

  • tony55723 said:

    const char* DEVICE_NAMES[] = {"Device0001", "Device0002", ....... ,"Device9999"};

    nRF52811 Flash is so small

    I would not recommend this approach if your list of potential names are as long as this, all but one of these entries actually will be useful to the device. In this case I would go with the approach using a single variable stored in flash, which you may later re-write if needed.

    It is not quite clear to me how the number of the device name will be generated or determined, could you elaborate on this?

    tony55723 said:
    But I have a question, the BLE data reception (NUS), or buttons, and what I consider UART (PCB copper wires), these all belong to external signals, so I still need to store data (Flash), right?

    Yes, all of these options would still need to store in flash in order to persist through a reset.

    tony55723 said:
    The next time the device boots up, it will first read from the Flash. For example, if it reads 0x0a, it will advertise as 'Device' + '0x0a', which is 'Device0010', right?

    If you are using a variable for your name which you have stored in flash then this variable will be read upon startup and input as the device name to the GAP function, yes. Please see one of the three FLASH storage examples here as a reference for how you may store your variable in flash.

    Best regards,
    Karl

  • Hello Ylvisaker ,

    The device number is assigned according to the quantity ordered by the customer. For example, if 100 units are ordered today, the numbers will be from 1 to 100. If 200 units are ordered tomorrow, the numbers will be from 101 to 300.

    Thank you very much. In the infocenter you provided, I found examples\peripheral\flash_fstorage. Later, I will try to implement the write flash function.

Related