How to set role for nrf_dm? One as reflector and the other as initiator

I tested on two 52832 based devices with nrf_dm sample code. It worked. Then I disabled "scan_start()" on one device, trying it make it as  reflector only. I did not change the other device, but the other device could not get the distance value. Need your help!

  • Hello,

    The reason you stop seeing distance measurements when you disable scanning on one of the devices is due to the nature of how this sample decides who to perform the distance measurement with. 

    When you have one device that is only advertising, that device will never get the advertising reports (callbacks when it has scanned an advertiement). This means that scan_filter_match() will never be called, which again means that peer_supported_add() is never called. 

    Then, later, when you advertise, and receive an adv_scanned_cb() callback, it uses "if (peer_supported_test())" to check whether the peer is in the list, but since no devices are added by peer_supported_add(), it will not set up a req. with DM_ROLE_REFLECTOR.

    DM_ROLE_INITIATOR will not be used either, since that is triggered from the data_cb() in the scan_filter_match(). 

    So, to make this work without scanning at all, you would need to comment out the line:

    if (peer_supported_test(info->addr)) {

    (and the opposing "}" a few lines below)

    in adv_scanned_cb(). Then you should see measurements where the non-scanning device acts as the reflector. 

    There are other ways to initiate this as well. One possible way would be to enter a BLE connection through normal advertising from one device and scanning from the other, and agree upon this inside the connection.

    Best regards,

    Edvin

Related