TC9.4 - IOT application exploiting Edge computing with Raspberry, time series, MyKPI

×

Warning message

  • You can't delete this newsletter because it has not been sent to all its subscribers.
  • You can't delete this newsletter because it has not been sent to all its subscribers.

Test Case Title

TC9.4 - IOT application exploiting Edge computing with Raspberry, time seriers, MyKPI

Goal

Showing how it is possible to create Snap4City applications also embedding them into edge computers.

Showing how IOT Edge can be created.

showing how to use Mykpi , MyData from iot Application, creation and exploitation of time series data

Prerequisites

Having a Raspberry in which you can put in execution the operating system with all in installed ready to use NodeRED and snap4city features for accessing to smart city API and IOT directory.

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

A change of the status of a set of actuators according to the conditions expressed on the values of other sensors

Steps

 

see also Mobile Phone Android as IOT Edge with IOT Applications in Node-RED

see also Registering IOT Edge: example of Raspberry Pi, total security 

see also TC 2.1b. Use snap4city nodes on your local IoT Application

1. In the “Stretch” version of “Raspbian” you can find node-red among the pre-installed programs ( in other versions following the official documentation here)

    2. Clicking on the program item starts node-RED and the following screen is displayed. In our case we want the node-RED to start at the start of RPI and we can do it by copying the penultimate script shown in the screen to a terminal and running it.

    3. Once this command has been executed, it is possible to restart the RPI and connect to the staticIPAddress:1880. Obtaining:

    4. To continue our experiment, we have connected one DHT22 humidity and temperature sensor to the GPIOs of the RPI.

    5. To install additional nodes on the node-RED you need the "npm" program which is not installed by default on "Raspbian". To do this you can open a terminal and run the following command "sudo apt-get install npm". Installed npm we can add the node that allows us to read the two sensors connected to the RPI.

    6. Click on the “Manage Palette” item of the node-RED menu:

    7. In the tab “Install”, search for “node-red-contrib-dht-sensor” and install it on node-RED (install also the nodes reported on TC 2.1b. Use snap4city nodes on your local IoT Application)

    8. After installation, the following node should appear.

    9. The sensor installed on the RPI is connected to the BCM PIN 26 (the orange wire that send the data). The letters BCM indicate the number that follows the GPIO string in the following legend. It is also connected on the Physical Pin 1 (3.3 Power - 1 on the figure, with the purple wire) for the power and on the Physical Pin 39 (Ground - 39 on the figure, with the yellow wire). The NodeRed only needs to indicate the PIN that sends the temperature and humidity data measured by the sensor. For more information on Raspberry GPIO see here.

    10. And you can configure both sensors on the respective node in this way

    11. By connecting the node of the sensor to a debug node and a node that sends a timestamp every 30 seconds

    12. We can see what is reported by the sensors (N.B. See that the humidity is in the field humidity instead that in the payload :where is reported the temperature):

    13. It is possible to integrate the sensor in the instruments developed for Snap4City. The sensor can be inserted into the IOTDirectory and this can be done simply by follow the steps on "TC2.11.    Search on IOT Directory for Devices and Sensors, IOT Device Registration"

     

    14. Once the configuration has been deployed, we can find the sensor inserted in the IOTDirectory

     

    15. Once the sensor has been created, it is possible to send the data from it to platform in various way.

    16. The flow reporting all the ways for sending the data is as follows:

     

    2.SENDING AS MY KPI VALUES

    1. For more information about How create and use My KPI see TC2.33 - How create My KPI and TC2.34 - How manage My KPI with IOT Applications

    2. To perform this Test Case two KPIs were made, one for the temperature and one for the humidity recorded by the sensor connected to the Raspberry PI

    3. The function node connected to the RPI-DHT22 output is used to map the temperature at the first output and the humidity at the second. This is possible with the following function:

     

    4. The first output, the temperature output, is connected directly to the save-my-kpidata-values node on which the temperature KPI has been configured (see TC 2.1b - Use snap4city nodes on your local IoT Application to know how use Authentication).

    5. The second output, the humidity output, is connected directly to the save-my-kpidata-values node on which the humidity KPI has been configured:

    6. Data is sent every minute and can be viewed within the KPI Editor:

    7. In addition, TC2.35 - How manage My KPI with Dashboard explains how to retrieve data from the KPI Editor and display it in a dashboard.

     

    3.SENDING DIRECTLY TO A DASHBOARD

    1. In this case the value is displayed directly in the dashboard and could be the easiest way, but you must remember that with the previous case of KPIs is saved a history of the data, while in this case the value is always displayed and is not stored anywhere.

    2. The values can be displayed in 4 different ways through these nodes present in those provided with the package node-red-contrib-snap4city-user:

    3. In our RaspberryPi flow we used Gauge Charts and Trend Charts:

    4. Once the nodes are inserted into the flow, you must authenticate and deploy them (see TC 2.1b - Use snap4city nodes on your local IoT Application). Once the node is reopened you can create a new dashboard or add the widget to an existing one by selecting it from the drop-down menu:

    5. Once you have created all 4 in nodes, named the widgets and selected the dashboard on which they should be displayed, you can deploy them and we'll get

    4.SENDING TO ORION BROKER AND GET VALUES ON CLOUD

    1. First of all, if it has not already been done in depth, your knowledge about what an Orion Broker is, what is the syntax to use to send messages (V1V2) and how to register a device on the platform (TC2.11.    Search on IOT Directory for Devices and Sensors, IOT Device Registration).

    2. For our example we registered a Raspberry Pi as a "RaspberryCertificates" device with two sensors: one that measures temperature and one that measures humidity:

    3. The measurements of the two sensors contained in DHT22 can be sent together in the same JSON, which must be properly formatted with the two function nodes:

    4. Where each measurement is treated separately:

     

    5. And then reunited through the JSON node before being sent to the Orion Broker:

    6. The Fiware-Orion-Out node must be configured as follows:

     

    7. The first field is used to indicate which is the address of the Orion Broker to which send the data collected by the sensors. Pressing the first time on the pencil to modify the service shows the default data that should be left unchanged:

    8. The second field can be used for authentication through certificates, by entering the certificate, key and certificate of the platform (downloadable here):

    9. As an alternative to the certificate two keys k1 and k2 can be used:

     

    10. Both certificates and keys can be found in the information of the device registered on the platform under the menu item MyDevices.

    11. Once you have entered the certificates or keys you can deploy the flow and you can see if the data is entered correctly in the Orion Broker.

    12. If all the data has been correctly inserted in the node configuration, every time the data is sent to the Orion Broker a successful message appears under the node related to the Fiware Orion Broker.

    N.B. You have the same indication of success even if the message sent with the JSON has the wrong syntax: the success only indicates that the message was sent correctly to the Orion Broker and if you do not see data arrive when you go to read could be that the JSON sent has not the correct syntax.

    13.While the write flow to Orion Broker can be performed on a machine that has a local IP address, the read flow must be entered on a machine that has a public IP address or that it is possible to reach it by calling REST. In this example we will use an IOT Application created in the cloud user profile.
    If the flow does not have a reachable address, the ORION BROKER will not be able to notify the change of a value in the sensors of the device recorded on the platform and no message will arrive.

    14.First you need to create an IOT Application (if you don't already have one) by following these steps TC 2.1a. Create your own IoTApplication.

    15. Then you have to use a fiware-orion-in node configured as the one inserted in the Raspberry to send the data:

    16. In the attributes field you can choose one of the possible data of the registered device to have only that data output and not the list of all attributes. In fact, in this flow we have inserted two fiware-orion-in nodes, one to retrieve the temperature data and one to retrieve the humidity data.

    17. As you can see below the Orion nodes, these nodes will listen to the address indicated respectively under each node and if that address is a local address it is not possible for the Orion Broker to contact the node.

    18. The function nodes are used to recover correctly the value sent inside the JSON that is returned from the Orion Broker

    19. In the function node we have to insert

    20. Once retrieved the data we can send it on the dashboards as we did previously in point 2.SENDING DIRECTLY TO A DASHBOARD