Azure IoT Hub

Verbind Delphi/C++Builder-applicaties met Azure IoT Hub via MQTT. SAS-token- of X.509-apparaatauthenticatie, device twin, direct-method-aanroepen en cloud-to-device-berichten.

TsgcIoTAzure_MQTT_Client

Azure IoT Hub MQTT 3.1.1-client — SAS-token- of X.509-authenticatie, device twin (desired/reported), direct methods, cloud-to-device-berichten en Azure-specifieke topic-conventies.

Componentklasse

TsgcIoTAzure_MQTT_Client

Platforms

Windows, macOS, Linux, iOS, Android

Editie

Standard / Professional / Enterprise

Stel hub en credentials in en verbind

Stel de IoT Hub-host, deviceId en SAS-key in (of een X.509-certificaat), maak vervolgens verbinding om je te abonneren op $iothub/twin/... en te publiceren op 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;

Wat zit erin

Een voorgeconfigureerde MQTT-client voor Azure IoT Hub die de username-, password- en topic-strings opbouwt die Microsoft verwacht.

SAS-token-authenticatie

Stel IoT.Authentication := iotAuth_SAS in en geef de device-key op — de component genereert kortlevende SAS-tokens met de juiste resource-URI en ondertekent ze met HMAC-SHA256.

X.509-authenticatie

Stel IoT.Authentication := iotAuth_Certificate in en laad het leaf-certificaat / de privésleutel — ondersteunt IoT Hub-thumbprint- en CA-getekende flows.

Device twin

Abonneer je op $iothub/twin/PATCH/properties/desired/# voor pushes van desired properties; publiceer op $iothub/twin/PATCH/properties/reported/?$rid= om de reported state bij te werken.

Direct methods

Abonneer je op $iothub/methods/POST/# voor inkomende direct-method-aanroepen; antwoord op $iothub/methods/res/<status>/?$rid=<id> met de response-payload.

Cloud-to-device

Abonneer je op devices/<id>/messages/devicebound/# voor berichten die door de hub in de wachtrij zijn gezet. De component levert elk bericht op het standaard OnMQTTPublish-event.

Reconnect-safe

WatchDog op de onderliggende client authenticeert opnieuw (vers SAS-token) en abonneert zich bij reconnect opnieuw op elk actief topic — de applicatie ziet een ononderbroken stroom.

Specificaties & referenties

Gezaghebbende bronnen voor het protocol dat deze component implementeert.

Documentatie & demo's

Deep-link naar de componentreferentie, pak het kant-en-klare demoproject en download de proefversie.

Online help — TsgcIoTAzure_MQTT_Client Volledige referentie van eigenschappen, methoden en events voor deze component.
Demoproject — Demos\10.IoT_Clients Kant-en-klaar voorbeeldproject. Wordt meegeleverd in de sgcWebSockets-package — download hieronder de proefversie.
Technisch document (PDF) Functies, snelstart, codevoorbeelden voor Delphi & C++ Builder en primaire bronverwijzingen — alleen voor deze component.
Gebruikershandleiding (PDF) Uitgebreide handleiding die elke component in de bibliotheek behandelt.

Klaar om Delphi te verbinden met Azure IoT?

Download de gratis proefversie en streaming IoT-telemetrie van Delphi-apparaten naar Azure IoT Hub.