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

Simulating multiple devices

I am in need of some guidance around how to simulate multiple devices, with different addresses, on the same NRF52

I am currently developing a test application using the NRF52 Dev Kit and SDK14.2 .

I have a device that connects to multiple peripheral devices, let's call the peripheral devices Widgets.

The aim is to make a system that simulates multiple Widgets, each with their own seperate addresses so that the device I am testing can connect to my simulated widgets as if there were several real widgets.

The NRF52 can only advertise as one device at a time so, I need to advertise as Widget 1 for some time period, the advertise as Widget 2, and so on.

My simulator also needs to be able to know which of my simulated widgets that my device is trying to connect to. This is because I have a configuration Android App that tells my device which devices to connect to, based on the advertised address.

I believe I can set up an app timer  whose timeout handler will generate an app scheduler event. This app scheduler event will then do something like:

static void app_sched_pull_evt(void *p_event_data, uint16_t event_size)
{
    sys_ble_evt_t *evt = (sys_ble_evt_t *) p_event_data;
    switch(evt->type)
    {
        case(SYS_BLE_EVT_SWITCH_ADV_DEVICE):
        {
            ble_advertising_stop();
            ble_set_gap_addr(&rand_bytes[adv_id], PEER_ADDR_LEN);
            adv_id = (adv_id + PEER_ADDR_LEN)%NUM_SUPPORTED_SIMULATED_OARLOCKS;
            advertising_start(BLE_GAP_ADV_TYPE_ADV_IND, BLE_ADV_INTERVAL, BLE_ADV_TIMEOUT); 
        } break;
    }
}

//The identity address cannot be changed while advertising, scanning or creating a connection
uint32_t ble_set_gap_addr(uint8_t const * address, uint8_t addr_len)
{
    if(addr_len != BLE_GAP_ADDR_LEN)
        return BLE_ERROR_GAP_INVALID_BLE_ADDR;
    
    
    ble_gap_addr_t addr;
    addr.addr_type = BLE_GAP_ADDR_TYPE_RANDOM_STATIC;
    addr.addr_id_peer = 0;
    uint32_t err_code = sd_ble_gap_addr_set(&addr);
    APP_ERROR_CHECK(err_code);
    return err_code;
}

How can I generate a valid address? Currently sd_ble_gap_addr_set returns BLE_ERROR_GAP_INVALID_BLE_ADDR .

Am I going about this the right way? I have tried using sd_ble_gap_privacy_set(ble_gap_privacy_params_t const *p_privacy_params) to do it which lets me pretend the advertisements are from multiple devices but, I need to contrain the number of different addresses to the number of simulated Widgets.

Parents Reply Children
No Data
Related