-
-
Notifications
You must be signed in to change notification settings - Fork 8
Description
Hello a try to connect to aws iot follow al exemples and issues in this repository but always not connect and give a error above is my code
#include <WiFi.h>
#include <ArduinoJson.h>
#include <NTPClient.h>
#include <ESP_SSLClient.h>
const char PROGMEM Const_PrivateKeyRSA[]
const char PROGMEM Const_CaCertificate[]
const char PROGMEM Const_ClientCertificate[]
// WiFi credentials
const char ssid[] = "********";
const char pass[] = "*******";
WiFiClient wifi;
ESP_SSLClient net;
WiFiUDP ntpUDP;
NTPClient timeClient(ntpUDP, "pool.ntp.org", 0, 1000); // Sync every second
void connectToAWS() {
timeClient.update();
// Get the current epoch time in UTC
unsigned long utcTime = timeClient.getEpochTime();
// Print the UTC time in Unix format
Serial.print("Current UTC time in Unix format: ");
Serial.println(utcTime);
net.setX509Time(utcTime);
// Configure WiFiClientSecure to use the AWS certificates we generated
net.setCACert(Const_CaCertificate);
net.setCertificate(Const_ClientCertificate);
net.setPrivateKey(Const_PrivateKeyRSA);
net.setBufferSizes(16384, 16384);
net.setDebugLevel(4);
net.setClient(&wifi);
// Try to connect to AWS
Serial.println("Connecting to AWS IOT...");
// Connect to the MQTT broker on the AWS endpoint we defined earlier
//Serial.print(net.connect("test.mosquitto.org", 8883));
Serial.print(net.connect("*********", 8883));
}
void setup() {
Serial.begin(115200);
// Connect to Wi-Fi
Serial.print("Connecting to Wi-Fi...");
WiFi.begin(ssid, pass);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("\nConnected to Wi-Fi");
Serial.print("SSID: ");
Serial.println(WiFi.SSID());
Serial.print("IP Address: ");
Serial.println(WiFi.localIP());
// Initialize NTPClient
timeClient.begin();
timeClient.update();
connectToAWS();
}
void loop()
{
}
and gives this log debug
`> INFO.mConnectBasicClient: Basic client connected!
INFO.mConnectSSL: Start connection.
WARN.mConnectSSL: Connection will fail, no authentication method is setup.
INFO.mConnectSSL: Wait for SSL handshake.
INFO.mUpdateEngine: State RECVREC
INFO.mUpdateEngine: State RECVREC
INFO.mRunUntil: SSL state changed.
INFO.mRunUntil: State RECVREC
INFO.mRunUntil: Expected bytes count: 5
INFO.mUpdateEngine: State Connection close
WARN.mRunUntil: Terminating because the ssl engine closed.
ERROR.mConnectSSL: Failed to initlalize the SSL layer.
ERROR.mConnectSSL: Chain could not be linked to a trust anchor.`
using the library wifisecureclient works, so the certs, keys, endpoint and port is ok.
The library works with only ca cert i test in mosquitto broker