Test Case Title |
TC2.12 - Creating IOT Applications |
Goal |
Create an IOT application by using/exploiting heterogeneous data and communication protocols, exploiting a large number of nodes/blocks implementing microservices. Each IOT Application may include several flows for data transformation, each flow can be saved and loaded. Create IOT applications discovery IOT devices relying on their properties Extract sensor observations from heterogeneous sensors (belonging to different context brokers and using different formats and units of measure) and conduct an analysis Show the obtained results in the debug section |
Prerequisites |
Using a PC with a web browser. You need credentials to access to the Node-Red application. The following functionalities are available only for specific Snap4city users with specific privileges. |
Expected successful result |
Generation of a flow that gather temperature observations from two thermometers that collect values in Celsius and Fahrenheit compute the average temperature each 20 seconds and show the result in the debug section. |
Steps |
|
According to Snap4City, an IOT applications may have connected multiple Dashboards, as well as a single Dashboard can be connected to multiple IOT Applications. The IOT Applications are created by compositing Blocks/nodes and connecting them. Each block/node has input on left and output on right. The Output of a block/node can be monitored by using a DEBUG Block, and the IOT Application editor has a view of the DEBUG data on the right panel. Snap4City has created a large set of MicroServices / Blocks / nodes allowing from IOT Applications to access at all the Smart City data and services. They can be donwloaded frome the Node-RED kibrary, in two formats, basic and advnaced. If one would like to have the advanced suite, both library of Snap4City nodes/microservices have to be installed. The IOT Applications, which can be requested into the Snap4City environment already have them installed.
The lists Snap4City nodes/microservices are
- IOTMicroServicesforFinalUsers https://www.km4city.org/iot-micro-doc/user.html
- IOTMicroServicesforDevelopers https://www.km4city.org/iot-micro-doc/index.html
- In this test case we start with a node-RED flow that is partially instantiated and you have to complete it.
- Open a Flow in your cloud (TC2.1a) or local (TC2.1b) IotApplication
- Import for testing the flow "TC9.5 - Creating IOT App coping with hetero.json" with the steps described in TC2.13 (on cloud) or import it from the file (if you have not an IOT Application on cloud)
- Once imported the flow, you can find the following two flows that simulate the generation of temperature values from two distinct sensors that adopt two different units of measure (Celsius the first one, Fahrenheit the second one). Also, the formats of the generated values are different (JSON the first one, single value the second one). The first flow produces observations every 5 seconds that are sent to the Orion Context Broker. The second one produces observations every 7 seconds and they are sent to a MQTT Context Broker. This is thus an example in which data produced in different formats, unit of measures, frequencies and transmitted according to different protocols need to be integrated.
- You can select from the list of blocks in the left panel, the Orion block and the MQTT input and configure them as specified in the following figure (the red rectangles contain the information that you need to digit). We remark that the other parameters are already set because of the presence of the two flows described above.
- Now you have to introduce a function for reading the JSON value from the Orion Context Broker and extract the temperature value. The following code should be written in the form of the function node
var temp= Number(msg.payload.temperature.value); msg.payload= temp; return msg; |
The code extracts the temperature value from the JSON and returns it in the payload of the message. Moreover, you need to create another function for the transformation of the Fahrenheit values in Celsius.
var temp = msg.payload; var val_conv=(temp-32)/(1.8); msg.payload=val_conv; return msg; |
At this point you need to insert in the canvas an aggregator node that is able to collect values arriving in input for a given interval of time and calculate the average value every 20 seconds (this is just for demo purpose). This component can be downloaded from the community of node-red developers.
- We have completed the creation of the nodes and we can wire them as reported in the following figure:
- Now you can deploy it and see the average temperature in the debug section. You can check your flow with the one that we have developed and made available (TC2.13 on cloud) in the resource manager "TC9.5 (Completed) - Creating IOT App coping with hetero.json" or import it from the file (if you have not an IOT Application on cloud).
WHAT IS NEXT:
- TC2.14. IOT Applications using multiple protocols, and formats for files Creating IOT Applications coping with heterogeneous data
- TC2.4. The daisy of MicroServices for Snap4City Dashboard and IOT App
- TC2.3. List of MicroServices and the Help, for Final Users and Developers
- Saving an IOT application into the Resource Manager and reusing it from another IOT applications, (eventually make it public for everybody)
- TC2.15. IOT application IOT device registration- Final user & Admin
- TC2.16. IOT Application Creation, using personal devices and exploiting city devices
- TC2.17. Event Driven IOT Applications, from brokers: Orion, SigFox, etc.
- TC2.18. Event Driven Data Management in Dashboards from: IOT Brokers and IOT Applications
- TC2.19. Creating Dashboards with IOT broker connection back and forward
- Creating IOT Application and Dashboard sharing the same IOT Devices (Controlling red light and speed limit)
- TC2.20. Creating Dashboards with IOT Application logic. Starting from new and old IOT application and get/connect a Dash, or from Dash connect and IOT app
- On road operator, sending color coding to the operator
- TC2.21. IOT Applications with Social Media Actions, and cultural scenarious