Read our blog which describes our IoT parking lot demo and the technology behind it. We will also tell you how to use Azure IoT Hub to send messages between Azure services and devices to achieve the same level of communication we had in our demo. You will learn about the different modules we have used in our demo and how to develop simple applications using Azure IoT Hub.
2. |www.toradex.com Toradex® is a registered trademark of Montadex GmbH June’16 2
CHAIRMAN
Introduction
In this blog post, I am going to talk about our IoT parking lot demo
and the technology behind it. I will try to explain how to use Azure IoT
Hub to send messages between Azure services and devices to achieve
the same level of communication we had in our demo. I will also quickly try to explain all
the different modules we used in our demo, but my samples will focus on Azure IoT Hub
and how to easily send and receive messages. If you are interested in knowing more
about Azure IoT Hub, you can check the details here.
3. |www.toradex.com Toradex® is a registered trademark of Montadex GmbH
In our demo, we have used multiple devices, namely:
• Parking Lot 1 (called Stretnor in our demo)
• Parking Lot 2 (called Theater Parkhouse in our demo)
• Public Display (Parking Lot independent device)
Every parking lot consists of more than one of the following devices:
• Gate Controller (Colibri T30 running Win10 IoT)
• Parking Controller (Colibri VF50 running Windows Embedded Compact 2013)
• Payment Terminal (Apalis iMX6 running Linux and Qt)
• Public Display (Colibri iMX6 running Windows Embedded Compact 2013)
6/20/2016 3
5. |www.toradex.com Toradex® is a registered trademark of Montadex GmbH June’16 5
CHAIRMAN
As you can see in the above image, all the communication messages go
through the Azure IoT Hub to the application service that processes these
messages. You can also see that we have a web page and database running in
Azure but this blog post focuses only on the part about Azure IoT Hub.
Message flow in IoT Parking demo
There are two basic events that trigger the flow of information between
devices and IoT Hub.
The first event is when a car arrives at the gate (refer the diagram below):
7. |www.toradex.com Toradex® is a registered trademark of Montadex GmbH June’16 7
CHAIRMAN
When a car arrives to the gate, the gate controller will scan the license plate and send a
message to IoT Hub (1). After the application service verifies the data, it will send the
message back to Gate Controller to open the gate (2). At the same time, a message is
sent to the Parking Controller with the number of assigned parking spaces (3). The
Parking Controller will start blinking the Red light indicating that the parking space is
going to be occupied soon. The message is sent also to the Payment Terminal. This
message includes the license plate number and time of arrival (4). At the same time,
the Public Display receives the information about all the parking spaces in the area (5).
When the car is parked at the parking space, the Parking Controller stops blinking the
Red light and sends a message to the IoT Hub indicating that car is parked (6). At the
same time, the Gate Controller is informed to close the gate (7).
9. |www.toradex.com Toradex® is a registered trademark of Montadex GmbH June’16 9
CHAIRMAN
When a car leaves the parking lot, the driver has to pay the parking charges first. On
the Payment Terminal, a person can select the appropriate license plate of their car
and select pay. A message is then sent to the IoT Hub initiating a request of payment
(1). Application service calculates the price and sends it back to the Payment
Terminal (2). When the Payment Terminal receives the payment credit, it sends the
information to the IoT Hub that the payment was successful (3). Application service
will than send a message to the Parking Controller that the car is about to be
removed from the parking lot (4). The Parking Controller starts blinking the Green
light. After the car is removed from the parking space, a message is sent to the IoT
Hub indicating the removal of car (5). The Parking Controller also opens the gate to
exit. After a timeout value, the gate is closed again and a message is sent to the IoT
Hub that the parking space is now free. After this, the Public Display again shows
the updated information on all the parking lots (6).
10. |www.toradex.com Toradex® is a registered trademark of Montadex GmbH May’16 10
CHAIRMAN
Sample application
In the following sample application, I will try and show to you how to
communicate with the Azure IoT Hub easily. To understand this sample you need
a basic understanding of C#. If you want to build the application, you will need
Visual Studio 2015.
To run the example, you will also need an Azure account. You will need to create
a free Azure IoT Hub and create a device on your Azure IoT Hub. You can use the
device explorer to do this. Device explorer documentation can be found here.
Here I am going to show you a small example of a server-side application that
takes messages from the IoT Hub and processes them. This code is really simple
and is not meant for the production environment.
11. |www.toradex.com Toradex® is a registered trademark of Montadex GmbH May’16 11
It is only to show you how easy it is to communicate with the Azure IoT Hub. In this
example, we only receive the message from the device and send new messages back
to the same device.
You will have to modify the server-side code with your connection string.
As you can see in my sample, I have only called the method connect of the class
TDXServerEmulator
12. |www.toradex.com Toradex® is a registered trademark of Montadex GmbH May’16 12
CHAIRMAN
This will take care of receiving and responding to messages.
To use the clients, you need to replace the URL to Azure IoT Hub with your URL.
Device.cs.
Inside your client you need to create a new Device object and register the
OnMessageReceived event. This will allow you to get all the messages sent from the
Azure IoT Hub to your device.
13. |www.toradex.com Toradex® is a registered trademark of Montadex GmbH May’16 13
CHAIRMAN
After this, you will be able to run the demo project. After you’ve executed the
project, two console applications will appear. You have to wait for the server
application to be ready for connection
14. |www.toradex.com Toradex® is a registered trademark of Montadex GmbH May’16 14
CHAIRMAN
After the server is ready, you can select “Send Hi” from the client application.
In the image above, you can see the client sending “Hi”. After the server received the
message from client, it responds with the following message, “Hi from IoT Hub”.
15. |www.toradex.com Toradex® is a registered trademark of Montadex GmbH May’16 15
CHAIRMAN
As you can see in my sample, it is really easy to communicate with the Azure IoT
Hub and send simple messages. For more complex applications, there are many
things that can be improved but that also makes the sample application more
complex.
With this sample and explanation, you should be able to develop simple
applications using Azure IoT Hub. Also all Toradex modules support Azure IoT
Hub. You can read more about the type of support offered by the Toradex modules
here. You can also download SDKs for WinCE and Linux.