Skip to main content

Introduction to integrating sensors

To use live data streams from real sensors, the sensor stream must first be integrated to provide the data to SA Engine.

Some sensor integrations already exist, but for many use cases a specific sensor is needed, and a custom integration has to be created. This section contains reference implementations and guides on how to integrate your own sensor using different approaches.

Existing integrations

A few examples of integrations that already exist are used in other guides in this documentation.

In the Detect-Shake use case, the accelerometer and some other sensors are accessed. This is enabled by foreign functions; in the Android app downloaded in the guide, the sensors are accessed through the android java interface.

In the Querying the microphone guide, the audio() function is used to acces the microphone on a PC. This is implemented using java foreign functions.

The Computer Vision system model uses python foreign functions to access images.

There are also examples of the sensor integration strategies described below. These can be used directly or used as reference implementations.

Create your own sensor integration

Access the sensor data

How to best integrate a sensor with SA Engine depends on the edge platform and the hardware and software interfaces that the sensor provides.

Serial streamer

Data streams that are sent on the serial port can be read directly using the Serial streamer function.

This function is used in Arduino UNO.

Pipe pump

On Linux-based systems, data can be piped from other processes to SA Engine using stdin/stdout. A data generator program is written in a language that is recommended by the sensor provider, for example Java, C or Python. It polls the sensors and sends the data to standard out. In SA Engine, a process running the data generator is started by a pipe pump that is set up to subscribe to the standard out of the process.

Overview of a pipe pump integration. The data generator reads the sensors and sends data to SA Engine.

This functionality is used in BME280.

A step-by-step walkthrough of how to implement this integration is found in Custom sensors with pipe pump.

Foreign functions

If the sensor is accessed in another programming language, but a pipe pump cannot be used, for instance if the edge runs on Windows, a more custom approach can be applied using foreign functions. A foreign function is an SA Engine function that can call functions in other programming languages, using the plugin interface. These foreign functions can be set up to pass sensor data into SA Engine.

SA Engine can also be embedded in other programs and receive calls through the client interface.

Both client and plugin interfaces are available in C, C++, Lisp, Java, Android and Python.

Represent the signal

To describe a sensor in the OSQL language, the built-in type Signal is used. It comes with properties such as name and signal_stream. This metadata model is called the sensor ontology.

Read about this in the Data stream wrappers section of the OSQL tutorial.

It is recommended to create a subtype of Signal to describe your signal in your data stream wrapper.