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

Device name change

Hi,

I know how to change the name of the device using

BLE_GAP_CONN_SEC_MODE_SET_OPEN(&sec_mode);
err_code = sd_ble_gap_device_name_set(&sec_mode,(uint8_t const *) DEVICE_NAME, sizeof(DEVICE_NAME));

No problem there. I know how to store it to pstorage.

But my question is where do I get the new name coming through. Basically where do I catch the characteristic change?

For my own services I have write handlers so I can capture it all there, but where do I put code in place to catch the change for the device name so I can store and restore?

Regards,

Chris

Parents
  • Bit of digging and found elsewhere but needed tweaking.

    In my "main.c" I have this now

    static void ble_gatt_params_on_ble_evt(ble_evt_t * p_ble_evt)
    {
        ble_gatts_evt_write_t * p_evt_write = &p_ble_evt->evt.gatts_evt.params.write;
        
        if (p_evt_write->context.char_uuid.uuid == BLE_UUID_GAP_CHARACTERISTIC_DEVICE_NAME)
        {
            RMLOG("TODO: Name change attempt");
            
            // Device name is
            //p_evt_write->data;
            //p_evt_write->len;
            
        }
        
    }
    

    And then in my main handler I do this

    static void ble_evt_dispatch(ble_evt_t * p_ble_evt)
    {
        
        on_ble_evt(p_ble_evt);
        
        // Connection parameters
        ble_conn_params_on_ble_evt(p_ble_evt);
        
        // Device Name parameter
        ble_gatt_params_on_ble_evt(p_ble_evt);
        
        // Handle the sense service
        ble_sense_on_ble_evt(&m_sense, p_ble_evt);
    
        // Handle any Roam Core BLE services
        ble_rmcs_on_ble_evt(&m_rmcs, p_ble_evt);
        
        // Handle the Battery services
        ble_bas_on_ble_evt(&m_bas, p_ble_evt);
    
        // Anything for advertising to handle
        ble_advertising_on_ble_evt(p_ble_evt);
    
    }
    
Reply
  • Bit of digging and found elsewhere but needed tweaking.

    In my "main.c" I have this now

    static void ble_gatt_params_on_ble_evt(ble_evt_t * p_ble_evt)
    {
        ble_gatts_evt_write_t * p_evt_write = &p_ble_evt->evt.gatts_evt.params.write;
        
        if (p_evt_write->context.char_uuid.uuid == BLE_UUID_GAP_CHARACTERISTIC_DEVICE_NAME)
        {
            RMLOG("TODO: Name change attempt");
            
            // Device name is
            //p_evt_write->data;
            //p_evt_write->len;
            
        }
        
    }
    

    And then in my main handler I do this

    static void ble_evt_dispatch(ble_evt_t * p_ble_evt)
    {
        
        on_ble_evt(p_ble_evt);
        
        // Connection parameters
        ble_conn_params_on_ble_evt(p_ble_evt);
        
        // Device Name parameter
        ble_gatt_params_on_ble_evt(p_ble_evt);
        
        // Handle the sense service
        ble_sense_on_ble_evt(&m_sense, p_ble_evt);
    
        // Handle any Roam Core BLE services
        ble_rmcs_on_ble_evt(&m_rmcs, p_ble_evt);
        
        // Handle the Battery services
        ble_bas_on_ble_evt(&m_bas, p_ble_evt);
    
        // Anything for advertising to handle
        ble_advertising_on_ble_evt(p_ble_evt);
    
    }
    
Children
Related