Wanted to interface to the new OpenAI API from Wio Terminal which requires https post protocol. I cannot seem to establish a connection to OpenAI. Certificate is from “api.openai.com” which hosts the endpoint. Program executes up until the connect function from WiFiClientSecure is executed and then it just seems to hang with no return value. Code is at:
Thanks for taking a look, but it’s still not functional. I took the suggested code and modified <#include WiFi.h> to include rpcWiFi.h instead (for the Wio, I guess). This simple program hangs at the Get request. Could be an issue with rpcWiFi? I know my OpenAI key is good and use it from other programs not on the Wio Terminal.
If anyone with a Wio Terminal wants to try this out, the code is below. You’ll need a free OpenID API key, though. Thanks!
/*
The simplest demo of Wio Terminal calling OpenAI
*/
There are no error codes. The last line I see execute is Serial.print("[HTTPS] GET…\n"); then it just seems to hang. The next line is the int httpCode = https.POST(payload); which doesn’t return and just seems to hang…I have all of the updated and most current libraries. Wifi connection is strong. I am out of ideas.
I bought a XIAO ESP32C3, the hardware this code was originally developed to run on. It will be interesting if it runs there but not on the Wio Terminal.
Hi Citric, I purchased a XIAO ESP32C3 to test the example code you supplied. In the github repository for the project there is a simple program showing accessing OpenAI in a very simple way. The program is at xiaoesp32c3-chatgpt/simplest_xiao-chatgpt.ino at main · limengdu/xiaoesp32c3-chatgpt · GitHub. The program runs great on the new ESP32C3 I purchased, but will not run on my Wio Terminal, even after I changed the WiFi.h library to rpcWiFi.h for the Wio. It will complle with no errors like that, but will not run. It does not give any error messages, it simply seems to run until line 49, where the https POST is called and I never see a return value. Has anyone a working example of an HTTPS POST using the Wio Terminal?