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

get the DEVICEADDR from the advertising packet?

I read that the DEVICEADDR is always in the advertising packet, so i need to take these data from the master each time that a slave is conected to them. I trying do something like that but i coldn't get what i like, here is part of my code:

//Definition:

ble_gap_addr_t deviceaddr [6];

//In the function on_adv_report:

sd_ble_gap_address_get(deviceaddr); printf("Direccion esclavo 2: %u", deviceaddr);

Maybe i define wrong the variable deviceaddr.

I use nrf51 dk and soft device S130.

Parents
  • You can read it directly from the advertisement packet. You can do it like this:

    static void on_adv_report(ble_evt_t * p_ble_evt)
    {
        uint32_t              err_code;
        const ble_gap_evt_t * p_gap_evt = &p_ble_evt->evt.gap_evt;
    
        
        const ble_gap_evt_adv_report_t * p_adv_report = &p_gap_evt->params.adv_report;
                
        const ble_gap_addr_t peer_addr = p_adv_report->peer_addr;
        
        printf("Address %02x%02x%02x%02x%02x%02x\r\n",
                                 peer_addr.addr[0],
                                 peer_addr.addr[1],
                                 peer_addr.addr[2],
                                 peer_addr.addr[3],
                                 peer_addr.addr[4],
                                 peer_addr.addr[5]
                                 );
    }
    
Reply
  • You can read it directly from the advertisement packet. You can do it like this:

    static void on_adv_report(ble_evt_t * p_ble_evt)
    {
        uint32_t              err_code;
        const ble_gap_evt_t * p_gap_evt = &p_ble_evt->evt.gap_evt;
    
        
        const ble_gap_evt_adv_report_t * p_adv_report = &p_gap_evt->params.adv_report;
                
        const ble_gap_addr_t peer_addr = p_adv_report->peer_addr;
        
        printf("Address %02x%02x%02x%02x%02x%02x\r\n",
                                 peer_addr.addr[0],
                                 peer_addr.addr[1],
                                 peer_addr.addr[2],
                                 peer_addr.addr[3],
                                 peer_addr.addr[4],
                                 peer_addr.addr[5]
                                 );
    }
    
Children
Related