Arduino Nano 33 IoT AWS MQTT

Hello, I've been trying to connect my nano 33 iot to aws iot to make a request to a topic, however i can't seem to find a way to attach the certificates hence i'm getting this error

#include <WiFiNINA.h>
#include <MQTT.h>

// SSL client and MQTT client setup
WiFiSSLClient net;
MQTTClient client(256);

// Wi-Fi credentials
const char* ssid = "WIFI_NETWORK";
const char* password = "";

// AWS IoT endpoint (replace with your actual endpoint)
const char* aws_endpoint = "xxxx-ats.iot.us-east-1.amazonaws.com";

// MQTT topic to publish to
const char* topic = "topic/test";

// Amazon Root CA Certificate (replace with your actual certificate)
const char ca_cert[] PROGMEM = R"EOF(
-----BEGIN CERTIFICATE-----

-----END CERTIFICATE-----
)EOF";

// Device Certificate (replace with your actual certificate)
const char device_cert[] PROGMEM = R"EOF(
-----BEGIN CERTIFICATE-----

-----END CERTIFICATE-----
)EOF";

// Private Key (replace with your actual private key)
const char private_key[] PROGMEM = R"EOF(
-----BEGIN RSA PRIVATE KEY-----

-----END RSA PRIVATE KEY-----
)EOF";

void setup() {
  // Initialize serial communication for debugging
  Serial.begin(115200);
  delay(100);

  // Check if the WiFi module is present
  if (WiFi.status() == WL_NO_MODULE) {
    Serial.println("WiFi module not detected");
    while (true);
  }

  // Connect to Wi-Fi
  Serial.print("Connecting to Wi-Fi...");
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("\nConnected to Wi-Fi");

  // Initialize MQTT client with AWS IoT endpoint and secure connection
  client.begin(aws_endpoint, 8883, net);
  Serial.println("MQTT client setup complete.");
}

void loop() {
  // MQTT connection and communication code
  if (!client.connected()) {
    Serial.println("Attempting MQTT connection...");
    if (client.connect("ArduinoNano33IoT")) { // Use unique client ID
      Serial.println("Connected to AWS IoT");
      // Publish data to the topic
      String message = "{\"temperature\": 25.0, \"humidity\": 60.0}"; // Example data payload
      client.publish(topic, message);
      Serial.println("Data published to topic: " + String(topic));
    } else {
      Serial.print("Failed to connect, status: ");
      Serial.println(client.lastError());
      delay(5000); // Retry after a short delay
    }
  }

  client.loop();
  delay(10000); // Wait 10 seconds before sending the next message
}

Connecting to Wi-Fi...

Connected to Wi-Fi

MQTT client setup complete.

Attempting MQTT connection...

Failed to connect, status: -3

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.