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
  • Overview
  • Prerequisites
  • Creating an Emulated Device
  • Emitting Emulated Events

Was this helpful?

Emulator API

An introduction to our Emulator API, accessible through both DT Studio and REST API.

Last updated 1 year ago

Was this helpful?

Overview

If you don't have access to physical sensors and want to test our services, the Sensor Emulator API gives you the ability to create and experiment with devices at will. An emulated sensor is designed to have all the features of a real sensor, making it a valuable tool for experimentation or debugging.

  • Explore DT Studio without the need for real sensors.

  • It can be interacted with through the REST API.

  • Emit any event type at will by simply clicking a button.

  • Generate events in your CI flow to automate integration tests.

You can find a list of all available emulator endpoints at our .

Prerequisites

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

Creating an Emulated Device

In DT Studio, navigate to the project in which you want to create the emulated sensor. In the left-most menu, locate the API Integrations -> Emulator page. Click Create Device.

Under the new device creation page, select a Device Type. A Device name and labels are optional but can be useful when managing several emulated devices at once.

Remember to Save New Emulated Device.

Send a POST request to:

https://emulator.d21s.com/v2/projects/<PROJECT_ID>/devices

A request body with the following parameters is required.

{
    "type": "temperature"
}

Example Usage

Using cURL with a Service Account for authentication, the following example creates a new emulated temperature sensor with a given name and a "group-number" label.

curl -X POST "https://emulator.d21s.com/v2/projects/<PROJECT_ID>/devices" \
    -u "<SERVICE_ACCOUNT_KEY_ID>":"<SERVICE_ACCOUNT_SECRET>" \
    -d '{"type": "temperature", "labels": {"name": "my-emulated-sensor", "group-number": "99"}}'

Example Usage

Using our Python API with Service Account credentials for authentication, the following example creates a new Emulated Temperature Device.

import disruptive as dt

device = dt.Emulator.create_device(
    project_id='<PROJECT_ID>',
    device_type=dt.Device.TEMPERATURE,
)

print(device)

Emitting Emulated Events

Events can be emitted at will using an emulated device.

In DT Studio, navigate to the project containing your emulated sensors. In the left-most menu, locate the API Integrations -> Emulator page. Click on your emulated device.

Under the details page of your emulated device, select the Event Type and related value you wish to emit. When set, click Send Event for immediate effect.

Send a POST request to:

https://emulator.d21s.com/v2/projects/<PROJECT_ID>/devices/<DEVICE_ID>:publish

Note: The updateTime field is optional for all event types, and defaults to now.

Example Usage

As an example, to publish a temperature event, include the following body in the POST request.

{
    "temperature": {
        "value": 42
    }
}

Using cURL with a Service Account for authentication, the following example emits a temperature event from the specified emulated temperature sensor.

curl -X POST "https://emulator.d21s.com/v2/projects/<PROJECT_ID>/devices/<DEVICE_ID>:publish" \
    -u "<SERVICE_ACCOUNT_KEY_ID>":"<SERVICE_ACCOUNT_SECRET>" \
    -d '{"temperature": {"value": 42}}'

Example Usage

import disruptive as dt

dt.Emulator.publish_event(
    device_id='<DEVICE_ID>',
    project_id='<PROJECT_ID>',
    data=dt.events.Motion(
        state='MOTION_DETECTED',
    ),
)

A list of all available parameters can be found in our .

Once the package is installed and authenticated as described in the , a new Emulated Device can be created by calling the following resource method.

The body of the POST request should be the to be published. The type of the published event must match the device type of the emulated event. For example, an emulated temperature sensor can't send objectPresent events. An overview of which events types are available for a given device type can be found .

Once the package is installed and authenticated as described in the , an emulated event can be published by calling the following resource method.

Using our Python API with Service Account credentials for authentication, the following example published a new to an emulated .

REST API Reference
Python API Reference
disruptive.Emulator.create_device()
Python API Reference
disruptive.Emulator.publish_event()
REST API Reference
event
motion event
here
motion sensor