DT Developer Docs
REST APIDT StudioStatus Page
  • Getting Started
  • Overview
  • Concepts
    • Devices
    • Events
    • Topics
      • Temperature Measurement Interval
      • Motion Sensor Activity Timer
  • Data Connectors
    • Introduction to Data Connectors
    • Creating a Data Connector
    • Configuring a Data Connector
    • Receiving Events
    • Best Practices
    • Example Integrations
      • Heroku
      • Google Cloud Functions
      • AWS Lambda
      • Azure HTTP Triggers
      • IBM Cloud Actions
    • Development Guides
      • Local Development with ngrok
  • REST API
  • Introduction to REST API
  • Explore Our Endpoints
    • with cURL
    • with Python API
    • with Postman
  • Authentication
    • OAuth2
    • Basic Auth
  • Error Codes
  • Emulator API
  • Examples
    • Pagination
    • Streaming Events
    • Touch to Identify
    • Refreshing Access Token
  • Reference
  • Status Page
  • Service Accounts
    • Introduction to Service Accounts
    • Creating a Service Account
    • Managing Access Rights
    • Permissions
    • Organizational Structures
  • Other
    • Application Notes
      • Generating a Room Temperature Heatmap
      • Modeling Fridge Content Temperatures
      • Outlier Detection on Multiple Temperature Sensors
      • Simple Temperature Forecasting for Substation Transformers
      • Sensor Data Insight with Power BI and Azure
      • Third-Party Sensor Data in DT Cloud
    • Frequently Asked Question
Powered by GitBook
On this page
  • Introduction
  • Prerequisites
  • DT Studio Configuration
  • Implementation
  • Raspberry Pi 3 Model A+
  • Mikroe Environment Click
  • Sample and Publish Events
  • Viewing Your Data in DT Studio
  • Next Steps

Was this helpful?

  1. Other
  2. Application Notes

Third-Party Sensor Data in DT Cloud

Last updated 1 year ago

Was this helpful?

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 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 can be used to sample barometric pressure data from a breakout board, then periodically publish events to the DT Cloud using our Python . This lets the third-party pressure data propagate our cloud just like any first-party sensor, allowing you to effortlessly expand your integrations.

Prerequisites

DT Studio Configuration

  1. Navigate to the DT Studio project into which to forward your third-party sensor data.

  2. Make sure you have a Service Account with a role of Project Developer or higher that is granted membership in the project.

  3. 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+

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

  1. Install the Disruptive Python API package with pip3 install disruptive.

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.

  1. Initialize an instance of the bme680 sensor which the Pi will sample every 1 second.

  2. For each new pressure sample, append a buffer list for storage between publishing events.

  3. 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.

import time
import statistics

import adafruit_bme680
import board
import disruptive as dt

# Publishing-related constants.
PUBLISH_INTERVAL = 60  # seconds
PROJECT_ID = '<YOUR_PROJECT_ID>'
DEVICE_ID = '<YOUR_EMULATED_DEVICE_ID>'

# Authenticate the disruptive package.
dt.default_auth = dt.Auth.service_account(
    key_id='YOUR_SERVICE_ACCOUNT_KEY_ID>',
    secret='YOUR_SERVICE_ACCOUNT_SECRET>',
    email='<YOUR_SERVICE_ACCOUNT_EMAIL>',
)

# Create sensor object, communicating over the board's default I2C bus.
i2c = board.I2C()
bme680 = adafruit_bme680.Adafruit_BME680_I2C(i2c)

# Set sea-level barometric pressure to match your location.
bme680.sea_level_pressure = 1006  # hPa

# Initialize a buffer list to hold values between publishing.
pressures = []

# Start a timer for tracking publishing interval.
t0 = time.time()

# Suspend in an infinite loop, exiting at KeyboardInterrupt.
try:
    while True:
        # Read and append barometric pressure reading from bme680.
        pressures.append(bme680.pressure)

        # Print new pressure value to stdout.
        print(f'Pressure: {pressures[-1]:.2f}')

        # Check timer interval.
        if time.time() - t0 > PUBLISH_INTERVAL:
            # Have pressure be the median buffer value.
            pressure = statistics.median(pressures)

            # Publish a new event for the emulated device.
            dt.Emulator.publish_event(
                device_id=DEVICE_ID,
                project_id=PROJECT_ID,
                data=dt.events.Temperature(pressure),
            )

            # Reset timer, clear list, and tell stdout what you did.
            t0 = time.time()
            pressures = []
            print(f'Published event with value {pressure:.2f}.')

        # Sleep for a second.
        time.sleep(1)

except KeyboardInterrupt:
    pass

Viewing Your Data in DT Studio

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.

Development Platform A 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 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 has been granted the role of Project Developer or higher.

Only minimal setup is required to recreate the steps in this application note.

For each third-party sensor data stream, you wish to forward, . We will use the Temperature Sensor type as a proxy to our data, even though we sample pressure data.

It is assumed that your Pi is set up with the latest version of and has a working internet connection. If you're unfamiliar with this process, you should read the .

We'll use the 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 or the official repository with sudo apt install python3 python3-pip.

Additionally, install any device driver packages to interact with your sensor. For our Environment Click board which hosts the sensor, has a readily available package we can use pip3 install adafruit-circuitpython-bme680.

Authenticate the package using your Service Account credentials.

You probably notice that we use the 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.

Once your script is running on your Raspberry Pi, head over to . 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.

Raspberry Pi
Environment Click
Service Account
DT Studio
Raspberry Pi OS
official introductory guide
Disruptive Python API
Pyenv
Bosch bme680
Adafruit
Disruptive Python API
DT Studio
Examples of how to integrate with various cloud services
Building a real-time heatmap
Outlier detection on multiple data streams
range of devices
Raspberry Pi
Mikroe Environment Click
Emulator API
Create An Emulated Sensor
temperature event