In this blogpost we are going to see how to connect a “thing” to the Internet of Things, using Ultralight 2.0 over HTTP using FIWARE.
In order to do it, we are going to use a Intel Edison board. We will add a temperature sensor. So our “thing” will be a thermometer, and we will send the information using the Ultralight 2.0, developed by Telefónica. In addition we will configure everything to use FIWARE.
So we will need:
- An Intel Edison board and a temperature sensor.
- A Cloud instance, or a server with access via SSH
- Intel XDK or a similar IDE to program our “thing”
- FIWARE Generic Enablers: Orion Context Broker, IoT Agent Ultra Light 2.0
The first step will be configure an instance, which we can connect with, and configure it. Having access to a cloud, we can launch an Ubuntu 14.04 instance and access to it via ssh. Then, we will install Docker and Docker-Compose, to configure our docker-compose file, which will be as follows:
[codeblocks name= ‘Uno’]
Now, in order to have the services up and running, we will use the command
[codeblocks name= ‘Cuatro’]
And after this, using the following commandwe will check that the services are up and running.
The next step will be configuring the IoT Agent, in order to communicate with Orion Context Broker. To do it so, we will follow the next steps:
- Extract the configuration file from the IoT Agent (docker) to the home directory of our instance (local host)
- Modifying the parameters
- Insert back again the configuration inside the IoT Agent docker container.
- Restart the IotAgent
In order to copy the configuration file, we will use the command:
We are now configuring our IoT Agent in order to work over HTTP, so everything related to MQTT will be seen later.
The most important thing of this file is specifying the “service” and “subservice” headers that we are going to use, the entity type (in this case “Thing”) and a URL and port where Orion Context Broker can be reached from the IoT Agent. In this case, the private IP of the instance will be enough,but we should avoid using localhost reserved word, because if we do it , we will find communications problems, since the docker container acts as a virtual machine with its own network interface, and we will not be able to communicate if we use this reserved word or 127.0.0.1
Now we will copy back the modified file and will substitute what was inside the IoT Agent container, and finally, we will restart the service, in order to reload the configuration. To do it, we will use the following commands
We have now our Cloud architecture, so once we have done it, we can now use our Intel Edison. We will be using the Intel XDK IDE, to program in Node.js and upload it to the board. The steps to be followed are:
- Connect the board
- Configure it to work in the same network
- Connect the sensors
- Upload the code
- Leave the board sending data
The Intel Edison has two USBs, one for the data transmission and another one for the power supply. We connect both of them to our computer and, in the case of Mac or Linux, there is no need to install any additional driver. In Window’s case you will need to install some specific drivers.
Once it has been done and with the board connected to the computer, we open a Terminal and use the command:
We will be asked to introduce user and password. In the first usage it will be root user and blank password. Once we are inside the board, we will configure it, and use the command
In this way, we will assign the device a name and a password, and will connect it to the same WiFi where our computer is.
Them we are going to use an LCD screen and a temperature sensor to show the ambient temperature recollected by the sensor, and send it through the Internet to our Orion Context Broker in the cloud. To do it so, we connect the Arduino shield to our Intel and connect the temperature sensor to one of the analog input/outputs and the LCD to one of the I2C input/outputs. The board have the following appearance
Now it is the moment to upload the code in the board. We will open the Intel XDK and we will upload the code, that will be explained later.
In this code the function useLcd() is the first to be called, which will write in the upper part of the LCD a message, and will be followed by the rotateColors(display), waiting2(display) and uploadData() functions. The rotateColors function will only change the LCD screen colors, while the function waiting2 will read the sensor and will write its value in the display, to finally call the uploadData function. The uploadData function will communicate our “thing” with the cloud using the Ultralight 2.0 using HTTP
We can see in the IntelXDK console how the data is being uploaded if we execute the code
In addition, we can now check that the data are being collected correctly in Orion Context Broker if we do a REST request to its API
Finally, we can create a dashboard to visualize the data of Ultralight 2.0 in real-time in a very easy way thanks to freeboard.io
With an existing account of freeboard.io, we will add the datasource. We will have to introduce the parameters like Fiware-Service, Fiware-Subservice, Host:Port, etc.
Then we will add a pane too, later on, add a widget of the Gauge type.
Next, we link the data source that we just added to the graphic value. In this case it would result as follows:
Once saved, we will be able to visualize our graphic and see how it changes every second.
The whole process can be found on our YouTube channel. You can find the video here:
[fusion_youtube id=”https://youtu.be/Flpnk8zA2vw” width=”” height=”” autoplay=”false” api_params=”” hide_on_mobile=”small-visibility,large-visibility” class=””][/fusion_youtube]
This was the post about how to connect a “thing” to the Internet of Things using FIWARE and the Ultralight 2.0 protocol over HTTP
Don’t miss the next post, where we will discuss about how to communicate via MQTT instead of HTTP!