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

BLE-UART service - add parsing to change advertisement name

Hello, I'm using the Nordic BLE-UART service found in the SDK. This is the "ble_app_uart" file in the SDK examples for the Nordic nRF51822. I'm basically sending JSON back and forth between a mobile device and another MCU, and the nRF51822 is just a transparent bridge on uART to the MCU.

However, the one instant where I need the nRF51822 to do something with the data is on receiving a certain string of uART from the MCU, that instructs the nRF51822 it needs to change the advertisement name. For example, if the uART string ever starts with 01A1, as in

01A1XXXXXX

Then I want to redefine "DEVICE_NAME" to XXXXXX (ASCII) and rerun the initiation code...which I think is just

gap_params_init();

Since gap_parms_init will rerun sd_ble_gap_device_name_set(), I thought this would work, and I can keep calling gap_params_init() as often as I change my name.

I'm pretty new to this, and I haven't been able to find example code to do two very specific things prior to calling gap_params_init().

1) Parsing: The uart callback is "nus_data_handler()", which seems to just put the character into app_uart_put(). I'm not sure where in the program I can get at the code that has the entire uart string, so I can start parsing it my "01A1" custom function code. I'm not sure how to extract the XXXXX name from that either, but one step at a time.

2) Redefine Name: Once I have name isolated, how do I redefine "DEVICE_NAME" to this new string? Currently, the definition <DEVICE_NAME> is static and the example code seem to assume that no one would change it.

define DEVICE_NAME "nRFAdvName"

Thanks for any pointers, especially to example code.

Eric

Related