If you don’t know the Bluetooth MAC address of the device you want to work with, you can still find a Digi device by executing a Bluetooth scan. This process looks for nearby Bluetooth devices and provides IDevice objects from the Plugin.BLE library that can be used later with the Bluetooth password to build a Digi device.

The methods required to start and stop the Bluetooth scan process are located in the DigiBLEManager class of the library.

Method Description

StartScanning()

Starts the scan process to look for nearby Bluetooth Low Energy devices.

StopScanning()

Stops the scan process to look for nearby Bluetooth Low Energy devices.

Before the scanning process starts, subscribe to the DeviceAdvertised event of the DigiBLEManager that notifies you when new Bluetooth devices are discovered. Then, you can use the IDevice object from the Plugin.BLE library provided to build the Digi device object.

Obtain Digi devices from a Bluetooth scan

// Instantiate the Digi BLE manager.
DigiBLEManager digiBLEManager = new DigiBLEManager();

// Subscribe to device advertised (discovered) event.
digiBLEManager.DeviceAdvertised += (IDevice device) =>
{
    // Build a Digi device using the advertised Bluetooth device.
    DigiBLEDevice myDigiBLEDevice = new DigiBLEDevice(device, "password");
};

// Start the scan process.
digiBLEManager.startScanning();

// Do some stuff
[...]

// Stop the scan process.
digiBLEManager.stopScanning();
In addition to the DeviceAdvertised event, the scanning process generates other events you can subscribe to. For more information about these events and how to subscribe to notifications, see Subscribe to Bluetooth events.