Using MQTT protocol to communicate with Azure IoT Hub without using any SDK
Published Oct 28 2019 09:06 AM 10.1K Views

We just published a new GitHub repository with a code sample to access an Azure IoT Hub via the MQTT protocol, without using the Azure IoT SDK. Constrained devices sometimes do not have enough memory to support the full SDK making it necessary to access the IoT Hub using the MQTT protocol.

These C code samples show how to use Eclipse Mosquitto to send telemetry messages to Azure IoT Hub’s MQTT endpoint, as well as how to receive events, exchange device twin properties, and deal with Plug and Play device capabilities.

We also updated the MQTT article, referencing this new GitHub repository, as this article explains how to connect using MQTT protocol to an IoT hub (topic, username or password to be used).

This repository contains folders with the following samples:


For Windows:

  • TelemetryMQTTWin32: contains sample code to send a telemetry messages to an IoT hub to build and run on a Windows OS.
  • SubscribeMQTTWin32: contains sample code which subscribes to events of a given IoT hub on a Windows OS.
  • DeviceTwinMQTTWin32: contains sample code to query and subscribe to the device twin events of a device in the IoT hub on a Windows OS.
  • PnPMQTTWin32: contains sample code to send a telemetry message with IoT Plug and Play device capabilities to an IoT hub to build and run on a Windows OS.

For Linux:

  • MQTTLinux: contains code and the build script to run on Linux (WSL, Ubuntu, Raspbian).
  • LinuxConsoleVS2019: contains the same code but in a VS2019 project targeting WSL (Windows Linux sub system). This project allows you to debug the code running on Linux step by step from Visual Studio.

For mosquitto_pub:

  • This folder contains two samples commands, used with mosquitto_pub utility tool, provided by
    • Mosquitto_sendmessage: to send a simple text message to an IoT hub acting as a device
    • Mosquitto_subscribe: To see events occurring in an IoT hub

We really want this repository to become a reference for developers interested in interacting with Azure IoT Hub over MQTT., so please send pull requests our way if you would like to add examples featuring your MQTT client of choice! We are looking forward to adding examples on how to do X.509 based authentication or use other MQTT libraries . If you have a comment or a suggestion, please open a GitHub issue.


Version history
Last update:
‎Oct 28 2019 09:26 AM
Updated by: