Need Help Implementing HTTPS on Arduino UNO R4 WiFi (ESP32-S3) for SMS API

Hi everyone,

I'm working on a project using the Arduino UNO R4 WiFi, and I'm trying to send an SMS through Textbelt's API. My code works fine for connecting to my iPhone hotspot, but when I attempt to send the SMS, I get the following error:

HTTP Response code: 400
Response:

400 The plain HTTP request was sent to HTTPS port

400 Bad Request

The plain HTTP request was sent to HTTPS port
cloudflare

From the error, I understand that the server is expecting an HTTPS (encrypted) request on port 443, but my code is sending a plain HTTP request. My current code uses the WiFiS3 library with a WiFiClient:

#include <WiFiS3.h>
#include <ArduinoHttpClient.h>

// Hotspot credentials
const char* ssid = "iPhone";
const char* password = "20215451";

// SMS API details
const char* server = "textbelt.com";
const int port = 443; // HTTPS port
const char* api_key = "YOUR_API_KEY";

// Set up client
WiFiClient wifi;
HttpClient client = HttpClient(wifi, server, port);

void setup() {
Serial.begin(115200);
WiFi.begin(ssid, password);

while (WiFi.status() != WL_CONNECTED) {
    delay(1000);
    Serial.println("Connecting to iPhone Hotspot...");
}
Serial.println("Connected to Hotspot!");

sendSMS("+18609901281", "Hello from Arduino UNO R4 WiFi!");

}

void sendSMS(String phone, String message) {
String requestBody = "{"phone":"" + phone + "","message":"" + message + "","key":"" + String(api_key) + ""}";
Serial.println("Sending SMS...");
client.beginRequest();
client.post("/text");
client.sendHeader("Content-Type", "application/json");
client.sendHeader("Content-Length", requestBody.length());
client.beginBody();
client.print(requestBody);
client.endRequest();

int statusCode = client.responseStatusCode();
String response = client.responseBody();

Serial.print("HTTP Response code: ");
Serial.println(statusCode);
Serial.println("Response: " + response);

}

void loop() {
// Do nothing
}
I tried switching to WiFiClientSecure to enable TLS/SSL, but I ran into a compilation error because WiFiClientSecure.h is not available in my current setup for the UNO R4 WiFi. According to the datsasheet the R4 wifi uses a ESP32-S3 module for Wi-Fi. This suggests that HTTPS should be supported, but I can't seem to find the proper secure client library or example code for this board.

Has anyone successfully implemented HTTPS requests on the Arduino UNO R4 WiFi (or similar boards with an ESP32-S3) using a secure client? Any pointers on the correct library to use or examples would be greatly appreciated!

Thanks in advance for your help.

the official Arduino class for secure connection is WiFiSSLClient

1 Like

I ran into the same issue and solved it by using WiFiClientSecure with setInsecure(), since the Arduino UNO R4 doesn’t fully support certificate validation. If you’re testing any HTTPS APIs, double-check the endpoint URL and required headers—small mistakes there can also cause 400 errors.

@yageornba this thread is about the Uno R4 WiFi, not about the esp32