As it stands today, the Bluetooth LE (BLE) module that Azure IoT Edge ships with does not support discovery of BLE devices. This is however on the product roadmap. In the meantime, the BLE module is perfectly usable for prototyping solutions by performing some preparatory work as documented here.
This tutorial assumes you are using a Texas Instruments SensorTag device connected to a Raspberry Pi 3 running Raspbian.
The BLE modules talk to the Bluetooth hardware on the Raspberry Pi 3 via the BlueZ stack. You need version 5.37 of BlueZ for the modules to work correctly. These instructions make sure the correct version of BlueZ is installed.
-
Stop the current bluetooth daemon:
sudo systemctl stop bluetooth
-
Install dbus, a BlueZ dependency.
sudo apt-get install libdbus-1-dev
-
Install ical, a BlueZ dependency.
sudo apt-get install libical-dev
-
Install readline, a BlueZ dependency.
sudo apt-get install libreadline-dev
-
Download the BlueZ source code from bluez.org.
wget http://www.kernel.org/pub/linux/bluetooth/bluez-5.37.tar.xz
-
Unzip the source code.
tar -xvf bluez-5.37.tar.xz
-
Change directories to the newly created folder.
cd bluez-5.37
-
Build BlueZ.
make
-
Install BlueZ once it is done building.
sudo make install
-
Change systemd service configuration for bluetooth so it points to the new bluetooth daemon in the file
/lib/systemd/system/bluetooth.service
. Replace the 'ExecStart' line with the following text:ExecStart=/usr/local/libexec/bluetooth/bluetoothd -E
Before running the sample, you need to verify that your Raspberry Pi 3 can connect to the SensorTag device.
-
Unblock bluetooth on the Raspberry Pi 3 and check that the version number is 5.37.
sudo rfkill unblock bluetooth bluetoothctl --version
-
Execute the bluetoothctl command. You are now in an interactive bluetooth shell.
-
Enter the command power on to power up the bluetooth controller. You should see output similar to:
[NEW] Controller 98:4F:EE:04:1F:DF C3 raspberrypi [default]
-
While still in the interactive bluetooth shell, enter the command scan on to scan for bluetooth devices. You should see output similar to:
Discovery started [CHG] Controller 98:4F:EE:04:1F:DF Discovering: yes
-
Make the SensorTag device discoverable by pressing the small button (the green LED should flash). The Raspberry Pi 3 should discover the SensorTag device:
[NEW] Device A0:E6:F8:B5:F6:00 CC2650 SensorTag [CHG] Device A0:E6:F8:B5:F6:00 TxPower: 0 [CHG] Device A0:E6:F8:B5:F6:00 RSSI: -43
In this example, you can see that the MAC address of the SensorTag device is A0:E6:F8:B5:F6:00.
-
Turn off scanning by entering the scan off command.
[CHG] Controller 98:4F:EE:04:1F:DF Discovering: no Discovery stopped
-
Connect to your SensorTag device using its MAC address by entering connect <MAC address>. Note that the sample output below is abbreviated:
Attempting to connect to A0:E6:F8:B5:F6:00 [CHG] Device A0:E6:F8:B5:F6:00 Connected: yes Connection successful [CHG] Device A0:E6:F8:B5:F6:00 UUIDs: 00001800-0000-1000-8000-00805f9b34fb ... [NEW] Primary Service /org/bluez/hci0/dev_A0_E6_F8_B5_F6_00/service000c Device Information ... [CHG] Device A0:E6:F8:B5:F6:00 GattServices: /org/bluez/hci0/dev_A0_E6_F8_B5_F6_00/service000c ... [CHG] Device A0:E6:F8:B5:F6:00 Name: SensorTag 2.0 [CHG] Device A0:E6:F8:B5:F6:00 Alias: SensorTag 2.0 [CHG] Device A0:E6:F8:B5:F6:00 Modalias: bluetooth:v000Dp0000d0110
Note: You can list the GATT characteristics of the device again using the list-attributes command.
-
You can now disconnect from the device using the disconnect command and then exit from the bluetooth shell using the quit command:
Attempting to disconnect from A0:E6:F8:B5:F6:00 Successful disconnected [CHG] Device A0:E6:F8:B5:F6:00 Connected: no
You're now ready to run the BLE gateway sample on your Raspberry Pi 3.