Connection from ESP32 always fails.
I have written a simple sketch just to test the connection. A very similar connection code running from Nano get connected.
Code: Select all
#include <WiFi.h>
#include <WiFiClientSecure.h>
const char ssid[] = "myssid";
const char pass[] = "mypassword";
#define BROKER_ADDRESS "io.adafruit.com"
#define BROKER_PORT 8883
/// Ca Cert Adafruit
const char* ca_cert1 = \
"-----BEGIN CERTIFICATE-----\n" \
"MIIGijCCBXKgAwIBAgIQAfUXR/1IrnlbCX0+CKqtnDANBgkqhkiG9w0BAQsFADBe\n" \
...
...
"ApmyW7PbQr+9lZuNzkqieNIt/VuCyNIKZEBJ3PA/2QfwvXdIpjE6M7yz+9kh9WdR\n" \
"Rg6qj6hPp2gvSQQrk361RY/sTtueAh4re8yyJDebH3B60kUwzNmMms7zcxQ0Ctvg\n" \
"/BDPVBd1VFF/tsoYO4P5iMar1YCl8BNozu6q4JP2E0HRygZD0U7vY2Gsi1wHdm5h\n" \
"VZnLJq6SRTbYUWY3tryEp2lJYQFiSoVfu5icebrLUVRmSl05PyYstjFekb9DCNyy\n" \
"LIBZsjmaFJoJCGo1y5cSqBYfwSsrq1aD9hn5LFeEVG+PEa10IlVv7l+33mLWZA==\n" \
"-----END CERTIFICATE-----\n";
WiFiClientSecure net;
void setup() {
Serial.begin(115200);
while (!Serial)
;
delay(1500);
Serial.println("Start");
WiFi.begin(ssid, pass);
Serial.println("checking wifi...");
while (WiFi.status() != WL_CONNECTED) {
Serial.print(".");
delay(1000);
}
Serial.println("wifi connected");
net.setCACert(ca_cert1);
if (net.connect(BROKER_ADDRESS, BROKER_PORT)) {
Serial.println("connected to server");
}
else {
Serial.println("connection to server failed");
}
}
void loop() {
// put your main code here, to run repeatedly:
}