BACE Webhooks
How to connect BACE to your IoT Application using Webhooks
Introduction
Webhooks are developed to send events to your application(s). The difference with classical API is that a webhook is used to actively push data to an external endpoint, instead of having the third-party poll for data.
In this chapter, we'll give a walkthrough on how to use Webhooks for measurements or events and provide some tips on how to use them most effectively for your application. A general introduction about how to use the BACE Webhooks is given in
How to use BACE Webhooks
Webhooks could be used to synchronize your asset measurements and events to your system. These measurements and events could be stored in your database to be ingested by your IoT application.
The BACE Webhook supports HTTPS URLs, and a static authentication header can be used to publish responses to subscribers. The data is sent by HTTPS Post requests.
For creating a new webhook using BACE Panel, please use following steps in Creating Webhooks
Sending Measurements as a Webhook
Measurements from your assets are forwarded as a webhook response in the order they are received by the IoT Connector. Depending on the sampling rate of IoT connector, you will receive a response for any new measurements retrieved from your assets.
If the IoT Connector cannot retrieve any new measurements from the device, for example when your asset is offline, you will not receive a webhook.
Example of one measurement
Here is an example webhook message for an IoT Connector with one measurement (aka datatype):
Here is the breakdown of all attributes in the webhook response:
Timestamp – Timestamp in milliseconds. This is the exact time of the measurement performed in the field.
Timestamp_seconds – Timestamp in seconds, same as above.
Timestamp_change – Timestamp in milliseconds. This is the time the value was last changed. For example, if the last value is 50, and the previous value is also 50, we don't change the timestamp from the first time we saw "50". Only when the value changes by >0.01 (in either direction) the
timestamp_changed
value updates to the time of that measurement.Datatype: Datatype of stored data. Each measurement type has a predefined or user configured datatype. An IoT Connectivity Module may be reporting the same data type (i.e. 5000 - Temperature) from many customer assets connected to it (i.e. Modbus #1 - Zwave #1)
Value: Value of the measurement.
Relations: Shows the relationship of the measurement:
id_container: Unique id of the container. Each IoT Connectivity Module will have a unique
id_container
.id_group: Unique id of the group. Each IoT Connectivity Module will have a unique
id_group
. This field could be used to interpret which IoT Connectivity Module has sent the measurement.source_device: Unique id of the IoT Connectivity Module or your asset sending the measurement. Each IoT Connector and Zwave device have their own unique ids. This field could be used to interpret which IoT Connectivity Module has sent the measurement. This value is same as
id_physical_device
explained in physical-device endpoint. The IoT Communication Module has a sticker that matches withlabel
attribute in the physical-device endpoint's response.id_container_data_latest: id_container of the latest data for this measurement. This could be useful for particular API calls if you want to request a specific measurement.
label: Predefined or user configurable label of the measurement. You can use generic expressions like "Temperature" or use it in a more descriptive way like "SolarConverter-FaultCode"
unit: Predefined or user configurable unit of the measurement.
icon: User configurable field. This field could be used as a hint to your frontend what icon to use for a given datatype when displaying status indicators.
Each webhook response should contain measurements for one IoT Connector which could be differentiated by its unique group_id
.
Example of Multiple Measurements
When your IoT Connector is configured to retrieve multiple measurements (aka datatypes) from your asset, you can see many data points in one webhook response. The example below shows a device with three different data types in the same response.
Let's breakdown the webhook response above. From the array length, it is understood that IoT Connector with "id_group": "3f813212-63aa-49b5-aa71-c95acbf14ad6"
has sent three measurements.
The first measurement has a descriptive label "label": "WTW-ZehnderE300-OutletTemperature",
which includes asset model & name and name of the value. The report value is "value": 280
per the response.
The second measurement is for a measurement called "label": "Consumption 1"
, and measurement is "value": 165.91600036621094
in "unit": "kWh"
. First and second measurements have the same id_group
and source_device.
Third measurement ia veryom a "label": "Electrical Meter"
connected to IoT Connector. However, the third measurement is received from Z-wave plug so that's why it has a different source_device
than the first two measurements.
Compact Format Overview
Certain gateways, such as BACE Go, can transmit a considerable volume of data, potentially exceeding 1MB in payload size when employing the standard format. Some backend services may find it overwhelming to process such large payloads.
Compact format is optimized to transmit essential data without verbosity. It's a way to retain crucial information in a concise manner to reduce payload size.
Here is the breakdown of all attributes in the webhook response:
groups – Unique id of the group. Each IoT Connectivity Module have a unique
id_group
. This field could be used to interpret which IoT Connectivity Module has sent the measurement.devices: Unique id of the IoT Connectivity Module or your asset sending the measurement. Each IoT Connector and Zwave device have their own unique ids. This field could be used to interpret which IoT Connectivity Module has sent the measurement. This value is same as
id_physical_device
explained in physical-device endpoint. The IoT Communication Module has a sticker that matches withlabel
attribute in the physical-device endpoint's response.datatypes: Datatype of stored data. Each measurement has a predefined or user configured datatype. If the event is related to a specific data type, it will be reported in this attribute. A good example is for Modbus Read-error which might occur when IoT Connector is trying to poll information from a specific modbus register assigned to a data type. Each nested datatype has three attributes:
label: A label can either be predefined or user-defined. It can be generic like "Temperature" or descriptive like "SolarConverter-FaultCode"
id_container_data_latest: id_container of the latest data for this measurement. This could be useful for particular API calls if you want to request a specific measurement.
data: An array where the first item indicates the timestamp (in milliseconds) of the measurement, and the second item denotes its value
Sending Events as a Webhook
Like measurements, any events from your assets, IoT Communication module or IoT connector are forwarded as a webhook response to your HTTP address.
Here is an example webhook message for an IoT Connector with one measurement:
Here is the breakdown of all attributes in the webhook response:
id_event – Unique id of the event.
id_group – Unique id of the group. Each IoT Connectivity Module have a unique
id_group
. This field could be used to interpret which IoT Connectivity Module has sent the measurement.source_device – Unique id of the IoT Connectivity Module or your asset sending the event. Each IoT Connector and Zwave device have their own unique ids. This field could be used to interpret which IoT Connectivity Module has sent the measurement. This value is same as
id_physical_device
explained in physical-device endpoint. The IoT Communication Module has a sticker that matches withlabel
attribute in the physical-device endpoint's response.from_device: If the event is generated by IoT Connector or your asset, the value is 1. If event is generated by IoT Communicator, the value is 0.
event_type – Type of the event. Each event has a different event, (i.e. 202 is an event type reporting connectivity changes and 207 is an event type reporting Over The Air update initiation.
event_type_label: Label of the data. A brief description of the event occurred. In this example above, the IoT Connector is reporting a boot start event.
Occured at – Timestamp in seconds. This is the exact time of the event occurred.
Value: Value of the event. Some event types have a value to provide more details about the event. The label and description of the event is included in the response with two different attributes. As an example, Event 202 is an event that occurs when IoT Connector is booting. The value is 1, if the device is powered on. The value is 3 if the reboot is due to a configuration change requiring reboot.
Datatype: This will be always null for events
event_value_label: Label of the event value. It will be published if the event has a value.
event_value_description: Description of the event value when the event has a value.
Limitations
Webhook count:
We currently limit usage to 2 effective webhooks for a given project. We'll be happy to discuss other options if this doesn't accommodate your need.
Types of data:
Currently only measurements are pushed. However, sending IoT Connector events is in the roadmap.
Delivery Guarantee
While the Webhooks have a retry mechanism and will attempt to ensure no data is left unsent. This is a best effort approach.
The webhook mechanism will check the remote server’s HTTP status code. If the returned code is not a “success“ range (2xx) it will add the attempted data to a retry queue and make an attempt at a later time to resend it. Repeat failures are given an escalating back-off timeout, meaning that for every failed attempt to deliver the data, the next attempt is delayed even longer, to prevent the wasting of our server’s time attempting to deliver data to a party that is unreachable.
The resending of failed delivery attempts is done with no guarantee as to the order data is delivered in:
New incoming data may be delivered before old data is retried.
Retried data may be resent in a different order than it arrived in, due to the escalating timeout mechanism.
The retry queue is purged on a schedule:
Messages that had to be retried, but were successful, are purged after 7 days (for record keeping to evaluate reliability).
Messages that were not delivered are retained for 28 days. After 28 days undelivered data is deleted permanently. This means that if our server is unable to deliver a given data payload to the configured address for the webhook for longer than 28 days, that data is deleted
Testing The Webhook Functionality
The easiest way to test the webhook functionality is by using the external website like webhook.site. Upon opening this website, it will create a unique instance of a webhook endpoint just for you, which is valid for 24h.
You can share the 'Your Unique URL' in the webhook URL with us to connect any group of devices to it that is currently gathering data. As soon as data is available in IoT Connector, it will be forwarded to the webhook and should be visible on this website.
Last updated