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]
                                 );
    }
    
  • Example:

    On the central I get advertisement packet with: “Address 0xE104D4DAF4F9

    This is in LSB format, so in MSB format this is: F9:F4:DA:DF:04:E1.

    On the peripheral I have this:

    DEVICEADDR[0]: 0xDAD404E1 -> DA:D4:04:E1

    DEVICEADDR[1]: 0x2B8679F4 -> 2B:86:79:F4

    The reason why "79" becomes "F9" is because the specification says that the 2 MSBit of the address must be set '11' . E.g. 79 binary -> 01:11:10:01 We set ‘11’ as the MSBit -> 11:11:10:01 -> F9

Reply
  • Example:

    On the central I get advertisement packet with: “Address 0xE104D4DAF4F9

    This is in LSB format, so in MSB format this is: F9:F4:DA:DF:04:E1.

    On the peripheral I have this:

    DEVICEADDR[0]: 0xDAD404E1 -> DA:D4:04:E1

    DEVICEADDR[1]: 0x2B8679F4 -> 2B:86:79:F4

    The reason why "79" becomes "F9" is because the specification says that the 2 MSBit of the address must be set '11' . E.g. 79 binary -> 01:11:10:01 We set ‘11’ as the MSBit -> 11:11:10:01 -> F9

Children
No Data
Related