0

I need to connect to IoT Core using Angular 16 and ngx-mqtt@16.0.0. I have tried all the methods. If I add protocolVersion:5 in the connection options, it returns the following error:

error screenshot

And without that option, the connection closes without connecting.

The connection options are as follows:

connectionIotCore: IMqttServiceOptions = {
hostname: 'xxxxxxxxxxxx-ats.iot.us-east-2.amazonaws.com',
port: 443,
protocol: 'wss',
path: '/mqtt',
protocolId: 'MQTT',
protocolVersion: 5,
clientId: localStorage.getItem('username') + '_' + uuidv4(),
rejectUnauthorized: false,
cert: `-----BEGIN CERTIFICATE-----

        -----END CERTIFICATE-----`, 
key: `-----BEGIN RSA PRIVATE KEY-----

        -----END RSA PRIVATE KEY-----`, 
ca: `-----BEGIN CERTIFICATE-----

      -----END CERTIFICATE-----`, 
}

and environment is:

screenshots showing versions

I have tried all the possible methods that have come to mind. I'm not sure if I need to do something in the AWS console, in the connection settings, or if the browser is simply not compatible with an SSL connection using the certificate. Please note that it is Ionic, but I am working on it as a web page. The reason for choosing Ionic instead of pure Angular is that I am still unsure if my app will also be a mobile app or not.

I have tried all the aws sdk libraries, and apparently they are compatible with javascript backend but not brower. That's why I ask how is the connection with ngx-mqtt since it is a very simple and easy to use library. At least with mosquitto with user/password authentication I can connect without problem, easy and fast.

I tried using ngx-mqtt: user/password, certificates of an object, certificate not associated with an object. On the other hand the aws sdk, paho-mqtt, mqtt.js, all the options with the same result: unauthorized.

But I want to use ngx-mqtt as I like that library

halfer
  • 19,824
  • 17
  • 99
  • 186
  • As per the [Device communication protocols](https://docs.aws.amazon.com/iot/latest/developerguide/protocols.html) documentation, the Authentication options when using MQTT over WebSocket are "Signature Version 4" and "Custom authentication". Certificates are not an option (the browser API's don't support [setting a client certificate](https://stackoverflow.com/a/49674945/11810946)). You might find [this article](https://www.here.com/learn/blog/using-mqtt-in-javascript-with-aws-iot) useful (in terms of building a URL with auth details). – Brits May 29 '23 at 19:56

0 Answers0