element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Azure Sphere Starter Kit
  • Products
  • Dev Tools
  • Avnet Boards Community
  • Azure Sphere Starter Kit
  • More
  • Cancel
Azure Sphere Starter Kit
Blog Troubleshooting Azure IoT Hub Connection Issues
  • Blog
  • Forum
  • Documents
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Azure Sphere Starter Kit to participate - click to join for free!
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: bwilless
  • Date Created: 7 Aug 2019 3:57 PM Date Created
  • Views 1807 views
  • Likes 7 likes
  • Comments 3 comments
  • azure sphere kit
  • azurespherech
  • azure sphere
  • azure sphere mt3620 starter kit
  • avnet
  • iot hub
  • azuresphkt
  • mt3620
Related
Recommended

Troubleshooting Azure IoT Hub Connection Issues

bwilless
bwilless
7 Aug 2019

This blog is intended to help developers who are having issues connecting to an IoT Hub, or an IoT Central application using one of the Avnet OOB example projects.  My personal experience is that I've always been able to connect to my IoT Hub.  I've done my best to identify and capture  things that I think can go wrong.  My list is not comprehensive at all, if you find another debugging tip, please post it in the comments for others to use!

 

There are three failure points when connecting to an IoT Hub from the Avnet Azure Sphere OOB example application.

  1. Is the Azure Sphere application properly configured?
  2. Is the network passing data from the Azure Sphere Device to the IoT Hub and other Azure services?
  3. Are the Azure resources correctly configured?
  4. Is the device actually connected to the internet and working properly?

 

Let’s look at each of these categories and determine how to prove to ourselves that each one is working correctly.

 

Is the application properly configured?

 

There are three code changes required for the Avnet Azure Sphere OOB application to connect to an IoT Hub, or an IoT Central application (which is using an IoT Hub under the covers)

  1. connection_strings.h
    1. Verify that you added a connection string to the header file
    2. Verify that you’re using the correct connection string
      1. IoT Hub:  Copy the "primary connection string" from the IoT Hub --> <your device> --> primary connection string
      2. IoT Central:  Generate a connection string using the method documented here:  https://docs.microsoft.com/en-us/azure/iot-central/howto-generate-connection-string
  2. build_options.h
    1. Modify the header file to include only code required for either IOT_CENTRAL_APPLICATION or IOT_HUB_APPLICATION
  3. app_manifest.json
    1. Verify that the hostname for the IoT Hub has been added to the “AllowedConnections” entry. This entry tells the OS to allow the application to send traffic to all FQDNs/IP Address' in the list.
    1. Verify that the hostname is correct!

 

Is the network passing data from the Azure Sphere Device to the IoT Hub and other Azure services?

 

This is the tricky part to validate.  If we could send a ping from the Azure Sphere device to the IoT Hub that would be great. But, we don’t have a shell on the Azure Sphere device to send a ping, and even if we could, the IoT Hub does not respond to pings.  So what can we do to validate that we have a clear network path from the Azure Sphere device to the IoT Hub?

 

The first thing we need to do is verify that our Azure Sphere device is connected to a Wi-Fi network. From the Azure Sphere command line tool execute the following command.

  • azsphere device wifi show-status

If the device is connected then you’ll see a status printed out similar to the graphic below

image

The network requirements for Azure Sphere are documented here:  https://docs.microsoft.com/en-us/azure-sphere/network/ports-protocols-domains.  If your ISP or internet connection blocks any of these ports you’re connection likely won’t work.  We can use Windows Powershell and the tnc (Test NetConnection) utility to probe ports on our IoT Hub and other azure resources to verify if they are reachable.  If your network blocks any of these ports, try using a different network, for example the network on your mobile phone’s wifi hotspot.  For the test below your PC should be connected to the same wifi network as your Azure Sphere device.

 

A successful tnc execution will look like the graphic below:

image

 

  1. Launch windows power shell
  2. Copy paste in each tnc * line below to check network connectivity.  Note that if the command shows <Your IoT Hub Hostname> you need to replace that text with your IoT Hub hostname
    • Device provisioning and communication with IoT Hub
      • tnc <Your IoT Hub Hostname> -port 8883
    • Device provisioning and communication with IoT Hub
      • tnc <Your IoT Hub Hostname> -port 443
    • Communication with web services, network time (NTP) server, and Azure Sphere Security service
      • tnc prod.device.core.sphere.azure.net -port 443
    • Internet connection checks, certificate file downloads, and similar tasks
      • tnc www.msftconnecttest.com -port 80

 

Are the Azure resources correctly configured?

 

We can use a simulated device running in a web browser to connect to the device we provisioned on the IoT Hub (or IoT Central).  While this does not validate that we can send data from the actual Azure Sphere device, it will confirm if we can connect to our IoT Hub and that the IoT Hub is correctly configured.  If the web browser and the Azure Sphere device are on the same network, then we can assume that the data path from our local network to the IoT Hub is good.

 

There is a Raspberry Pi simulator that will connect to the IoT device on your IoT Hub.

  1. Open the simulator: online Raspberry Pi simulator
  2. Using your IoT device connection string modify the source code at line #15
    1. Note this connection string can be from your IoT Hub --> IoT device, or the connection string you generated for your IoT Central application
  3. Click on the run link under the source code
  4. You should see the device send data to the IoT Hub

 

image

 

Is the device actually connected to the internet and working properly?

 

One way to determine if your device is working properly is to run one of the Microsoft Azure Sphere examples called "HTTPS_Curl_Easy.sln" that can be found here: https://github.com/Azure/azure-sphere-samples/tree/master/Samples/HTTPS/HTTPS_Curl_Easy .  This application demonstrates how to use the cURL "easy" API with Azure Sphere over a secure HTTPS connection.  The application periodically downloads the index web page at example.com.

 

A working system will display output similar to the graphic below . . .

image

A non-working system will display output similar to the graphic below.  Note, I turned off my cable modem and left my wifi router on-line to capture this state.  The application just hung waiting for a connection.

image

 

I hope this you blog helps you find issues with the OOB application connecting to your IoT Hub.  Please share things that you find by commenting on this blog. Hopefully we can help others get past similar roadblocks!

  • Sign in to reply

Top Comments

  • bwilless
    bwilless over 5 years ago in reply to tekmeister +1
    Sorry for the confusion. The Blog and the Hackster Technical Training course use DIFFERENT gitHub repositories. The codebase for this blog uses the connection string method for connecting the device to…
  • tekmeister
    tekmeister over 5 years ago in reply to bwilless +1
    Thanks Brian, I thought I had missed something fundamental, but couldn't see where..
  • tekmeister
    tekmeister over 5 years ago in reply to bwilless

    Thanks Brian,

     

    I thought I had missed something fundamental, but couldn't see where..

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • bwilless
    bwilless over 5 years ago in reply to tekmeister

    Sorry for the confusion.  The Blog and the Hackster Technical Training course use DIFFERENT gitHub repositories.  The codebase for this blog uses the connection string method for connecting the device to your IoT Hub, and the Hackster Technical Training course codebase uses the Device Provisioning Service to connect to your IoT Hub. 

     

    Make sure and save a copy of the app_manifest.json file you updated for DPS and use it in the new repo.

     

    For the Hackster Technical Training course please clone the GitHub project here:  https://github.com/bawilless/AzureSphereHacksterTTC.git

     

    Brian

     

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • tekmeister
    tekmeister over 5 years ago

    Hi Brian,

     

    I've been trying to complete Lab 4 of the Hackster training course and there's seems to be a step missing when configuring the application for IoT Hub. MY_CONNECTION_STRING needs to be updated, but neither the lab PDF or the accompanying video reference this, unless I missed it?

     

    On this page you suggest the connection string should be copied from the primary connection string of the IoT Hub. This confuses me somewhat as the steps preceding these in the lab are about configuring a Device Provisioning Service. I thought one of the goals of the DPS was to assign the hub to the device? Doesn't putting the IoT Hub connection string directly in the app bypass the DPS in this instance?

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube