Giter Club home page Giter Club logo

dart-flutter-mqtt5-example's Introduction

A MacOS Flutter Client for the AWS IoT using Secure WebSocket

A MacOS Flutter Client for the AWS IoT using Secure WebSocket for a Project utilising the AWS IoT Ecosystem

Getting Started

Setup Auth

Grab the Credentials and place them in the assets/sert forlder.

mkdir -p assets/cert
if [ ! -f ./assets/cert/root-CA.crt ]; then
  printf "\nDownloading AWS IoT Root CA certificate from AWS...\n"
  curl https://www.amazontrust.com/repository/AmazonRootCA1.pem > ./assets/cert/root-CA.crt
fi

Setup assets in pubspec.yaml

In the pubspec.yaml make sure the certificates are listed in the flutter/assets section as follows

flutter:
  assets:
    - assets/cert/root-CA.crt
    - assets/cert/xxx.cert.pem
    - assets/cert/xxx.private.key

Setup the Configs in lib/main.dart

Open the lib/main.dart and configure the follwing:

final strrootCA = 'assets/cert/root-CA.crt';
final pub_key = 'assets/cert/xxx.cert.pem';
final strprivKey = 'assets/cert/xxx.private.key';

final mqtt_endpoint = 'xxxxxxxxxxxxxx';
final mqtt_port = 8883; // AWS IoT Core uses poty 8883 for mqtt protocol.
final mqtt_clientIdentifier = 'xxx';
final mqtt_topic = 'xxx';

Fire it up

flutter clean
flutter pub get
flutter build macos

And then

flutter run

and select the option macOS.

TLS VERIFY Errors / RootCA ?

AWS self-signs their certificates which isn't trusted out of the box. We explicitly set the security context to trust the rootCA's certificate via setTrustedCertificatesBytes.

Excerpt from lib/main.dart below:

SecurityContext context = new SecurityContext()
    ..setTrustedCertificatesBytes(rootCA.buffer.asUint8List())
    ..useCertificateChainBytes(certificates.buffer.asUint8List())
    ..usePrivateKeyBytes(privateKey.buffer.asUint8List());

END OF DOCUMENT

dart-flutter-mqtt5-example's People

Contributors

kryochronic avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.