Proper way to change NUS UUID in a Zephyr project - prj.conf?

In a previous ticket on another topic this question came up. Given it was a tangent to the original topic of that thread, and I think it would be helpful to others, I decided to open a different ticket to address it. 

Some background; my development environment is VS Code with nRF Connect extension pack. Created the project with the "Create a new application from sample" wizard, selected application type "Workspace", and started from the peripheral UART sample. On the nRF5340-dk it builds, runs, debugs, etc., no problem. 

The question is: for the end product I want to change the BT_UUID_NUS_VAL which is defined in nus.h, and I want the change to be tracked as part of the my git repo where the project files are tracked. When this question came up on the other thread, the response was: 

"The sample you are suggesting would not require you to change any of the files in SDK or Zephyr, but rather through configuring your application files either within prj.conf in the peripheral_uart folder (a.k.a, project folder) or by defined macros in the .c or .h files."

However, how to do this is not obvious to me. Can an example of how to changes this within  prj.conf be given? I agree, this would be the best solution since the prj.conf file is already part of the project git repo, but I do not see a clear way to override the BT_UUID_NUS_VAL or BT_UUID_NUS_SERVICE value in the SDK nus.h file from the prj.conf file. 

The other suggestion is to change the macros in the .h file which means that I will be making a change to the SDK files, which I would like to avoid. 

So, I'm looking for guidance on how the Nordic engineering team would recommend overriding the default UUID in nus.h. 

Regards,

Brad

  • Hi Brad, 

    If you are going to make your own service (including the change of UUID), I would suggest to create your own service source and header file .c and .h and remove any relation to the NUS sample service that we provided. 

    If you have a look at the peripheral_ht example you can find that we use the hts.c and hts.h inside src folder. The files are included in the project by the Cmakelists.txt. 

    You can do the same with your own service .c and service .h files. Then you can remove any NUS related declaration in your project. 

  • Hello Hung, 

    Thanks for the info. I'll make a copy of the nus.h/.c files and start form there. I'm guessing I will also have to remove CONFIG_BT_NUS=y from my prj.conf file as well. I'll give it a try and see if I run into any problems. 

    -Brad

Related