shamblett / mqtt_client

A server and browser based MQTT client for dart
Other
548 stars 176 forks source link

AWS connection over wss for webapp #366

Closed juanjoabarca closed 2 years ago

juanjoabarca commented 2 years ago

I made a flutter web application, it works perfectly with my local broker over ws, the problem starts when I need to connect the application with AWS, I followed the instructions in this video How to connect to AWS IOT with MQTT with AWS Signature Version 4 authentication? to authenticate but I can't get it to work.

Could you guide me on this, thank you.

part of my code:

 Future<bool> initMqtt() async {
    _client = MqttBrowserClient(host!, '')
      ..port = port!
      ..logging(on: true)
      ..keepAlivePeriod = 20
      ..onConnected = onConnected
      ..onDisconnected = onDisconnected
      ..onSubscribed = onSubscribed
      ..websocketProtocols = MqttClientConstants.protocolsSingleDefault
      ..setProtocolV311();

    final mqttMsg = MqttConnectMessage()
        .withWillTopic('willtopic')
        .withWillMessage('Will message')
        .startClean()
        .withWillQos(MqttQos.atLeastOnce);
    _client.connectionMessage = mqttMsg;
    return await connectionMqtt();
  }
shamblett commented 2 years ago

It can be tricky to connect to AWS, there is an example in the examples directory named aws_iot.dart that may help. I don't use AWS myself but if you search through the closed issues you will find a few reports of issues connecting to AWS that were resolved.

bmjhversteeg commented 2 years ago

371