This project combines Raspberry Pi 3 Model B+, RadBeacon Dot and WolkAbout IoT Platform to report the presence of discovered Bluetooth devices. You can use devices other than RedBeacon Dot, as long as you have access to the Bluetooth device address. The discovery of Bluetooth devices will be done at every user-defined interval. If the list of discovered devices contains the addresses that were defined by the user, then the information of their presence or absence will be sent to the cloud.
Considering that there is no need for actual wiring other than connecting the power supply to the Raspberry Pi, what you need is access to the Raspberry Pi either via SSH or by connecting a monitor and a keyboard to it.
Software setupThis project uses two repositories: WolkGateway and WolkGatewayModule-Bluetooth.
WolkGateway bridges communication between WolkAbout IoT Platform and multiple non-IP-enabled devices connected to it through modules. The modules enable communication with subordinate devices by implementing the device’s network communication protocol on one end (Bluetooth in this project), and parse data between the Mosquitto MQTT broker on the other end.
Start with connecting to the Raspberry Pi and cloning the WolkGateway repository:
git clone --recurse-submodules https://github.com/Wolkabout/WolkGateway.git
After that, install WolkGateway’s dependencies by running:
sudo apt-get install mosquitto cmake python python-pip && sudo python -m pip install conan
Now that the dependencies are installed change directory into WolkGateway and run the configure.sh
script. This script will prepare the build system and compile OpenSSL. Because of the limited hardware capabilities, this step will take some time (up to 10 minutes), so while waiting for this step to finish, create a gateway on WolkAbout IoT Platform.
Head over to demo.wolkabout.com and register/log in with your account. Next, switch to the Device Management tool from the application menu.
Press + and from the dropdown menu select Create device without device type.
Enter the name for the gateway and the optionally a device key.
Set the Protocol to WolkAbout MQTT Gateway, Connectivity Type to MQTT and Sub device Management to GATEWAY.
Tick the checkbox for Create Default Semantic and click Save.
A pop-up will appear with the gateway name and the key, as well as its password.
Save this information by using one of the options from the bottom on the left as you will need to enter it into WolkGateway/out/gatewayConfiguration.json.
After the configure.sh
script finishes, change directory to WolkGateway/out/ and run make
. To run the application correctly, you need to enter device credentials into gatewayConfiguration.json:
{
"name": "",
"key": "",
"password": "",
Before running the gateway application, make sure that Mosquitto is running by invoking
systemctl start mosquitto
Then start the application with
./WolkGatewayApp gatewayConfiguration.json
After a couple of seconds, the gateway will connect to the Platform and perform its initial configuration, after which it is possible to register devices through the gateway.
For easier use, create a service that will run the gateway by creating a new file wolk_gateway.service and copy the content from the project’s attachments. Make changes to the username and the path if necessary. Then move it and enable it with the following commands:
sudo mv wolk_gateway.service /lib/systemd/system/wolk_gateway.service
sudo chmod 644 /lib/systemd/system/wolk_gateway.service
sudo systemctl daemon-reload
sudo systemctl enable wolk_gateway.service
sudo systemctl start wolk_gateway.service
To check the state of the service use
sudo systemctl status wolk_gateway.service
, and also use restart stop disable
if needed.
This completes the setup for WolkGateway repository resulting in a service that will forward the data from the Bluetooth module to WolkAbout IoT Platform.
Change directory to home/<user> and clone the WolkGatewayModule-Bluetooth repository:
git clone --recurse-submodules https://github.com/Wolkabout/WolkGatewayModule-Bluetooth.git
After that, install WolkGatewayModule-Bluetooth’s dependencies by running:
sudo apt-get install autotools-dev autoconf libtool m4 zlib1g-dev cmake python python-pip && python -m pip install conan
Now change directory to WolkGatewayModule-Bluetooth/dependencies and run the install_bluez.sh
script that will install BlueZ, which is a Bluetooth stack for Linux kernel-based family of operating systems. After installing BlueZ, it's recommended you reboot your system and check whether it was updated by invoking bluetoothctl -v
- it should display 5.50.
After confirming that Bluetooth is running, change back into the WolkGatewayModule-Bluetooth directory and run the configure.sh
script. This time the configure.sh
script will take considerably less time to complete as OpenSSL will already be compiled and cached. Next, change the directory to WolkGatewayModule-Bluetooth/out/ and run make
.
Now that you have built the project, the next step is to enter Bluetooth device addresses into deviceConfiguration.json. You can find this information on the label of the RadBeacon Dot, but, if you are using some other device, find a way to obtain the address.
{
"host": "tcp://localhost:1883",
"readingsInterval": 15,
"devices": [
{
"name": "RadBeacon1",
"key": "0C:F3:EE:B3:B5:8D"
},
{
"name": "RadBeacon2",
"key": "0C:F3:EE:B3:B4:35"
}
]
}
The scanning interval is in seconds and can be modified by changing the readingsInterval field.
Now, you can start the module application with
sudo ./bluetoothModule deviceConfiguration.json
It will send a registration request for the devices entered into the list in deviceConfiguration.json through the gateway to WolkAbout IoT Platform.
Following the same steps as for wolk_gateway.service, create a service for the Bluetooth module using the bluetooth_module.service file from the project’s attachments.
To display the current presence of multiple devices, create a new data semantic.
Open Data Management from the application menu and create a new semantic group.
Then add feeds to the semantic, selecting the Presence from each of the beacons.
And then click Save.
Now we can create a dashboard that will display this semantic group
Give your dashboard a name and set the scope to the previously created semantic group.
Now add Reading widgets for each device's presence.
You can now monitor the presence of your Bluetooth devices in real time using the dashboard widgets as well as over time using reports.
For more information about WolkAbout IoT Platform's features, you can visit our User Guides page.
Comments