Connecting to 8Base with an Arduino Uno Wifi Rev2 using SSL

Hi all,

I originally posted this question on StackExchange without any luck, but I figured I'd go right to the source to see if anyone in the Arduino community has attempted something similar.

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 (Note that the workspace ID is not the real one. I changed it to keep mine anonymous):

POST /clabciv8p030709mh4t5mgyep HTTP/1.1
Host: api.8base.com
Authorization: Bearer MY_TOKEN
Content-Type: application/json
Content-Length: 64

{
    "query": "{ listOfMachinesList { items{ machineID } } }"
}

Using the Postman console, I verified that the TLS port is the default 443 port.

Using various examples online, I used the WifiNINA library to produce this code (again, I changed the workspace ID for this forum post):

#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 /clabciv8p030709mh4t5mgyep 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 in the Arduino Help Center.

Using this code and the certificate instructions above, I was able to connect to google 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 even setup a REST endpoint for 8base using a webhook without any luck. 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!

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