Please note: The information in this article was from 2019 before the introduction of thin-edge.io. It is possible to integrate Apama running on a Raspberry Pi with Cumulocity IoT by using the thin-edge.io components.
Thin-edge.io and Apama Community Edition - Knowledge base - Software AG Tech Community & Forums
Let’s 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.
// Name: Spike
// Version: 2.0.0.0
// Row: 0
com.industry.analytics.Analytic("Spike",["TemperatureData"],["Spikes","avg:Moving Average","upper:Upper","lower:Lower"],{"verbose":"false","timeWindow":"60.0d"})
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:
Introduction to Python Plug-ins - Knowledge base - Software AG Tech Community & Forums
temperature = round(getTemperatureFromSenseHat(),2)
plugin.getLogger().info("temperature is " + str(temperature))
evt = Event('Temperature', {"reading": str(temperature)})
Correlator.sendTo("monitor_messages", evt)
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 set up 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!