Article by: Paolo Caressa. March 13, 2019
Originally published on: https://www.codemotion.com/magazine/iot-development-the-snap4city-way-3353
During the last decade, application development has extended its borders far and beyond the classical web application paradigm. In particular, two main tendencies arose, namely Cloud Computing and the Internet of Things.
Delivering applications on cloud frameworks is now a simple and standard task for programmers. Production environments or even retail customers or software vendors require the capability to do it easily and efficiently. The same is becoming true for IOT applications, which pose a different level of complexity and new challenges to developers.
Indeed, by its very nature, IOT has to do with different hardware devices and communication protocols and it displays a manifold of ways to collect data, connect to a device or even manage devices to prepare them for a connection. While in the Cloud Computing paradigm big vendors provide APIs and frameworks which have become de facto standards, in the IOT realm there is a more fragmented picture concerning platforms, devices and standards.
In particular, IOT development aimed at smart city applications is becoming an important issue. Providing a unified, integrated and complete framework is where Snap4City comes into play. It delivers a fully open source, data-driven, scalable platform based on cloud, which also enables its users to analyse and aggregate huge amounts of data by means of big data and machine learning techniques, and to offer services such as anomaly detection, early warning and environmental risk assessment.
Snap4City applications should be viewed as data-driven applications, which may be customised tailoring on specific needs and shared among the community. The basic tool to use and manage IOT applications on Snap4City is the dashboard, which is in a sense the governance layer of smart city application within Snap4City itself:
The dashboard provides both the front-end of the applications and the development environment in which to create them. Snap4City allows us to set up an application by combining micro-services according to a given logic flow, in a stateful manner, thanks to a GUI editor to describe graphically the logic flow and all the single services it ought to connect.
The programmer can choose from dozens of micro-services which perform a single micro-task, such as, for example:
- Device search services (geolocalisation, getting info, public transport routes search, etc.)
- Snap4City job scheduling management (check existing jobs, trigger a job, pause a job, etc.)
- Data analytics (descriptive statistics, machine learning predictions, time series predictions, etc.)
- Service search (by GPS position, by keywords and tags criteria, by bus routes, etc.)
- Application data management
- Dashboard customisation (adding widgets, buttons, contents and more on a dashboard)
- Sigfox integration (recall that Sigfox is a low cost connectivity solution for IOT https://www.sigfox.com/en).
- Device handling (registration, etc.).
Img 2: Example of a micro-service description (developer view)
To actually build the application, Snap4City provides a graphical tool resembling BPMs, to assemble the invocation of micro-services into a control flow, and to insert a code snippet to perform some simple specific tasks which do not require a service but which alter the state of the application (for example variables’ values).
Img 3: GUI wizard to create and manage micro-services control flow.
More precisely, Snap4City provides a NodeRED-like tool augmented by the large set of micro-services discussed above. In this way, IOT applications can be fully integrated behind a City Dashboard for decision makers and for city users as well. However, it is worth stressing that an IOT application may or may not have a dashboard at all, or they also have many dashboards. Indeed, a dashboard itself is represented as a block in the oriented graph representing the control flow of the application.
It is worth showing how easy to use the Snap4City wizard is to build applications, with a simple toy example. Let us suppose we have two devices, providing temperature values in Celsius and in Fahrenheit, the first one storing the value in a JSON file, the second one just emitting a single value, the first one with frequency of five seconds, the second one with frequency of seven seconds.
Thus we have two devices with different values, different formats, communication protocols and different frequencies. We want to integrate their data inside a unique application to collect them and aggregate them into a single time series.
Img 4: Two simple different flows to be integrated, as they appear in the Wizard.
Next we can introduce two blocks, for example one Orion Context Broker block and one MQTT input block and configure them, by adding a “temperature” variable in the Orion block and linking it in the MQTT block, which also displays the name of the value produced by the second device:
Img 5 and 6: Blocks configuration.
Img 7: Code snippet (into a function) to get a value from a JSON.
Also needed is a function to convert Fahrenheit to Celsius, and we put it into another function block:
Img 8: Code snippet (into a function) to convert from Fahrenheit to Celsius.
At this point, we have all the element displayed in the wizard:
Flow control before aggregation and connection.
Img 9: Flow control before aggregation and connection.
To properly connect them, one can use an aggregator node. This one has to be installed by managing the user palette, which lets the developer search all along the NodeRED repository and filter according to keywords:
Img 10: Adding NodeRED nodes to the user palette.
Deploying and testing the application is simple as well as building it, as we have done in this toy example.
A final word: each application is executed through the Computation Management Service tools that have to verify the actual possibility to deploy and to execute each application on allocating and connecting the corresponding microservices (according to the compatible hardware and possible allocations). This allows for a kind of hybrid solution exploiting Edge/Fog Computing, cloud facilities, parallel and distributed batch processing, and also taking advantage of contextual information, and reducing latency in developed services.
Snap4City platforms and solutions are available at Snap4city.org website, where you can register and start exploring its features. But if you want to really challenge your skills and propose your innovative solutions for connected cities, you can join the upcoming Snap4City Hack, the big online hackathon on the topics of Smart City and IoT.
Snap4City launched a big online Hackathon on Ecological Watch, Social and Service Evolution, Stimulating Business Growth, City Aware.
Using Snap4City tools to manage IoT, Big Data and analytics, the hackathon challenges will cover different themes – Ecological Watch, Social and Service Evolution, Stimulating Business Growth, City Aware – and real data from cities such as Helsinki or Antwerp.