Gray_code_element

Wednesday, May 21, 2025

Using ESP32 for HTTPS

 

#include <WiFi.h>
#include <WiFiClientSecure.h>
 
const char* ssid = "yourSSID";
const char* password = "yourPassword";
 
const char* host = "script.google.com";
const int httpsPort = 443;
 
// Optional: root certificate for Google (you can skip this in testing)
const char* root_ca = \
"-----BEGIN CERTIFICATE-----\n" \
"...Google's root cert here...\n" \
"-----END CERTIFICATE-----\n";
 
void setup() {
    Serial.begin(115200);
    WiFi.begin(ssid, password);
    while (WiFi.status() != WL_CONNECTED) {
        delay(500);
        Serial.print(".");
    }
    Serial.println("Connected.");
 
    WiFiClientSecure client;
    client.setInsecure(); // or use: client.setCACert(root_ca);
 
    if (!client.connect(host, httpsPort)) {
        Serial.println("Connection failed");
        return;
    }
 
    String url = "/macros/s/your-script-id/exec?sheetName=Sheet1&row=5&col=1&value=FromESP32";
    client.print(String("GET ") + url + " HTTP/1.1\r\n" +
        "Host: " + host + "\r\n" +
        "Connection: close\r\n\r\n");
 
    while (client.connected()) {
        String line = client.readStringUntil('\n');
        Serial.println(line);
    }
}
 
void loop() {}

No comments:

Post a Comment

Using ESP32 for HTTPS

  #include   < WiFi.h > #include   < WiFiClientSecure.h > const   char *   ssid   =   " yourSSID " ; const   cha...