HTTP Downlinks
How to send HTTP Post or Get Requests as Downlinks and how to configure those.
Intro
This documentation explains how to set up HTTP downlinks on the Datacake platform for API devices. The document will walk you through configuring downlinks, triggering downlinks based on measurements, and integrating these downlinks into dashboards and the rule engine. The HTTP downlink feature is designed to work with devices that are connected to Datacake via HTTP and MQTT integrations.
Setting Up HTTP Downlinks
Video
Learn everything about HTTP Downlinks in the following video:
Creating a New HTTP Downlink
Access the Device Settings: Navigate to your API device settings on the Datacake platform.
Add a New Downlink: In the downlink configuration section, click "Add Downlink."
Name and Describe the Downlink: Provide a name and description. For example, "My first HTTP downlink" and a description like "This downlink sends HTTP requests to a specified URL."
Choose the Downlink Type: Select "HTTP Downlink" as the downlink type.
Configuring the HTTP Request
Define the HTTP Method and URL:
In the downlink editor, define the HTTP method (e.g., POST, GET) and provide the URL to which the downlink should send requests.
Set Up Optional Parameters:
Configure additional settings such as query parameters, headers, and the request body. For example:
Testing the HTTP Downlink:
Use the "Try Decoder" feature to test the downlink configuration. This simulates sending a request and displays the method, URL, headers, and body structure that will be sent.
Saving and Applying the Downlink
Save the Downlink Configuration: Click "Save" to create the downlink.
Verify Downlink Creation: The platform will notify you once the downlink has been successfully created.
Trigger the Downlink: You can trigger the downlink manually from the device's interface or use conditions such as measurements and time-based scheduling.
HTTP Downlink Examples
This section provides super simple examples of how to create downlinks that make POST and GET requests to a third-party API. These examples show how to utilize the given Encoder
function without accessing any measurement data, making it easy to understand and use as a template.
You can copy and paste those code examples into the Downlink Encoder view.
Overview
The Encoder
function can be used to create POST and GET requests. Below are basic examples that demonstrate how to:
Call a POST request without utilizing any measurement data.
Call a GET request with custom query parameters.
HTTP POST Request Downlink
Plain POST Request without Measurements
POST Request using Measurements
POST Request using selected device data
This example demonstrates how to safely access a database field called TEMPERATURE
and how to include it in the POST request. The try...catch
block ensures that any errors in accessing the measurement field are handled gracefully.
POST Request with Authentication
Produces the following output:
GET Request Downlink Examples
The following example shows you how to create a downlink to call the following URL as GET-Request using query-parameters:
URL:
https://api.example.com/device-status?device_id=018097a2-26dd-436e-9460-8492b848b481&device_name=Datacake-Device&status=active&type=sensor
Advanced Topics
For sure, it is possible that using the downlink encoder, which gets executed every time the user sends a downlink, the rule engine triggers a downlink, or writing into a field automatically triggers a downlink.
So this code snippet gets executed. That means you could use the code snippet to check against measurement while in use, but also use other techniques, code functionalities like time checks or counters if the downlink really needs to be sent.
Example
If you need any assistance in writing code, please reach out to us. We are happy to help.
Triggering HTTP Downlinks Based on Measurements
Downlinks can be automatically triggered upon receiving a measurement on the device. This functionality enables automatic responses based on real-time data, such as checking if a measurement falls within the desired target range or validating if the device's configuration matches expected values. This is particularly useful for scenarios where an immediate action is required, such as sending a configuration update when certain conditions are met.
If you want to know more about this feature, we have a detailed "how to" available on our documentation for you:
Using the "Trigger on Measurements" Feature
Enable Measurement-Based Triggers: In the downlink editor, enable the "Trigger on Measurements" option.
Define the Measurement Field: Specify which measurement field (e.g., temperature, humidity) will trigger the downlink. This field should correspond to a measurement being recorded by the device.
Accessing Measurement Values:
Use the
measurements
object to access recorded values. For example, to access a temperature value, use:
Testing the Downlink with Measurements: Use the "Try Decoder" feature to validate that the downlink correctly includes the measurement values.
Integrating HTTP Downlinks into Dashboards
Adding a Downlink Widget to the Dashboard
Edit the Dashboard: Navigate to the device's dashboard and click "Edit Dashboard."
Add a New Widget: Select the "Downlink Widget" from the list of available widgets.
Select the Downlink: Choose the HTTP downlink you created and configure the widget’s name, appearance, and color settings as needed.
Save and Test the Widget: Save the changes and test triggering the downlink directly from the dashboard widget.
Viewing Downlink Status and Debugging
Access Debug Information: After triggering the downlink, access the "Debug" tab to view detailed information about the HTTP request.
Review the Response: Check the status code and any returned data to verify successful execution.
Using HTTP Downlinks in the Rule Engine
HTTP downlinks are fully compatible with our new rule engine. This will allow you, for example, to send a downlink based on a measurement. If the same device or any other device in your workspace has met or reached a threshold, you can send a downlink to a different device.
Our new rule engine also allows you to send downlinks via a schedule. For example, you can create a single rule to send a downlink at 9 a.m. to hundreds of devices.
If you are interested to learn more about Downlink Scheduling, here's a great how-to guide for you:
How to Schedule Mass-Downlinks (Multicast) using Datacake Rule Engine
Setting Up Rules for HTTP Downlinks
Open the Rule Engine: Navigate to the Rule Engine section of the Datacake platform.
Create a New Rule: Click "Add Rule" and choose the device you want to configure.
Choose a Trigger Type:
Time-Based Triggers: Set the rule to trigger the downlink at specific times (e.g., every day at 9:00 AM).
Measurement-Based Triggers: Configure the rule to send a downlink when a measurement (e.g., temperature) reaches a certain value.
Configuring the Rule Action
Select the Downlink: Choose the HTTP downlink created earlier as the action for this rule.
Define Additional Conditions: Add any additional conditions, such as sending the downlink only when the device is online.
Saving and Activating the Rule
Save the Rule: Once all configurations are complete, save the rule.
Activate the Rule: Ensure the rule is activated so that the downlink is triggered automatically based on the defined conditions.
Last updated