Back to Home

Cross-platform IoT: Troubleshooting / Microsoft Blog

Microsoft · iot · azure

Cross-platform IoT: Troubleshooting

Original author: Nik Sachdeva
  • Transfer
  • Tutorial
Hello, Habr! Earlier, we looked at the Azure IoT CLI and the IoT Center Browser, which are designed to manage the center, devices, as well as to send and receive messages. In this post, we will discuss a troubleshooting program that provides additional support and capabilities for the IoT Center. Look under the cat!



Series of articles “Cross-platform IoT”


1. Cross-platform IoT: Using the Azure CLI and Azure IoT Hub
2. Cross-platform IoT: Operations with devices
3. Cross-platform IoT: Troubleshooting

What is a diagnostic program for?


There are situations when something goes wrong and you are trying to determine the cause. The most difficult thing is usually with a network connection, whether it is blocking a port with a firewall or a bandwidth that is not wide enough. And the result is one - an unstable connection. Since IoT’s operations are monitored through the Azure Management Portal, as well as the IoT’s endpoint, a thorough study of logs and crash dumps can be time-consuming and require more than one support application to open. The IoT Center Diagnostic Tool is a recent addition to the IoT Center Toolkit. This is an effective communication verification utility that provides initial data on possible malfunctions in case the IoT center does not function correctly.

The tool is also written in node.js and is an open source software solution (MIT). To install the tool on your equipment, run the following command in the terminal:

npm install -g iothub-diagnostics

Running the diagnostic tool is quite simple, all you need is a connection string from your IoT center. No other options or commands are provided.

Judging by the results of my tests, the tool needs permission iothubowner. I have not tried to apply it with all policies, probably you can restrict access or use policies with a lower level of rights.

iothub-diagnostics "HostName=youriothub.azure-devices.net;SharedAccessKeyName=iothubowner;SharedAccessKey=="

Once the connection is established, the tool is launched to perform a series of tests:

  1. First, network tests are performed to check DNS resolution, the program checks the connection with the URL to make sure that Internet connection is possible. PingURL is currently tied to http://www.microsoft.com. The code provides an indication of your DNS or address, so that you can configure it at your discretion.
  2. Next, port availability and TLS encryption requirements are checked. In this case, the tests also include HTTPS connection checking (443), by default httpsRequestUrl is bound to https://www.microsoft.com.
  3. The last stage of verification is carried out in the center: first, a temporary device is registered, and then connections D2C (devices to the cloud) and C2D (clouds to the device) are tested using all supported protocols: (HTTPS (443), AMQP (5672 and 5671) and MQTT (1833 and 8883)).

The result obtained at the end of the tests should look something like this:

2017-03-16T07:38:51.193Z - info: *******************************************
2017-03-16T07:38:51.196Z - info: * Executing the Microsoft IOT Trace tool. *
2017-03-16T07:38:51.196Z - info: *******************************************
2017-03-16T07:38:51.197Z - info:  
2017-03-16T07:38:51.198Z - info: --- Executing network tests ---
2017-03-16T07:38:51.222Z - info:  
2017-03-16T07:38:51.223Z - info: Starting DNS resolution for host 'www.microsoft.com'...
2017-03-16T07:38:51.254Z - info: --> Successfully resolved DNS to 23.204.149.152.
2017-03-16T07:38:51.255Z - info:  
2017-03-16T07:38:51.255Z - info: Pinging IPV4 address '23.204.149.152'...
2017-03-16T07:38:51.291Z - info: --> Successfully pinged 23.204.149.152
2017-03-16T07:38:51.291Z - info:  
2017-03-16T07:38:51.291Z - info: Sending https request to 'https://www.microsoft.com/'
2017-03-16T07:38:51.444Z - info: --> Completed https request
2017-03-16T07:38:51.445Z - info:  
2017-03-16T07:38:51.445Z - info: --- Executing IOT Hub tests ---
2017-03-16T07:38:54.731Z - info:  
2017-03-16T07:38:54.732Z - info: Starting AMQP Test...
2017-03-16T07:38:59.141Z - info: --> Successfully ran AMQP test.
2017-03-16T07:38:59.142Z - info:  
2017-03-16T07:38:59.142Z - info: Starting AMQP-WS Test...
2017-03-16T07:39:03.460Z - info: --> Successfully ran AMQP-WS test.
2017-03-16T07:39:03.466Z - info:  
2017-03-16T07:39:03.466Z - info: Starting HTTPS Test...
2017-03-16T07:39:08.036Z - info: --> Successfully ran HTTPS test.
2017-03-16T07:39:08.059Z - info:  
2017-03-16T07:39:08.060Z - info: Starting Mqtt Test...
2017-03-16T07:39:11.828Z - info: --> Successfully ran Mqtt test.

In case of error during testing, the corresponding exception will be recorded in the log and displayed.

In general, the diagnostic tool is a great small-sized program to quickly scan your environment for common problems with device connections and operations. Please note that this tool does not support monitoring or network tracing for IoT center servers. It is designed to connect clients and test the core operations of the IoT center.

Of course, additional functions and reporting tools can be added to it, allowing you to get more information about the types of tests performed. I would like the tool to be integrated into the CI / CD channel, and the tests of basic operations were expanded due to tests of my own design.

Read Next