0

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");
}
2
  • Did you correctly set up the certificate? Commented Aug 3, 2022 at 21:07
  • Yes...because the Cloudwatch logs show that the device connected and even subscribed Commented Aug 4, 2022 at 1:52

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.