Apama on the Thin Edge with Cumulocity IoT

In this blog, we will look at how we can use Apama running on the Raspberry Pi to act as a “Thin Edge” device, and integrate it with Cumulocity IoT Cloud.

A “Thin Edge” platform is designed to handle a potentially large amount of data generated by sensors/devices, perform additional analytics on that data, and then communicate the results (e.g. calculated aggregate values, alarms, etc.) back to a “Thick Edge”/Cloud deployment.  This reduces the amount of data that needs to be published from the edge to the cloud, thus also reducing the overall network and data storage costs.

In this case, for our “Thin Edge” device we are using the humble Raspberry Pi with a SenseHat mounted, and Apama installed on it.

As a simple demonstration of the capabilities, we are reading the temperature sensor data from the Raspberry Pi SenseHat device, and calculating a time-weighted moving average from it.  We also calculate a Bollinger Band to show the volatility of the temperature over time.

Performing the statistical analysis of the temperature is simple using the Industry Analytics Kit.  The pre-built “Spike” analytic in the Industry Analytics Kit provides all the functionality that we require.  It even provides us with the built in rule to generate an event whenever there is a spike in the temperature that breaches this nominal band (e.g. to warn us of overheating), which we publish to Cumulocity IoT as alarms.

The task of getting the Raspberry Pi SenseHat data into Apama is made simple with Apama 10.3 thanks to the inclusion of Python plugin support which is covered in this Blog article.

We also use the Apama Cumulocity IoT Transport to send data to our Cumulocity IoT Cloud tenant. The Cumulocity IoT Raspberry PI Agent is also installed on the Raspberry Pi, so that we can use the built-in functionality to register the Raspberry Pi and directly access the sensor data from it.

In the Cumulocity IoT Cloud tenant we can display all the data really simply on a dashboard with a graph, radial dials, and the list of alarms that have been generated.  We can even setup another set of Cumulocity IoT Smart Rules on the raw or calculated values that we are publishing.

All the materials, code and templates are available on GitHub for you to extend and enhance. Enjoy!

— Nigel Milham