Azure IoT Hub (TsgcIoTAzure_MQTT_Client) — sgcWebSockets | eSeGeCe

Azure IoT Hub

Connect Delphi/C++Builder applications to Azure IoT Hub over MQTT. SAS-token or X.509 device authentication, device twin, direct method invocation and cloud-to-device messaging.

TsgcIoTAzure_MQTT_Client

Azure IoT Hub MQTT 3.1.1 client — SAS-token or X.509 authentication, device twin (desired/reported), direct methods, cloud-to-device messages and Azure-specific topic conventions.

Component class

TsgcIoTAzure_MQTT_Client

Platforms

Windows, macOS, Linux, iOS, Android

Edition

Standard / Professional / Enterprise

Set hub, set credentials, connect

Set the IoT Hub host, deviceId and SAS key (or X.509 certificate), then connect to subscribe to $iothub/twin/... and publish to devices/<id>/messages/events/.

uses
  sgcIoT;

var
  Azure: TsgcIoTAzure_MQTT_Client;
begin
  Azure := TsgcIoTAzure_MQTT_Client.Create(nil);
  Azure.IoT.Host     := '.azure-devices.net';
  Azure.IoT.DeviceId := 'sensor-001';

  // SAS token authentication
  Azure.IoT.Authentication := iotAuth_SAS;
  Azure.IoT.SAS.Key := 'base64-shared-access-key';

  Azure.OnMQTTConnect := procedure(Connection: TsgcWSConnection;
    const Session: Boolean; const ReasonCode: Integer;
    const ReasonName: string;
    const ConnectProperties: TsgcWSMQTTCONNACKProperties)
  begin
    // subscribe to cloud-to-device messages
    Azure.Subscribe('devices/sensor-001/messages/devicebound/#');

    // subscribe to twin desired-property updates
    Azure.Subscribe('$iothub/twin/PATCH/properties/desired/#');
  end;

  Azure.Active := True;

  // publish telemetry
  Azure.Publish('devices/sensor-001/messages/events/',
    '{"temp":22.5}');
end;
// uses: sgcIoT
TsgcIoTAzure_MQTT_Client *Azure = new TsgcIoTAzure_MQTT_Client(this);
Azure->IoT->Host     = ".azure-devices.net";
Azure->IoT->DeviceId = "sensor-001";
Azure->IoT->Authentication = iotAuth_SAS;
Azure->IoT->SAS->Key = "base64-shared-access-key";

Azure->Active = true;

What's inside

A pre-configured MQTT client for Azure IoT Hub that builds the username/password/topic strings Microsoft expects.

SAS-token auth

Set IoT.Authentication := iotAuth_SAS and supply the device key — the component generates short-lived SAS tokens with the right resource URI and signs them with HMAC-SHA256.

X.509 auth

Set IoT.Authentication := iotAuth_Certificate and load the leaf certificate / private key — supports the IoT Hub thumbprint and CA-signed flows.

Device twin

Subscribe to $iothub/twin/PATCH/properties/desired/# for desired-property pushes; publish to $iothub/twin/PATCH/properties/reported/?$rid= to update the reported state.

Direct methods

Subscribe to $iothub/methods/POST/# for inbound direct-method invocations; reply on $iothub/methods/res/<status>/?$rid=<id> with the response payload.

Cloud-to-device

Subscribe to devices/<id>/messages/devicebound/# for messages enqueued by the hub. The component delivers each on the standard OnMQTTPublish event.

Reconnect-safe

WatchDog on the underlying client re-authenticates (fresh SAS token) and resubscribes to every active topic on reconnect — the application sees a continuous stream.

Specifications & references

Authoritative sources for the protocol this component implements.

Documentation & Demos

Deep-link to the component reference, grab the ready-to-run demo project, and download the trial.

Online Help — TsgcIoTAzure_MQTT_Client Full property, method and event reference for this component.
Demo Project — Demos\10.IoT_Clients Ready-to-run example project. Ships inside the sgcWebSockets package — download the trial below.
Technical Document (PDF) Features, quick start, code samples for Delphi & C++ Builder and primary-source references — this component only.
User Manual (PDF) Comprehensive manual covering every component in the library.
Best value: All-AccessEvery eSeGeCe product, Premium Support included, from €1,059/year.
See All-Access pricing

Ready to Connect Delphi to Azure IoT?

Download the free trial and stream IoT telemetry from Delphi devices to Azure IoT Hub.