There is no response from a GET request with the Wio Terminal to a specific API, api. ambeedata .com The code is modified from Seeed's example: Reading Github Repository Stats from Wio Terminal. The original Github example works fine. After modifying the code to pass my API key and use the api. ambeedata .com endpoints, the request doesn't return. However, a connection is established to the server. Testing the request in Postman with the same request returns the correct JSON response. The Realtek RTL8720 firmware is 2.1.2, and all dependant libraries are the most recent versions. (Arduino FS, rpcUnified, rpcWiFi, SFUD, mbedtls) Using a different Arduino board, I replicated the code and got the correct JSON response from api.ambeedata.com. Any recommendations on what to try next would be appreciated! The same question asked at stackoverflow, but still not getting any helping reply so I put here.
switches
#include <rpcWiFi.h>
#include <WiFiClientSecure.h>
const char* ssid = "SSID"; // your network SSID
const char* password = "password"; // your network password
const char* server = "api.ambeedata.com"; // Server URL
const char* test_root_ca = \
"-----BEGIN CERTIFICATE-----\n"
//Removed for the brevity of the post
"-----END CERTIFICATE-----\n";
WiFiClientSecure client;
void setup() {
//Initialize serial and wait for port to open:
Serial.begin(115200);
while (!Serial); // Wait for Serial to be ready
delay(1000);
// attempt to connect to Wifi network:
while (WiFi.status() != WL_CONNECTED) {
Serial.print("Attempting to connect to SSID: ");
Serial.println(ssid);
Serial.println(WiFi.status());
WiFi.begin(ssid, password);
Serial.println(WiFi.status());
Serial.print(".");
// wait 3 seconds for re-trying
delay(3000);
}
Serial.print("Connected to ");
Serial.println(ssid);
client.setCACert(test_root_ca);
Serial.println("\nStarting connection to server...");
if (!client.connect(server, 443)) {
Serial.println("Connection failed!");
}
else {
Serial.println("Connected to server!");
//Send GET request to API
client.println("GET https://api.ambeedata.com HTTP/1.0");
client.println("Host: api.ambeedata.com");
client.println("Connection: close");
client.println("x-api-key: apikey");
client.println("Content-type: application/json");
client.println();
Serial.println("request sent");
while (client.connected()) {
String line = client.readStringUntil('\n');
if (line == "\r") {
Serial.println("headers received");
break;
}
}
Serial.println("reply was:");
Serial.println("==========");
String line = client.readStringUntil('\n');
if (line == "\r") {
Serial.println("headers received");
}
// if there are incoming bytes available
// from the server, read them and print them:
while (client.available()) {
char c = client.read();
if (c == '\n') {
Serial.write('\r');
}
Serial.write(c);
}
client.stop();
}
}
void loop() {
// do nothing
}