Connecting a BLE wireless SoC board to update a Cloud dashboard via a industrial gateway
This application note explains the complete setup and sample script to send environmental data, e.g. temperature from a BLE sensor board to a cloud dashboard using our industrial nodeG5 gateway.
This exercise uses the following
Let's get started
We will not go deep into programming the XG24 development board which can be done using Simplicity Studio 5 IDE for C development.
Fig 1. Programming the BLE XG24 development board using Simplicity Studio.
To prepare the XG24, we used the sample bt_doc_thermometer C application, which first enables a remote Bluetooth host (nodeG5) to pair with the board and then send temperature readings to the gateway. We will then build and flash the .hex file over to the board.
We have also included a demo script \amp\iot\BTdata2DB.py inside the NodeG5. This script (1) connects to the XG24 dev board via Bluetooth BLE to receive the temperature readings then (2) writes the data (temperature) onto the board's data store for an active IoT Cloud client to send the data out.
Let's first begin by enabling the Bluetooth radio in the nodeG5. To do this you will need to log into the NodeG5's web configuration menu & select the 'IOT Hardware Setup' option in the left menu pane. Enable it by switching “Bluetooth Radio” to “On”.
Do note that the gateway needs to be rebooted to activate the radio (and once this is done it will be enabled in future reboots).
Next, we need to check the BLE sensor board’s MAC Address and UUIDs using [bluetootctl]
The user can now check the Bluetooth Assigned Numbers documents i.e. the GATT UUIDs (i.e. for Device Service and Parameter Characteristics) and also data types used for the temperature data sent to our gateway.
The user will now also have the MAC and UUID that is needed for the Python script.
SERVICE_UUID = “00001809-0000-1000-8000-00805f9b34fb”
CHARACTERISTIC_UUID = “00002a1c-0000-1000-8000-00805f9b34fb”
DEVICE_MAC_ADDRESS = “68:0A:E2:4B:D4:0C”
The script uses the Python Bleak package to connect and manage the Bluetooth connection with the XG24 board.
The program then waits for notification of data received from the device 0x1809 Health Temperature and specific GATT Characteristics, i.e. temperature 0x2A1c
A Python asyncio notification handler will be initiated to wait for temperature data bytes from the service i.e. our prototype “Healthcare Temperature” sensor apparatus.
Each time the gateway receives a data packet from the temperature sensor board over BLE, the write_data_measurements() function will process the received bytes and write the temperature data to the gateway’s database. The user can choose to further process the data, e.g. statistically or send the data to a Cloud back-end or server (e.g. MQTT)
In this demo, the data is sent to a cloud dashboard service, Ubidots over LTE with the integrated data client. The nodeG5 gateway also supports AWS Iot Core, Azure IoT Hub/Central and also can link up to cloud services via a TLS secured MQTT client (example below).
In this demo, the sensor board’s temperature data is visualised as a graphical real-time widget.