MQTTLAB.IOTSIM.IO/azure
Portal for public SaaS MQTT labs based on MIMIC MQTT Simulator with Azure IoT Hub for Azure IoT training.
You can try for free (no registration/credit card required) the other MQTT labs , then upgrade to this paid lab if you like it.
Azure IoT Get Started Tutorial
Overview
Onboarding an external device to Azure IoT for the first time is a task that until now took hours if not days . To overcome this hurdle, we created this Azure IoT Getting Started Lab to get started in minutes.
This MIMIC MQTT lab demonstrates integration of Azure IoT Hub and MIMIC MQTT Simulator to produce an out-of-the-box lab for immediate first-time setup and use of dynamically controllable devices . By having a quick, successful example, you will short-circuit integration of your own devices into Azure IoT Hub.
Check out this 2-minute Youtube video of 100 simulated devices generating telemetry to Azure IoT in real-time, and a subscriber client displaying their payload.
This lab extends the Azure IoT Hub Getting Started page to set up within minutes any number of realistic, third-party, MQTT-based sensors publishing arbitrary JSON telemetry that fits the Azure IoT device guidelines. There is no limit to the scalability, but we'll setup 1 sensor and then you can try the same yourself on any number in the lab for your requirements (if you need more sensors, send e-mail to sales@gambitcomm.com).
Features
Features of this lab include:
- no prior requirements except for a valid Azure IoT Hub account, ie. a Azure IoT login ;
- no extra setup of NODE.JS or cloning of Github source code #nocode;
- step-by-step, clear instructions for all tasks;
- 1 realistic sensor (or more) that publishes telemetry via MQTT ;
- the sensor is authorized to access your account (and only your account) in Azure IOT Hub, just like real devices will have to be;
- dynamic telemetry published over the internet to Azure IoT Hub and reflected in the device state;
- real-time, interactive control of the telemetry to reproduce any scenario you want at any point in time;
- investigate all aspects of Azure IoT interaction with a third-party device;
- finally, verifiable cleanup of everything we setup automatically.
Tasks
These are the tutorial steps you are going to perform to get going quickly:
Do you have questions? Maybe we answered them in the FAQ below. If not, contact our support team.
The power of MIMIC is not limited to this. If you have a scenario you need simulated, send e-mail to sales@gambitcomm.com.
Step 1: Setup
Objective
Setup a temporary IoT Hub instance in Azure Cloud for this lab. This guarantees that any outside access only goes through this temporary hub. Later, when you remove the hub, all further access will be denied.
This procedure is shown in this 3-minute Youtube video . You can follow along step-by-step by just pausing the video as needed.
Procedure
To operate your lab, we recommend 2 web browser (Chrome, Firefox, Edge, ...) windows side by side. For example in the left browser window you can have your MIMIC MQTT lab for Azure, and in the right your Azure portal, logged into your Azure Cloud login , eg. as in Figure 1:
Figure 1 - 2 browser windows side-by-side
When we point to features in either of the windows, they will be highlighted with a red circle. For example, in Figure 1 above we have highlighed the main menu of MIMIC lab and that of the Azure portal. Check it out by clicking on the Figure 1 picture to open it (make it larger). Then press your browser Back button (left arrow) to get back to this page.
You can maximize either of them when working in one window for a while.
NOTE: this is the most complicated part of the tutorial, because we cannot automate it for you, and it shows you what is involved with Azure Cloud for when you have to do everything yourself.
-
We first follow the steps from the Microsoft
tutorial
page to create a subscription, enable billing and create a IoT Hub resource.
Once you do, it is deployed as shown in Figure 2:
Figure 2 - New IoT Hub
Give the IoT Hub a simple, yet memorable name, for example mimic-demo. Then press Save.
-
In the left MIMIC MQTT lab window
click on Azure Tutorial. then Step 1: Setup....
This will from now on be referred to as Azure Tutorial -> Step 1:
Setup....
The Step 1: Setup dialog appears.
Figure 3 - Step 1: Setup dialog
-
Enter the Azure IoT Hub that you want to have your IoT things to live
in, ie. replace the beginning of YOUR-IOTHUB.azure-devices.net.
- Once you click OK, a new Run Script Console tab is opened in the left lab browser window with the output of the processing. When it says Task completed, and there are no ERROR messages, your lab is configured to work with your Azure temporary project.
Results
The IoT Hub instance is setup and you are ready to use the MIMIC MQTT Lab to add a device, investigate how it connects, and play with it.
Step 2: Add Device(s)
Objective
The left MIMIC MQTT lab browser window shows red icons, one for each simulated device. This is the equivalent of your real-world devices sitting on your lab bench. They are not doing anything.
We need to configure one of the devices to publish telemetry to Azure IoT Hub. This task configures Azure to allow access by the device, and configures the devices to use the access keys provided by Azure.
Procedure
-
In the right Azure IoT Hub portal in Figure 3, if you press on the
Devices menu item on the left, you will end up in the
device list for the IoT Hub instance, which should be empty if you just
created it, as shown in Figure 4.
-
In the left MIMIC MQTT lab window
click on Azure Tutorial -> Step 2: Add Device....
The Step 2: Add Device dialog appears.
Figure 4 - Step 2: Add Device dialog
Type the Device ID of the device to be created in your Azure Cloud account. We recommend to name your MIMIC simulated devices beginning with mimic, that way you can find them easily later, so the first device should be named mimic1.
-
On the right side Azure window, click Add Device, and a new
Create a device page displays. Set the Device ID
field to same as in the MIMIC dialog, eg. mimic1, then press
the Save button at the bottom.
-
Refresh the list of devices, then click on the newly created
mimic1 device. Then copy its Primary Key from the
right Azure portal with the copy button, then past to the left MIMIC
dialog with CTL-V.
Figure 5 - Step 2: Primary Key
-
Once you click OK, a new Run Script Console tab is
opened in the browser with the output of the processing. When it says
Task completed, and there are no ERROR
messages, your new sensor device is added to your MIMIC MQTT Lab.
-
Now you can switch back to the left lab browser tab titled
MIMIC MQTT Lab: Azure. You can dismiss the Run Script Console
tab later when everything works.
- If it does not have it already, when you now reload the MIMIC MQTT Lab window, the first icon should have a name underneath its number, eg. the first device will be named mimic1. It is red because it is currently stopped. This is the equivalent of the device sitting on your lab bench in the real world with power switched off.
Results
So far we did the following in Azure IoT:
-
created a temporary hub for this lab to access Azure IoT;
-
created a device with Device ID mimic1 and unique access keys;
- integrated the device into the MIMIC MQTT lab.
You can click on the device in your Azure IoT panel and investigate its settings. You are now ready to experiment with this device in the next sections.
Using the lab
To start using the lab, first verify that at least one thing with the chosen device ID, eg. mimic1, is showing in your Azure IoT Hub as shown in Figure 5 above.
Step 3: Start Device(s)
Objective
The devices in your lab are stopped, equivalent to lab equipment sitting on your lab bench and powered off. So they are not doing anything. We need to power up the recently configured device, the one that is labelled mimic1.
Procedure
To start it, select the red icon(s) of the device(s) you want to start. Each selected device will have a blue indicator in the upper left. Then click on Azure Tutorial -> Step 3: Start Device(s) -> Go!.
The selected icon(s) will turn green, as if you had turned power on.
Just like the equipment on your lab bench, whether it delivers telemetry to Azure IoT or not depends on whether you have configured the correct parameters in the MQTT client software.
In this lab, if you added the device as in the section above and there were no errors, then it will publish telemetry once a second. You will know that it works when a orange <--> arrow appears in the icon, indicating activity.
You can immediately monitor generated messages with the az iot hub monitor-events command either from their Azure cloud shell or from your own shell by importing their Azure IoT SDK as shown in this 2-minute Youtube video .
In particular, we made it so that the light value changes frequently at random, like a flickering light. Try following the steps by watching the video.
Results
The icon of the selected device shows green to indicate that it is started, and telemetry is published to Azure IoT. Now you can investigate further how things work, and change telemetry on the fly.
Step 4: Investigate
Objective
Now that it is running, you'll want to see how the lab device and your Azure IoT device are linked. That way you can reproduce this with your real devices.
Procedure
To check the configuration of the device in your Azure IoT Console, click on the device. It shows the private keys for SSL communications, when you click on it. Those determine how your MQTT device can interact with Azure IoT Hub .
To check the configuration of the simulated device in MIMIC, select the device icon in the lab, then click on Azure Tutorial -> Step 4: Investigate -> MQTT Configuration...
Figure 7 - Step 4: MQTT Configuration
The important configuration parameters for the device are the
-
Config File - this defines the MIMIC simulation: what MQTT payload
to send where and when. Here we publish once a second to the
event topic
the telemetry with a JSON message containing default
Bosch XDK
telemetry:
{ "sn":"20:19:AB:F4:0F:E2", "data":{ "acc":{ "x":26, "y":32, "z":1012, "unit":"mG" }, "gyro":{ "x":1220, "y":-6835, "z":-2319, "unit":"mdeg/s" }, "mag":{ "x":40, "y":1, "z":-4, "unit":"uT" }, "light":{ "value":22394, "unit":"mLux" }, "temp":{ "value":50000, "unit":"mCelsius" }, "pressure":{ "value":98897, "unit":"Pascal" }, "humidity":{ "value":39, "unit":"%rh" } } }
The sn value is assigned uniquely at device start, simulating attributes that are determined at device startup.
The light value changes at random for this tutorial. This simulates a very dynamic attribute that changes at every sample.
Finally, the temp values can be dynamically controlled to achieve on-demand, consistent, real-time results, eg. in the Step 5: Change Telemetry section below.
-
Broker - your Azure IoT MQTT server
-
Port - 8883 for secure MQTT communications
-
ClientID - same as your device ID, eg. mimic1
-
Username - as detailed in the section
Using the MQTT protocol directly (as a device) in their
instructions
- Password - the password is a SAS Token generated dynamically from your configured primary keys as detailed in the previous link
- TLS Config - uses a default client certificate
These are the configurables you would have to setup in your real-world device to communicate with Azure IoT.
NOTE: The OK button is disabled in this lab. More advanced labs allow you to configure anything on the simulated devices.
You can investigate the TLS certificates with Step 4: Investigate -> TLS Configuration...
Results
We verified the necessary configuration for a device to communicate with Azure Iot Hub.
Step 5: Change Telemetry
Objective
You are seeing real-time, dynamic telemetry in your subscription on Azure IoT. The temp value is static, while the light value changes at random, like a flickering light. In this task we will interactively change the temperature to some other predictable value. This lets you change the temperature on-demand, eg. a device over-heating. Imagine the effort to do this with a real device.
Procedure
If you have not done so already above, in the MIMIC lab window select the green icon(s) of the device(s) you want to manipulate. Each selected device will have a blue indicator in the upper left. Then click on Azure Tutorial -> Step 5: Change Telemetry....
In the Step 5: Change Telemetry dialog, change the Temperature value to something else, eg. 38160. As soon as you click OK, the new temperature value is published. It might take a while to show up in the graph, depending on Azure delays.
In your Azure Console, you can create a Time Series Insight instance, and pull the telemetry values into the Time Series Insight graph. The new temp telemetry will be reflected, as shown in this 1-minute video:
This is very clumsy, since we are using the simple built-in facilities of Azure IoT. In Step 7 below we will explore advanced ways of displaying the telemetry, but it will require much more effort.
Results
We changed temperature telemetry on the fly, on-demand, predictably. You can use this technique when it comes to testing your application for certain conditions.
Step 6: Stop Device(s)
Objective
Your lab devices are continuously generating telemetry and publishing messages to Azure IoT Hub. This task stops them, the equivalent of powering down the real equipment.
Procedure
In the MIMIC lab window select the green icon(s) of the device(s) you want to stop. Each selected device will have a blue indicator in the upper left. Then click on Azure Tutorial -> Step 6: Stop Device(s).
The icon(s) will turn red, and messages cease to be published.
Results
We stopped the devices to stop publishing messages.
Step 7: Advanced Tasks
These are further optional tasks you can do in your lab:
-
you can repeatedly do
Step 2: Add Device
, and it will add more things with incrementing instance number upto
the total allowed in your lab. Once you start the lab devices,
you will see independent telemetry for each;
- you can run a better subscriber application to implement simple anomaly detection: detect values above a threshold as implemented in this open-source application in our Github repository and shown in this 2-minute Youtube video ;
Step 8: Cleanup
Objective
Once a lab is setup, you want to clean it up when you are done, to be certain no left-over devices have access to your account. This procedure makes certain there are no left-overs.
Procedure
The Azure Tutorial -> Step 8: Cleanup... lets you cleanup devices setup in the lab. Just select the device(s), then that menu item cleans up any associated resources from the MIMIC MQTT Lab. You also need to delete each device from Azure IoT Hub.
Once you have deleted a device, you can add one back in with different credentials with the Add step above.
To clear the rest, as detailed for Q: What about security / privacy? in the next section, ie.:
- remove the temporary project mimic-project that we created in Step 1 above in your Azure IoT Console under the IAM menu, Settings item. Just click SHUTDOWN and it will remove all resources associated with the project.
Frequently Asked Questions
- Q: What will this cost me?
A: Besides the fixed cost for the MIMIC MQTT lab, there will be minor Azure IoT costs in your Azure Cloud account that we cannot control, most likely less than $1. Well worth the savings in effort in seeing a third-party device publish to the Azure IoT device state in under 5 minutes.
- Q: What exactly does this do to my Azure Cloud account?
A: You setup a temporary IoT Hub mimic-demo in the above Setup.
If you run the Step 2 - Add dialog with your Azure authentication parameters it will setup exactly 1 device instance with an associated certificate that links to the mimic-project project. Any subsequent device additions create a new certificate and thing that link to that project.
- Q: What about security / privacy?
A: The lab will be able to access your account during the session because access tokens are stored in the lab configuration. You can delete the temporary project mimic-project that you created in the Setup section above. Then you can verify that the devices can no longer talk to your account. This is verifiable cleanup, ie. you have proven that the outside device cannot access any more.
- Q: What next?
A: This lab gives you a small successful step in connecting a few third-party sensors publishing real-time, dynamic, predictable, controllable telemetry to Azure IoT Hub device in a matter of minutes. The next steps are up to you:
- You can build on what you learned to connect your own devices to
Azure IoT Hub;
-
Explore our other free resources / videos to learn about solutions to
common problems you will encounter in IoT development;
-
You can rent a lab anytime you need to test different aspects of your
application, or lease a longer-term
MIMIC MQTT Simulator
with more features;
- You can scale the deployment to as many devices as you need to test, demo, train your IoT Application.
- You can build on what you learned to connect your own devices to
Azure IoT Hub;