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.
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.
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.
TsgcIoTAzure_MQTT_Client
Windows, macOS, Linux, iOS, Android
Standard / Professional / Enterprise
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;
A pre-configured MQTT client for Azure IoT Hub that builds the username/password/topic strings Microsoft expects.
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.
Set IoT.Authentication := iotAuth_Certificate and load the leaf certificate / private key — supports the IoT Hub thumbprint and CA-signed flows.
Subscribe to $iothub/twin/PATCH/properties/desired/# for desired-property pushes; publish to $iothub/twin/PATCH/properties/reported/?$rid= to update the reported state.
Subscribe to $iothub/methods/POST/# for inbound direct-method invocations; reply on $iothub/methods/res/<status>/?$rid=<id> with the response payload.
Subscribe to devices/<id>/messages/devicebound/# for messages enqueued by the hub. The component delivers each on the standard OnMQTTPublish event.
WatchDog on the underlying client re-authenticates (fresh SAS token) and resubscribes to every active topic on reconnect — the application sees a continuous stream.
Authoritative sources for the protocol this component implements.
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. | Open | |
| Demo Project — Demos\10.IoT_Clients Ready-to-run example project. Ships inside the sgcWebSockets package — download the trial below. | Open | |
| Technical Document (PDF) Features, quick start, code samples for Delphi & C++ Builder and primary-source references — this component only. | Open | |
| User Manual (PDF) Comprehensive manual covering every component in the library. | Open |