Closed JoaquimFlavio closed 4 years ago
I believe port 443 is the secure TLS option for AWS(was 8883), so you will need to set secure to true and set up any cert paths you need as per the example in the examples directory.
I can't use certificates for this aplication, i need use a WebSockets... Because i using the Cognito for provider my acsses credentials. It`s a very strange, i create 2 users for test, and 1 working and other don't working....
For ports, the AWS say (https://docs.aws.amazon.com/pt_br/iot/latest/developerguide/protocols.html):
Protocolo | Autenticação | Porta | ProtocolName da ALPN |
---|---|---|---|
MQTT | Certificado do cliente X.509 | 8883, 443† | x-amzn-mqtt-ca |
HTTPS | Certificado do cliente X.509 | 8443, 443† | x-amzn-http-ca |
HTTPS | SigV4 | 443 | N/D |
MQTT pelo WebSocket | SigV4 | 443 | N/D |
Ok, you could try changing the websocket protocol string, see the examples. When you say '1 working and other don't working' do you mean two mqtt_clients or one mqtt_client and another type of client?
The 2 clients is from the Cognito. I use hers for get the credentials, and create a URL for connect on AWS-IOT (https://docs.aws.amazon.com/pt_br/iot/latest/developerguide/http.html).
When i use the first Cognito user, the connection is sucessfull! But when i use the second Cognito user, the connection don't work....
Logging for first:
flutter: 2020-02-25 04:54:20.373247 -- SynchronousMqttConnectionHandler::internalConnect entered
flutter: 2020-02-25 04:54:20.373729 -- SynchronousMqttConnectionHandler::internalConnect - initiating connection try 0
flutter: 2020-02-25 04:54:20.373988 -- SynchronousMqttConnectionHandler::internalConnect - websocket selected
flutter: 2020-02-25 04:54:20.375496 -- MqttWsConnection:: WS URL is wss://
flutter: 2020-02-25 04:54:21.070417 -- MqttConnection::_startListening
flutter: 2020-02-25 04:54:21.071357 -- SynchronousMqttConnectionHandler::internalConnect sending connect message
flutter: 2020-02-25 04:54:21.071938 -- MqttConnectionHandler::sendMessage - MQTTMessage of type MqttMessageType.connect
Header: MessageType = MqttMessageType.connect, Duplicate = false, Retain = false, Qos = MqttQos.atMostOnce, Size = 0
Connect Variable Header: ProtocolName=MQIsdp, ProtocolVersion=3, ConnectFlags=Connect Flags: Reserved1=false, CleanStart=true, WillFlag=false, WillQos=MqttQos.atMostOnce, WillRetain=false, PasswordFlag=false, UserNameFlag=false, KeepAlive=0
MqttConnectPayload - client identifier is :
flutter: 2020-02-25 04:54:21.074491 -- SynchronousMqttConnectionHandler::internalConnect - pre sleep, state = Connection status is connecting with return code noneSpecified
flutter: 2020-02-25 04:54:21.675037 -- MqttConnection::_onData
flutter: 2020-02-25 04:54:21.684137 -- MqttConnection::_onData - message received MQTTMessage of type MqttMessageType.connectAck
Header: MessageType = MqttMessageType.connectAck, Duplicate = false, Retain = false, Qos = MqttQos.atMostOnce, Size = 2
Connect Variable Header: TopicNameCompressionResponse={0}, ReturnCode={MqttConnectReturnCode.connectionAccepted}
flutter: 2020-02-25 04:54:21.694044 -- MqttConnection::_onData - message processed
flutter: 2020-02-25 04:54:21.697801 -- SynchronousMqttConnectionHandler::_connectAckProcessor
flutter: 2020-02-25 04:54:21.698661 -- SynchronousMqttConnectionHandler::_connectAckProcessor - state = connected
flutter: 2020-02-25 04:54:21.702914 -- SynchronousMqttConnectionHandler:: cancelling connect timer
flutter: 2020-02-25 04:54:21.705611 -- SynchronousMqttConnectionHandler::internalConnect - post sleep, state = Connection status is connected with return code connectionAccepted
flutter: 2020-02-25 04:54:21.705978 -- SynchronousMqttConnectionHandler::internalConnect exited with state Connection status is connected with return code connectionAccepted
Logging for second:
flutter: 2020-02-25 04:50:39.843245 -- SynchronousMqttConnectionHandler::internalConnect entered
flutter: 2020-02-25 04:50:39.853408 -- SynchronousMqttConnectionHandler::internalConnect - initiating connection try 0
flutter: 2020-02-25 04:50:39.854278 -- SynchronousMqttConnectionHandler::internalConnect - websocket selected
flutter: 2020-02-25 04:50:39.855500 -- MqttWsConnection:: WS URL is wss:____MYURL_____
flutter: 2020-02-25 04:50:40.599027 -- MqttConnection::_startListening
flutter: 2020-02-25 04:50:40.601652 -- SynchronousMqttConnectionHandler::internalConnect sending connect message
flutter: 2020-02-25 04:50:40.605424 -- MqttConnectionHandler::sendMessage - MQTTMessage of type MqttMessageType.connect
Header: MessageType = MqttMessageType.connect, Duplicate = false, Retain = false, Qos = MqttQos.atMostOnce, Size = 0
Connect Variable Header: ProtocolName=MQIsdp, ProtocolVersion=3, ConnectFlags=Connect Flags: Reserved1=false, CleanStart=true, WillFlag=false, WillQos=MqttQos.atMostOnce, WillRetain=false, PasswordFlag=false, UserNameFlag=false, KeepAlive=0
MqttConnectPayload - client identifier is :
flutter: 2020-02-25 04:50:40.638170 -- SynchronousMqttConnectionHandler::internalConnect - pre sleep, state = Connection status is connecting with return code noneSpecified
OK, not sure why you think the client isn't working here, in the first case its OK, it looks more like a user perms issue.
I make a prototype with this code: https://pub.dev/packages/aws_iot, and now working for 2 Cognito Clients. The solution is a add AttachPolicy for a client.
Thanks for the attention
I trying connect to AWS-IOT with Cognito. This is ok for 1 client, but, case i try use other client i get an error:
My code for connect:
The error:
Can someone help me?