Developing a sensor integration
Last modified: Tuesday February 28, 2023.
You can develop an integration for sensors from a number of different sensor manufacturers by using a generic integration. By integrating sensors with Alta Video, data from the sensors is available to all of the tools and features within Alta Video.
Exactly how each sensor integrates into Alta Video Cloud depends on the make and type of sensor, its capabilities, and the available API functions for the sensor. Find this information from the technical documentation provided by the sensor manufacturer.
Sensor integration using direct webhooks
If the sensors support the option to send webhooks in custom formats, configure the webhooks to meet the required Alta Video Cloud data format.
Sensor integration using an intermediate application
Create an application to sit between the sensors and Alta Video Camera Proxy — the application sits between the sensor and Alta Video Cloud, and ensures the webhook sent to Alta Video Cloud are correctly formatted. The application receives messages from the sensor and converts them to the webhooks required by Alta Video.
Some sensors might require an application that uses the sensor API to poll for information that is then converted into the Alta Video Cloud webhooks.
Sources and channels
The Alta Video generic sensor integration can be used for a wide range of scenarios. To achieve this, data is grouped in two ways within the system, and any integration should align with this.
If the sensor data is not suitably aligned, the user may not be able to achieve the desired behavior within Alta Video Cloud.
Sensors can be used to take one or more measurements in one or more places. Overall a sensor can consist of one or more:
- Sources — physical locations where one or more measurements are taken. Sources can be linked to cameras, and placed onto maps in Map view.
- Channels — single measurements taken at a source. Each channel is associated with a source and provides a stream of data.
This means four different types of sensor can be added:
- Single source, single channel — a single measurement is made by the device.
- Single source, multiple channels — multiple measurements are made by a device in a single location. For example an air quality monitor could report multiple values.
- Multiple sources, single channel per source — the device reports a single piece of information from multiple physical locations. For example a sensor that measures the temperature in several distinct rooms. By doing this as multiple sources, each temperature measurement can be displayed in a separate location in Map view, and have different cameras associated with each source.
- Multiple sources, multiple channels per source — a combination of the above.
The decision on whether to use one device with multiple sources, or to appear as multiple devices each containing a single source depends on the following factors:
- The capabilities of the sensor. If the chosen sensor can send webhooks natively, but only to one address, then it will need to be treated as a single device with multiple sources.
- Heartbeats are per device, so if communicating that one source is offline is important, then consider separate devices per source.
- It the device has a fixed number of inputs, such as 8 sets of terminal blocks, then consider making these multiple sources within a single device.
- The ease of adding devices to Alta Video Cloud and configuring the sources depends on how many sources and channels are in each device. By having one source per device, more devices need to be added, but less configuration is required for each one.
Each channel within the sensor must be of a single type, but a sensor can include several channels, with a different type of data for each channels.
A sensor might send temperature measurements on one channel, and air pressure measurements on another channel.
An application can interact with multiple sensors, and can then present these to Alta Video Cloud as either separate sensors with their own individual webhooks, or as a single, larger multi-source sensor with each channel uniquely identified.
If the application is acting as a single, larger, sensor, the heartbeat mechanism for detecting whether a device is offline applies to the whole sensor.
Messaging
The sensor, or the application, sends updates to a webhook address on Alta Video Cloud using HTTP POST.
Alta Video Cloud needs to receive these updates at a suitable frequency that includes all changes of status or significant sensor value changes. The exact timing and the sizeof the sensor value changes depends on the types of sensor being used and the specific requirements for the integrations.
Sending updates at high frequency might impact the usability of the Alta Video Cloud deployment.
Multiple channels can be updated concurrently, but you do not need to update all channels in a single message.
Send the payload to Alta Video Cloud as an array of JSON objects in the format:
[{message1},{message2},{message3}]
When sending data for a single channel, the data should still be formatted as an array, containing a single item:
[{message1}]
Each message must consist of the following fields:
"channel_id"
of type string - uniquely identifies the channel within the sensor. The matching value should be specified when configuring each of the channels when adding this sensor to Alta Video. It is up to the integration to determine how to uniquely identify the channels. These could be:- The channel number; “0”, “1”, etc.,
- The measurement type, for example, “temperature”, “pressure”
- Based on some hardware property of the sensor such as the MAC or serial number.
"value"
of type float - the value of the sensor reading, expressed as a float value. If the sensor is of a Boolean type, then send 0 or 1 in the value field."timestamp"
of type (unsigned) integer - the number of milliseconds since 01/01/1970 00:00:00 UTC. This is the UTC timestamp of the event based on the UNIX epoch. If using a Unix system, this is the regular UNIX timestamp multiplied by 1000."status"
of type string - indicates the sensor status and can take one of the following values:“normal”
- used when the value is within expected values“warning”
- used for minor issues“alarm”
- used for more serious issues
An example of the total payload sent to Alta Video Cloud is:
[{"channel_id": "1","value": -23, "timestamp": 1633711926000,"status": "normal"},
{"channel_id": "7","value": -15, "timestamp": 1633711926000,"status": "alarm"}]
Heartbeat messages
Each sensor, or application, must send periodic messages. Alta Video Cloud uses the lack of messages to determine whether the sensor is offline, and so the frequency of messages should be known and used as part of the configuration of the sensor in Alta Video Cloud. Failure to send periodic messages will lead to the sensor appearing offline within Alta Video Cloud
In addition, sending of heartbeat messages allows Alta Video Cloud to learn the current state of the sensor after any restart of Alta Video deployment. After restarting, Alta Video Cloud will not display a value for a sensor until a message has been received for the channel. Therefore sending data for all channels in a heartbeat message allows Alta Video Cloud to learn the current values in a timely manner.
Documenting your integration
When you develop an integration with Alta Video Cloud, you should also document that integration. The documentation needs to include:
- How to get, install, and run any external application that is needed for the integration with Alta Video Cloud.
- The settings in the extension code that are needed. For example, the settings required to receive messages from the sensors.
- Any required sensor configuration. For example, to ensure the sensor sends messages to a specific place.
- Configuration of the Alta Video Cloud user interface. Document the data to be used, most critically around channel names to be entered, which should link back to anything already defined.
- How to get the webhook URL from Alta Video Cloud and where this information needs to be entered in the sensor integration.