I'm trying hit some endpoints on the 8Base API with the Arduino Uno Wifi Rev2. I was able to get this API call to work with Postman, but I've had no luck once I convert it to my Arduino code. In Postman, clicking the "Code" button reveals that this is what the successful Postman request looks like:
POST /MY_PATH HTTP/1.1
Host: api.8base.com
Authorization: Bearer MY_TOKEN
Content-Type: application/json
Content-Length: 64
{
"query": "{ listOfMachinesList { items{ machineID } } }"
}
Here's what the relevant parts of my Arduino code look like after translating this API call into my Arduino:
#include <ArduinoJson.h>
#include <SPI.h>
#include <WiFiNINA.h>
#include <Arduino.h>
WiFiSSLClient client;
char server[] = "api.8base.com";
const String requestBody = "{\"query\": \"{ listOfMachinesList { items{ machineID } } }\"}";
int status = WL_IDLE_STATUS;
void setup(){
Serial.begin(9600);
Serial.println("Starting");
status = WiFi.begin(WifiSSID, WifiPassword);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.println("Waiting for connection");
}
Serial.println("Connected to wifi");
attemptConnect();
}
void attemptConnect() {
Serial.println("\nStarting connection to server...");
if (client.connectSSL(server, 443)) {
Serial.println("connected to server");
// Make a HTTP request:
client.print("POST /MY_PATH HTTP/1.1");
client.println("User-Agent: Arduino/2.2.0");
client.print("Authorization: Bearer ");
client.println(String(APIKey));
client.println("Content-type: application/json");
client.print("Host: ");
client.println(server);
client.println("Connection: keep-alive");
client.println();
Serial.println("finished POST request");
} else {
Serial.println("didn't connect");
}
}
The connection appears to fail on"client.connectSSL(server, 443)" before it can get inside the "if". My Serial Monitor shows the "didn't connect" message. Further, I added some additional Serial.println statements inside the connectSSL function. It looks like the connection fails in a function called void ServerDrv::startClient'", specifically here:
if (!SpiDrv::waitResponseCmd(START_CLIENT_TCP_CMD, PARAM_NUMS_1, &_data, &_dataLen))
{
WARN("error waitResponse");
}
I added the certificates from both api.8base.com and 8base.com following the instructions here: https://support.arduino.cc/hc/en-us/articles/360016119219-How-to-add-certificates-to-Wifi-Nina-Wifi-101-Modules-
Using this code and the certificate instructions above, I was able to connect to google.com on port 443, but no luck with 8base. I know that 8base uses GraphQL for their connections, but I was able to hit another GraphQL endpoint on a different, non-SSL server. I also checked to see if 8base was using a non-standard port, but, according to Postman, it is using 443. I'm a little confused why I can't get past the connectSSL function. On the surface, it seems like it should behave the same way as it does when I connect to Google, but there must be something else going on that I'm missing. Any help would be greatly appreciated!