Stopping DM Service While Keeping BLE Active on nRF5340

Hello Nordic Support Team,

I’m working with an nRF5340 on nRF Connect SDK 3.0.2, using both the Distance Measurement (DM) service and BLE DFU.

My application topology consists of Anchors and Tags. On the Tag side, I only use advertising.

After I call dm_init() and perform some ranging, I would like to know how I can stop only the DM service while keeping the Bluetooth stack running, since I still need BLE for DFU.

Thanks in advance for your support.

Best regards.

  • Hello,

    The DM sample is a bit finicky. It doesn't do regular BLE connections, but instead a mix of advertising and scanning. When it detects another device advertising with the manufacturer data that is present in the scan response packet (sd), then it will adjust it's advertising data accordingly, and resume scanning. When two devices detects that they are advertising with matching scan response data, they will initiate the distance measurement procedure. 

    So for this to work the devices needs to be advertising with the scan response data packet containing the sample's mfg_data, and it needs to be scanning. 

    Attached is a sample that by default doesn't scan, and doesn't advertise with the mfg_data in the scan response packet. Pressing button 1 will add the scan response packet, and it will trigger the device to start scanning.

    So if you flash this sample to 2x DKs, they will by default not do anything. If you press button 1 on both the devices, they will start doing distance measurements. If you press button 2 on one of the devices, that device will take away the scan response packet, and stop scanning. This results in the distance measurements stopping, and it will only advertise with it's device name.

    Pressing button 1 again will resume the distance measurements.

    nrf_dm.zip

    Give it a go, and see if this is what you need.

    Best regards,

    Edvin

Related