Third-Party Sensor Data in DT Cloud
Introduction
When using Disruptive Technologies sensors, your data is continuously captured and forwarded by a Cloud Connector to the DT Cloud where it is stored for 31 days. While our current range of devices already covers many use cases, some sensor types, like barometric pressure, are yet not in our repertoire. However, while we continue to expand our offerings, a method of including third-party sensor data into our cloud does exist.
In this application note, we will take a look at how a Raspberry Pi can be used to sample barometric pressure data from a Mikroe Environment Click breakout board, then periodically publish events to the DT Cloud using our Python Emulator API. This lets the third-party pressure data propagate our cloud just like any first-party sensor, allowing you to effortlessly expand your integrations.
Prerequisites
Development Platform A Raspberry Pi or any other development board that can connect to our REST API. It is assumed that you are at least familiar with your platform of choice.
Third-Party Sensor An Environment Click or any other third-party sensor that can be sampled by your platform.
Service Account Creating, deleting, and interacting with emulated devices require that your User or Service Account has been granted the role of Project Developer or higher.
DT Studio Configuration
Only minimal DT Studio setup is required to recreate the steps in this application note.
Navigate to the DT Studio project into which to forward your third-party sensor data.
Make sure you have a Service Account with a role of Project Developer or higher that is granted membership in the project.
For each third-party sensor data stream, you wish to forward, Create An Emulated Sensor. We will use the Temperature Sensor type as a proxy to our data, even though we sample pressure data.
Take note of both the sensor- and project IDs as these will be used for publishing the events.
Implementation
This application note uses a Raspberry Pi with an Environment Click breakout board, but the implementation would be the same for any other platform. However, the GPIO pins and Python environment makes the Pi a good choice for quick and easy prototyping.
Raspberry Pi 3 Model A+
It is assumed that your Pi is set up with the latest version of Raspberry Pi OS and has a working internet connection. If you're unfamiliar with this process, you should read the official introductory guide.
Enabling I2C
We'll be using the I2C communication protocol to exchange information between the Pi and Environment Click breakout board. By default, this is disabled on the Pi, but can be enabled through the shell.
sudo raspi-config
-> Interface Options > I2C > Enable
Python Environment
We'll use the Disruptive Python API to publish emulated sensor events with only a few lines of code. Therefore, a working Python 3 environment must be configured.
Install Python 3.7 or greater, either through the use of Pyenv or the official repository with
sudo apt install python3 python3-pip
.Install the Disruptive Python API package with
pip3 install disruptive
.Additionally, install any device driver packages to interact with your sensor. For our Environment Click board which hosts the Bosch bme680 sensor, Adafruit has a readily available package we can use
pip3 install adafruit-circuitpython-bme680
.
Mikroe Environment Click
The Environment Click requires no configuration other than connecting it to the Pi.
As we're using I2C, connect the SDA and SCL pins between both devices.
Power the breakout board using the Pi 3V3 and GND pins.
Sample and Publish Events
Once you have a working Python 3 environment and the breakout board is connected, the sensor can be sampled by the Pi, then published as an event to the DT Cloud. The following snippet does exactly this.
Authenticate the Disruptive Python API package using your Service Account credentials.
Initialize an instance of the bme680 sensor which the Pi will sample every 1 second.
For each new pressure sample, append a buffer list for storage between publishing events.
Once every 60 seconds, publish the median pressure value to an emulated device.
Remember to replace variables on the form <VARIABLE>
with your own details.
You probably notice that we use the temperature event to publish our data. This is because a pressure event type does not exist, and since the data type is simply a floating-point number, it does not matter.
Viewing Your Data in DT Studio
Once your script is running on your Raspberry Pi, head over to DT Studio. Here you should see the sensor data updating at each publishing interval. Using the Dashboard, a card can be created to inspect how your data behaves over time.
Again, our cloud thinks the data is from a temperature sensor, but this is only a visual side-effect. If you choose to interact with- or forward the data it is, of course, unaffected.
Next Steps
Now that your third-party sensor data is in our cloud, all services that are available to our first-party devices can be utilized. Here are a few examples of what you can do with your data.
Last updated