aws_iot_device 0.0.4

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

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

Alternatively, your editor might support pub 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]
5
Health:
Code health derived from static analysis. [more]
12
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
70
Overall:
Weighted score of the above. [more]
20
Learn more about scoring.

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

  • Dart: 2.3.2
  • pana: 0.12.18

Platforms

Detected platforms:

Low code quality prevents platform classification.

Health issues and suggestions

Fix lib/src/device.dart. (-87.43 points)

Analysis of lib/src/device.dart failed with 7 errors, 12 hints, including:

line 179 col 38: Static method 'buildCanonicalQueryString' can't be accessed through an instance.

line 180 col 25: Static method 'buildCanonicalRequest' can't be accessed through an instance.

line 189 col 40: Static method 'hashCanonicalRequest' can't be accessed through an instance.

line 190 col 30: Static method 'buildStringToSign' can't be accessed through an instance.

line 192 col 10: Static method 'buildCredentialScope' can't be accessed through an instance.

Document public APIs. (-1 points)

20 out of 20 API elements have no dartdoc comment.Providing good documentation for libraries, classes, functions, and other API elements improves code readability and helps developers find and use your API.

Maintenance issues and suggestions

Fix platform conflicts. (-20 points)

Low code quality prevents platform classification.

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

While nothing is inherently wrong with versions of 0.0.*, it might mean 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.22
mqtt_client ^5.2.0 5.5.3
tuple ^1.0.2 1.0.2
Transitive dependencies
async 2.2.0
charcode 1.1.2
collection 1.14.11
convert 2.1.1
crypto 2.0.6
event_bus 1.1.0
http 0.12.0+2
http_parser 3.1.3
matcher 0.12.5
meta 1.1.7
path 1.6.2
pedantic 1.7.0
quiver 2.0.3
source_span 1.5.5
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