Skip to main content

azure_iot_hub 0.1.0-dev.1 copy "azure_iot_hub: ^0.1.0-dev.1" to clipboard
azure_iot_hub: ^0.1.0-dev.1 copied to clipboard

Unofficial native Dart device SDK for Azure IoT Hub with MQTT/TLS, WebSockets, SAS/X.509 authentication, telemetry, twins, direct methods, C2D messages, retries and cancellation.

example/azure_iot_hub_example.dart

import 'dart:convert';
import 'dart:io';

import 'package:azure_iot_hub/azure_iot_hub.dart';

Future<void> main() async {
  final connectionString =
      Platform.environment['AZURE_IOT_DEVICE_CONNECTION_STRING'];
  if (connectionString == null || connectionString.isEmpty) {
    throw StateError('Set AZURE_IOT_DEVICE_CONNECTION_STRING before running.');
  }
  final client = DeviceClient.fromConnectionString(connectionString);
  try {
    await client.sendEvent(
      .new(
        utf8.encode(jsonEncode({'temperature': 21.5})),
        contentType: 'application/json',
        contentEncoding: 'utf-8',
      ),
    );
    final twin = await client.getTwin();
    print(
      'Telemetry acknowledged; desired version: '
      '${twin.properties.desired?[r'$version']}',
    );
  } on OperationFailure catch (error) {
    stderr.writeln(
      'Operation failed: ${error.reason.name}; '
      'delivery: ${error.delivery.name}',
    );
    exitCode = 1;
  } finally {
    await client.close();
  }
}
0
likes
160
points
54
downloads

Documentation

API reference

Publisher

unverified uploader

Weekly Downloads

Unofficial native Dart device SDK for Azure IoT Hub with MQTT/TLS, WebSockets, SAS/X.509 authentication, telemetry, twins, direct methods, C2D messages, retries and cancellation.

Repository (GitHub)
View/report issues

License

MIT (license)

Dependencies

cancellation_token, crypto, event_bus, mqtt_client, typed_data, uuid

More

Packages that depend on azure_iot_hub