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

change device name on button press

Hi.

I havent found answer for - in my opinion - common question - how to temporarily change name of ble device on button press. As long as button isnt pressed - advertise NOBUTTON name and if i press it - advertise BUTTON name, or any other.

i am complete noob in nrf51822 programming, intermediate in arduino so any advice would be more than appreciated. I succesfully programmed nrf52-DK to led control via ble - so i use common mbed tutorial files. If i understand correctly i should:

  • connect nrf51822 to 52DK (how? can you provide correct blueprints?)
  • mix button program with normal ble advertising. (do you have any button managment source files?)

Can you - please - provide any source files, tutorials or information that might help me to achieve my goal?

I have: multiple nrf51822 boards nrf52 dk motherboard mbed account and succesfully mbed compiled programs to motherboard.

Regards, Kalreg.

Parents
  • Hi,

    The nRF5x DK boards is marked with PCA100xx number, where PCA10028 is nRF51 DK and PCA10040 is nRF52 DK. You can also see this from the chip markings, where nRF51422 is nRF51 DK, and nRF52832 is nRF52 DK.

    It should be possible to change the advertised name in mbed. Note that you have to stop advertising, initiate the advertising with the new data, and start advertising again.

    In your code, you most likely have a function initializing the advertising, which put the device name in the advertising packet using accumulateAdvertisingPayload(). Something like this should work:

    const static char     DEVICE_NAME1[] = "NAME1";
    const static char     DEVICE_NAME2[] = "NAME2";
    
    bool buttonPressed = false;
    
    void changeAdvertisingName(void)
    {
    	BLE &ble = BLE::Instance();
    	
    	ble.gap().stopAdvertising();
    	if(buttonPressed)
    	{
    		ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LOCAL_NAME, (uint8_t *)DEVICE_NAME1, sizeof(DEVICE_NAME1));
    	}
    	else
    	{
    		ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LOCAL_NAME, (uint8_t *)DEVICE_NAME2, sizeof(DEVICE_NAME2));
    	}
        ble.gap().startAdvertising();
    }
    

    Button presses can be handled using the mbed InterruptIn library.

    Best regards,

    Jørgen

Reply
  • Hi,

    The nRF5x DK boards is marked with PCA100xx number, where PCA10028 is nRF51 DK and PCA10040 is nRF52 DK. You can also see this from the chip markings, where nRF51422 is nRF51 DK, and nRF52832 is nRF52 DK.

    It should be possible to change the advertised name in mbed. Note that you have to stop advertising, initiate the advertising with the new data, and start advertising again.

    In your code, you most likely have a function initializing the advertising, which put the device name in the advertising packet using accumulateAdvertisingPayload(). Something like this should work:

    const static char     DEVICE_NAME1[] = "NAME1";
    const static char     DEVICE_NAME2[] = "NAME2";
    
    bool buttonPressed = false;
    
    void changeAdvertisingName(void)
    {
    	BLE &ble = BLE::Instance();
    	
    	ble.gap().stopAdvertising();
    	if(buttonPressed)
    	{
    		ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LOCAL_NAME, (uint8_t *)DEVICE_NAME1, sizeof(DEVICE_NAME1));
    	}
    	else
    	{
    		ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LOCAL_NAME, (uint8_t *)DEVICE_NAME2, sizeof(DEVICE_NAME2));
    	}
        ble.gap().startAdvertising();
    }
    

    Button presses can be handled using the mbed InterruptIn library.

    Best regards,

    Jørgen

Children
No Data
Related