I am trying to connect to AWS IoT through the Arduino Portenta H7 and I am following this blog (https://create.arduino.cc/projecthub/Arduino_Genuino/securely-connecting-an-arduino-mkr-wifi-1010-to-aws-iot-core-a9f365).
When I run the code, it shows that there was an error connecting to the MQTT broker (Error code: -2)...but when I check the Cloudwatch logs, it shows a successful connection and a client initiated disconnection. I am not sure why it disconnects as my code does not initiate disconnection.
Here is the code:
void connectMQTT() {
Serial.print("Attempting to MQTT broker: ");
Serial.print(broker);
Serial.println(" ");
while (!mqttClient.connect(broker, 8443)) {
// failed, retry
Serial.print(mqttClient.connectError());
Serial.print("\t");
delay(5000);
}
Serial.println();
Serial.println("You're connected to the MQTT broker");
Serial.println();
// subscribe to a topic
mqttClient.subscribe("arduino/incoming");
}