aws_iot_device 0.0.4

  • README.md
  • CHANGELOG.md
  • Example
  • Installing
  • Versions
  • new66

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.0.4

  • Added missing "unsubscribe" method

0.0.3

  • Relaxed constraints
  • Export MQTT and Tuple

0.0.2

  • Formatted

0.0.1

  • Initial version, it's working for my use case.

example/aws_iot_device_example.dart

import 'dart:io';

import 'package:aws_iot_device/aws_iot_device.dart';

main() async {
  const region = 'us-east-1';

  //These you will get from Cognito
  const accessKey = '';
  const secretAccessKey = '';
  const sessionToken = '';

  //This is your host. It's probably something like 'abcde191919-ats'
  const host = '';

  //This is the ID of the AWS IoT device
  const deviceId = '123-123-123-123';

  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!');
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  aws_iot_device: ^0.0.4

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter packages get

Alternatively, your editor might support pub get or flutter packages get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:aws_iot_device/aws_iot_device.dart';
  
Version Uploaded Documentation Archive
0.0.4 Jan 15, 2019 Go to the documentation of aws_iot_device 0.0.4 Download aws_iot_device 0.0.4 archive
0.0.3 Jan 12, 2019 Go to the documentation of aws_iot_device 0.0.3 Download aws_iot_device 0.0.3 archive
0.0.2 Jan 10, 2019 Go to the documentation of aws_iot_device 0.0.2 Download aws_iot_device 0.0.2 archive
0.0.1 Jan 10, 2019 Go to the documentation of aws_iot_device 0.0.1 Download aws_iot_device 0.0.1 archive
Popularity:
Describes how popular the package is relative to other packages. [more]
36
Health:
Code health derived from static analysis. [more]
99
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
90
Overall:
Weighted score of the above. [more]
66
Learn more about scoring.

We analyzed this package on Jan 15, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.1.0
  • pana: 0.12.10

Platforms

Detected platforms: Flutter, other

Primary library: package:aws_iot_device/aws_iot_device.dart with components: io.

Health issues and suggestions

Document public APIs. (-1 points)

20 out of 20 API elements (library, class, field or method) have no adequate dartdoc content. Good documentation improves code readability and discoverability through search.

Format lib/src/device.dart.

Run dartfmt to format lib/src/device.dart.

Maintenance suggestions

Package is pre-v0.1 release. (-10 points)

While there is nothing inherently wrong with versions of 0.0.*, it usually means that the author is still experimenting with the general direction of the API.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0 <3.0.0
amazon_cognito_identity_dart ^0.0.20 0.0.20
mqtt_client ^5.2.0 5.3.0
tuple ^1.0.2 1.0.2
Transitive dependencies
async 2.0.8
charcode 1.1.2
collection 1.14.11
convert 2.1.1
crypto 2.0.6
event_bus 1.0.1
http 0.12.0+1
http_parser 3.1.3
matcher 0.12.4
meta 1.1.7
path 1.6.2
quiver 2.0.1
source_span 1.5.1
stack_trace 1.9.3
string_scanner 1.0.4
term_glyph 1.1.0
typed_data 1.1.6
Dev dependencies
test ^1.0.0