Hi,
I am trying to make HTTP POST requests to AWS Lambda with BearSSLClient on Arduino Nano 33 IoT, but the endpoint always disconnects after 60 seconds. I verified it with curl requests from the host and it responds just fine.
I generated the certificates, created the AWS Thing and created a HTTP Endpoint. Maybe I should not be using SSL/TLS?
The code looks like this:
WiFiSSLClient wifiClient; // Used for the TCP socket connection
BearSSLClient client(wifiClient); // Used for SSL/TLS connection, integrates with ECC508
void setup() {
//Initialize serial and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
// check for the WiFi module:
if (WiFi.status() == WL_NO_MODULE) {
Serial.println("Communication with WiFi module failed!");
// don't continue
while (true);
}
String fv = WiFi.firmwareVersion();
if (fv < WIFI_FIRMWARE_LATEST_VERSION) {
Serial.println("Please upgrade the firmware");
}
if (!ECCX08.begin()) {
Serial.println("No ECCX08 present!");
while (1);
}
// Set a callback to get the current time
// used to validate the servers certificate
ArduinoBearSSL.onGetTime(getTime);
// Note how the certificate is formed
String(certificate) = String(client_cert) + String(root_ca);
Serial.println(certificate);
// Set the ECCX08 slot to use for the private key
// and the accompanying public certificate for it
client.setEccSlot(0, certificate.c_str());
// attempt to connect to WiFi network:
while (status != WL_CONNECTED) {
Serial.print("Attempting to connect to SSID: ");
Serial.println(ssid);
// Connect to WPA/WPA2 network. Change this line if using open or WEP network:
status = WiFi.begin(ssid, pass);
// wait 10 seconds for connection:
delay(5000);
}
Serial.println("Connected to WiFi");
printWiFiStatus();
Serial.println("\nStarting connection to server...");
// if you get a connection, report back via serial:
if (client.connect(server, 443)) {
Serial.println("connected to server");
// Make a HTTP request:
client.println("GET / HTTP/1.1");
client.print("Host: ");
client.println(server);
//client.print("content-length: ");
//client.println("3");
//lambda.println("connection: close");
client.println();
//client.println("{}");
}
}
void loop() {
// if there are incoming bytes available
// from the server, read them and print them:
while (client.available()) {
char c = client.read();
Serial.write(c);
}
// if the server's disconnected, stop the client:
if (!client.connected()) {
Serial.println();
Serial.println("disconnecting from server.");
client.stop();
// do nothing forevermore:
while (true);
}
}