Escolar Documentos
Profissional Documentos
Cultura Documentos
Introduction
CHAIRMAN
unanswered question for many of these electronics developers: how to make all of the
gathered data useful? Because that is what the Internet of Things is about.
www.toradex.com
June16 |
There are some examples of real applications taken from the Microsoft website in
CHAIRMAN
order to share a preview of what the IoT can represent: there is an elevator
company
June16 |
By itself, the vastness of services offered is already a good reason to use the Azure
CHAIRMAN
services, but Microsoft goes one step ahead and compare its services with the
Amazon Web Services to reinforce that their solution is the better a strong
statement that only users and time will confirm, or the other way around. Among the
reasons to use their services is the security offered, the easiness of integration and
the gentle learning curve.
The main goal of this article is to develop an IoT application, from the reading of field
sensors to the presentation of results and the retrieving of business intelligence. The
hardware used to collect the sensors data and send it to the cloud is: a Toradex Colibri
VF61 SoM + the Iris Carrier Board, since Toradex is an Azure IoT certified partner. .
This is, therefore, an advantage, once Toradex is an Azure IoT Certified Partner.
www.toradex.com
June16 |
The application should get some sensors data and send it to an IoT service from the
Microsoft Azure cloud solution, called Azure IoT Hub. Once the data is being
received on
CHAIRMAN
the cloud, it can be processed in many ways by other Microsoft Azure services. That is
what will be done in the second part of this article series, but for now the focus will be
on how to configure the Azure IoT Hub and send messages to it.
The chosen IoT environment was the monitoring of a car. For demonstration purposes,
sensors were attached to a remote controlled car, to which a Toradex customized SBC
was also embedded. In the image 1 it is possible to see the picture of the demo and the
image 2 holds a block representation of the aimed application.
www.toradex.com
June16 |
CHAIRMAN
June16 |
CHAIRMAN
June16 |
CHAIRMAN
Javascript along with Node.js: a server-side (which in this case is the Toradex
with changes being made every new release (at least for Node), and it should be
taken under consideration. The release version of the Azure IoT Node packages
being used in this article is the version 1.0.1.
The setup of the whole environment, from the programming of the embedded
system to the configuration of Azure in order to receive data was divided in three
June16 |
CHAIRMAN
a fixed amount of azure credits can be used to deploy applications that use the Azure
services without charge; also, the IoT Hub has a free version dedicated to
development, with limited resources, also free of charge, even beyond the trial
period. For more details about the pricing and the IoT Hub per se, the IoT Hub page
can be visited.
www.toradex.com
June16 |
After setting an Azure account, it is first needed to create an IoT Hub. For that,
CHAIRMAN
the Azure portal should be accessed using the newly created account and
the
options +New > Internet of Things > Azure IoT Hub selected. The configuration
screen for the new IoT Hub is shown in image 3. The option "Free" should be
selected in the Pricing and scale tier; a new resource group should be created in
the Resource Group field and the Location selected must match the location of the
other services to be deployed later. Any Name can be chosen and the IoT Hub
Units and Device-to-cloud partitions fields cannot be edited in the free version.
After clicking create, the service will be deployed and it might take a few
seconds.
www.toradex.com
May16 | 10
www.toradex.com
May16 | 11
That being done, the IoT Hub should appear in the Dashboard, that is, the main
Azure Portal page. After clicking it, a page like in the image 4 should open: there
will be some Essentials information such as the region of the IoT Hub; an Usage
section that gives a feedback to the system administrator regarding how many
messages were sent from devices to this service and the number of registered
devices; and a Monitoring section where the number of messages received over
time are displayed.
www.toradex.com
May16 | 12
CHAIRMAN
www.toradex.com
May16 | 13
applications, the Shared access policies option over the Settings tab should be selected.
In the new tab Shared access policies that will open, there will be a policy called
"iothubowner", which has all possible permissions to this IoT Hub and it should be
clicked. The iothubowner tab will open and its Connection string primary key should
be copied for later usage: it is the key that will allow management and monitoring of
this IoT Hub devices in the next steps. The tabs described in this paragraph to get the
connection string are illustrated in the image 5.
www.toradex.com
May16 | 14
CHAIRMAN
www.toradex.com
May16 | 15
CHAIRMAN
Now that everything is configured in the cloud, the iothub-exporer tool needs to be
installed on the development machine so that devices can be added to the IoT Hub.
There is another tool named Device Explorer, only available for Windows systems,
so if Windows is being used in the development machine, this option might be
checked out. Since in this article the Ubuntu 14.04 is being used, I will stick to the
iothub-explorer. It should be noted that the Node version running needs to be at
least 0.12.x (it says a version 4.x or higher is needed for all the features to work),
but at the time this article was written, the apt-get tool was currently installing
some 0.10.x version. To solve this issue, the Node Version Manager (NVM) and,
subsequently, the Node version 0.12.9 were installed. From the terminal, the
iothub-explorer can be installed using the NPM (Node Package Manager):
www.toradex.com
May16 | 16
Then the iothub-explorer can be run with the help option to see its usage possibilities:
leonardo@leonardo:~$ iothub-explorer help
As it can be seen in the terminal from the previous command, among the iothubexplorer options there are create and monitor-events. In order to use this tool, the
connection string acquired in the image 5 must be used. First of all, a device named
"tdx_iot_car" will be created, as in the command below. Note the option connectionstring that displays the device connection string (not to be confused with the IoT Hub
connection string). It should be copied since it is the key used to connect this newly
created device to the IoT Hub, by enabling the Colibri VF61 application to send
messages to the Hub.
www.toradex.com
May16 | 17
May16 | 18
authentication:
SymmetricKey:
CHAIRMAN
primaryKey: somesharedaccesskeyreturned
secondaryKey: somesecondaryaccesskeyreturned
connectionString: HostName=toradex.azuredevices.net;DeviceId=tdx_iot_car;SharedAccessKey=somesharedaccesskeyreturned
May16 | 19
CHAIRMAN
The repository where are the packages installer and the node file regarding this
article example send_data.js can be cloned into the the board. To clone and install
the node packages, the following commands must be run:
www.toradex.com
May16 | 20
Now the code that sends data to the IoT Hub can be run, but first let's explain some
CHAIRMAN
points about it: it is used the HTTP protocol to provide communication, but the AMQP
and MQTT protocols are also supported; The variable named connectionString value
must be the same string got from a few steps above, while creating the device with the
iothub-explorer:
var connectionString = "HostName=toradex.azuredevices.net;DeviceId=tdx_iot_car;SharedAccessKey=somesharedaccesske
yreturned"
Inside the setInterval() loop many values are randomly created to be sent to the IoT
Hub as if it were data from some sensors, such as temperature, distance from an
ultrasonic sensor, acceleration and gyro, some gps coordinates and the date/time
from the board.
www.toradex.com
May16 | 21
How to get this data from real sensors will be addressed in the next article from this
CHAIRMAN
series. The JSON.Stringify() function generates a JSON encoded string from
the data
www.toradex.com
May16 | 22
In case everything goes well, the callback function from the sendEvent() method
CHAIRMAN
should not print anything to the console while the code is running. The following
command runs the Colibri VF61 code and displays the feedback message
continuously printed to the console when all goes right:
www.toradex.com
May16 | 23
As a feedback to guarantee that the data is being received, the IoT Hub section of the
CHAIRMAN
Azure Portal should update the daily message count and the monitoring graph
should
present with a spike, as shown in image 6. Note that it might take from a few seconds to
more than a minute until this information gets updated in the portal.
www.toradex.com
May16 | 24
CHAIRMAN
www.toradex.com
May16 | 25
CHAIRMAN
May16 | 26
To see the data stream that is coming into the IoT Hub, the iothub-explorer tool
CHAIRMAN
may be used. To achieve this, the monitor-events option must be used with the
device id. Note that, for this to work, the Colibri VF61 application must be running
at the same time that the iothub-explorer, whereas to see the statistics from the
Azure Portal there is no need for it. The image 7 displays the iothub-explorer
receiving the data while the board was sending it simultaneously. The command to
monitor the events is displayed above, before the image:
leonardo@leonardo:~$ iothub-explorer
"your_iothub_connection_string" monitor-events yourdevice
www.toradex.com
May16 | 27
CHAIRMAN
May16 | 28
The Microsoft Azure website has plenty of documentation about the Iot Hub as more
CHAIRMAN
information is needed to develop more complex and/or robust applications. There are
things such as creating a device, or getting messages sent from devices to the Hub, that
can be accomplished programatically refering to the documentation is a good way to
obtain more information on the matter. Also, in the next article the focus will be in
interfacing some sensors to the Colibri VF61 + Iris Carrier Board and than, as real data
is sent to the IoT Hub, it can be used as an input to other Azure services that can
generate insights and/or add some control variables to the deployed application.
www.toradex.com
May16 | 29
I hope it was a helpful introductory article on how to join a Toradex SBC solution with
CHAIRMAN
the Azure IoT Hub service and that you may find it useful! Also, I would like to thank the
Grupo Viceri team from Brazil for their expertise regarding Azure and Business
Intelligence, that led to the partnership that which resulted in the IoT Car project. See
you soon in the next article.
This blog post was originally featured on Embarcados.com in Portuguese. See here.
www.toradex.com
May16 | 30
Thank
you!
www.toradex.com
May16 | 31