Home
%3CLINGO-SUB%20id%3D%22lingo-sub-959354%22%20slang%3D%22en-US%22%3EUsing%20MQTT%20protocol%20to%20communicate%20with%20Azure%20IoT%20Hub%20without%20using%20any%20SDK%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-959354%22%20slang%3D%22en-US%22%3E%3CP%3EWe%20just%20published%20a%20new%20%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2FAzure-Samples%2FIoTMQTTSample%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3EGitHub%20repository%3C%2FA%3E%20with%20a%20code%20sample%20to%20access%20an%20Azure%20IoT%20Hub%20via%20the%20MQTT%20protocol%2C%20without%20using%20the%20Azure%20IoT%20SDK.%20Constrained%20devices%20sometimes%20do%20not%20have%20enough%20memory%20to%20support%20the%20full%20SDK%20making%20it%20necessary%20to%20access%20the%20IoT%20Hub%20using%20the%20MQTT%20protocol.%3C%2FP%3E%0A%3CP%3EThese%20C%20code%20samples%20show%20how%20to%20use%20%3CA%20href%3D%22https%3A%2F%2Fmosquitto.org%2F%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3EEclipse%20Mosquitto%3C%2FA%3E%20to%20send%20telemetry%20messages%20to%20Azure%20IoT%20Hub%E2%80%99s%20MQTT%20endpoint%2C%20as%20well%20as%20how%20to%20receive%20events%2C%20exchange%20device%20twin%20properties%2C%20and%20deal%20with%20Plug%20and%20Play%20device%20capabilities.%3C%2FP%3E%0A%3CP%3EWe%20also%20updated%20the%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fazure%2Fiot-hub%2Fiot-hub-mqtt-support%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3EMQTT%20article%3C%2FA%3E%2C%20referencing%20this%20new%20GitHub%20repository%2C%20as%20this%20article%20explains%20how%20to%20connect%20using%20MQTT%20protocol%20to%20an%20IoT%20hub%20(topic%2C%20username%20or%20password%20to%20be%20used).%3C%2FP%3E%0A%3CP%3EThis%20repository%20contains%20folders%20with%20the%20following%20samples%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH3%20id%3D%22toc-hId-1653363193%22%20id%3D%22toc-hId-1653363193%22%3EFor%20Windows%3A%3C%2FH3%3E%0A%3CUL%3E%0A%3CLI%3ETelemetryMQTTWin32%3A%20contains%20sample%20code%20to%20send%20a%20telemetry%20messages%20to%20an%20IoT%20hub%20to%20build%20and%20run%20on%20a%20Windows%20OS.%3C%2FLI%3E%0A%3CLI%3ESubscribeMQTTWin32%3A%20contains%20sample%20code%20which%20subscribes%20to%20events%20of%20a%20given%20IoT%20hub%20on%20a%20Windows%20OS.%3C%2FLI%3E%0A%3CLI%3EDeviceTwinMQTTWin32%3A%20contains%20sample%20code%20to%20query%20and%20subscribe%20to%20the%20device%20twin%20events%20of%20a%20device%20in%20the%20IoT%20hub%20on%20a%20Windows%20OS.%3C%2FLI%3E%0A%3CLI%3EPnPMQTTWin32%3A%20contains%20sample%20code%20to%20send%20a%20telemetry%20message%20with%20IoT%20Plug%20and%20Play%20device%20capabilities%20to%20an%20IoT%20hub%20to%20build%20and%20run%20on%20a%20Windows%20OS.%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CH3%20id%3D%22toc-hId--898793768%22%20id%3D%22toc-hId--898793768%22%3EFor%20Linux%3A%3C%2FH3%3E%0A%3CUL%3E%0A%3CLI%3EMQTTLinux%3A%20contains%20code%20and%20the%20build%20script%20to%20run%20on%20Linux%20(WSL%2C%20Ubuntu%2C%20Raspbian).%3C%2FLI%3E%0A%3CLI%3ELinuxConsoleVS2019%3A%20contains%20the%20same%20code%20but%20in%20a%20VS2019%20project%20targeting%20WSL%20(Windows%20Linux%20sub%20system).%20This%20project%20allows%20you%20to%20debug%20the%20code%20running%20on%20Linux%20step%20by%20step%20from%20Visual%20Studio.%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CH3%20id%3D%22toc-hId-844016567%22%20id%3D%22toc-hId-844016567%22%3EFor%20mosquitto_pub%3A%3C%2FH3%3E%0A%3CUL%3E%0A%3CLI%3EThis%20folder%20contains%20two%20samples%20commands%2C%20used%20with%20mosquitto_pub%20utility%20tool%2C%20provided%20by%20Mosquitto.org%3A%3CUL%3E%0A%3CLI%3EMosquitto_sendmessage%3A%20to%20send%20a%20simple%20text%20message%20to%20an%20IoT%20hub%20acting%20as%20a%20device%3C%2FLI%3E%0A%3CLI%3EMosquitto_subscribe%3A%20To%20see%20events%20occurring%20in%20an%20IoT%20hub%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3EWe%20really%20want%20this%20repository%20to%20become%20a%20reference%20for%20developers%20interested%20in%20interacting%20with%20Azure%20IoT%20Hub%20over%20MQTT.%2C%20so%20please%20send%20pull%20requests%20our%20way%20if%20you%20would%20like%20to%20add%20examples%20featuring%20your%20MQTT%20client%20of%20choice!%20We%20are%20looking%20forward%20to%20adding%20examples%20on%20how%20to%20do%20X.509%20based%20authentication%20or%20use%20other%20MQTT%20libraries%20.%20If%20you%20have%20a%20comment%20or%20a%20suggestion%2C%20please%20open%20a%20GitHub%20issue.%3C%2FP%3E%0A%3CP%3EEric%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-TEASER%20id%3D%22lingo-teaser-959354%22%20slang%3D%22en-US%22%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-center%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F151514i9361D44D4D54F4DB%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%22MQTGitHub.png%22%20title%3D%22MQTGitHub.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%3EConstrained%20devices%20sometimes%20do%20not%20have%20enough%20memory%20to%20support%20the%20full%20SDK%20making%20it%20necessary%20to%20access%20the%20IoT%20Hub%20using%20the%20MQTT%20protocol.%20%3CFONT%3EWe%20just%20published%20a%20new%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2FAzure-Samples%2FIoTMQTTSample%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3E%20GitHub%20repository%3C%2FA%3E%20with%20code%20sample%20to%20access%20an%20Azure%20IoT%20Hub%20via%20the%20MQTT%20protocol%2C%20without%20using%20the%20Azure%20IoT%20SDK.%3C%2FFONT%3E%26nbsp%3B%3C%2FFONT%3E%3C%2FP%3E%3C%2FLINGO-TEASER%3E%3CLINGO-LABS%20id%3D%22lingo-labs-959354%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EAzure%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EIoT%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
Frequent Visitor

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.org:
    • 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.

Eric