aws_iot_device 0.0.4
aws_iot_device: ^0.0.4

A wrapper around MQTT to make it easier to connect to AWS IoT.

A simple wrapper around MQTT to talk to the AWS IoT backend using Websockets.

Usage #

First you'll need to get Cognito credentials. We're using the Websocket way to talk to AWS and it needs the access key, secret key and session token.

You can use the amazon_cognito_identity_dart library to get Cognito credentials.

import 'package:aws_iot_device/aws_iot_device.dart';
main() async {
var device = AWSIoTDevice(region, accessKey, secretAccessKey, sessionToken, host);

  try {
    await device.connect(deviceId);
  } on Exception catch (e) {
    print('Failed to connect, status is ${device.connectionStatus}');
    exit(-1);
  }

  device.messages.listen((message) {
    print('Received message on topic "${message.item1}", message is "${message.item2}"');
  });

  //The MQTT topic you want to subscribe to
  const topic = '';

  device.subscribe(topic);

  device.publishMessage(topic, 'Hi!');
}

What about private keys and the like? Well, using Cognito credentials means you don't need that stuff.

0
likes
40
pub points
42%
popularity

A wrapper around MQTT to make it easier to connect to AWS IoT.

Homepage

Documentation

API reference

Uploader

nathankerr@gmail.com

License

MIT (LICENSE)

Dependencies

amazon_cognito_identity_dart, mqtt_client, tuple

More

Packages that depend on aws_iot_device