I'm attempting to post data directly to Google Sheets (GS) from a nodemcu. I have created a GS , script and deployed as a web app with no permission restriction. I can successfully post data to the GS using the url and Google Script ID from Firefox. The code has two defined values of temp and humidity and should post to the GS but continue to receive "esp8266/ardunio CI has failed" error and debugging indicates "BSSL: read: failed". I was originally using WiFiClientSecure library but switched to WiFiClientSecureBearSSL with no change. The code and serial out put are below. Any suggestions would be appreciated.
#include <ESP8266WiFi.h>
#include <WiFiClientSecureBearSSL.h>
//Define variables
float t;
float h;
//SSID and Password of WiFi router.
const char* ssid = "xxxx";
const char* password = "xxxxxx!";
//Host & httpsPort
const char* host = "script.google.com";
const int httpsPort = 443;
//--> Create a WiFiClientSecure object.
WiFiClientSecure client;
//--> spreadsheet script ID
String GAS_ID = "AKfyxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
void setup() {
Serial.begin(115200);
delay(500);
//Wake up wifi
WiFi.forceSleepWake();
delay(1000); //time to wake up wifi
//Connect to WiFi network
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, password);
//Wait for connection
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.print(".");
//If successfully connected to the wifi router, the IP Address is displayed in the serial monitor
Serial.println("");
Serial.print("Successfully connected to : ");
Serial.println(ssid);
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
Serial.println();
delay(1000);
client.setInsecure();
}
}
void loop() {
// Temperature and humidity readings
t = 23.45;
h = 12.34;
//Call the sendData Subroutine
sendData(t, h);
delay(30000);
}
// Subroutine for sending data to Google Sheets
void sendData(float t, float h) {
Serial.println("==========");
Serial.print("connecting to ");
Serial.println(host);
//Connect to Google host
if (!client.connect(host, httpsPort)) {
Serial.println("connection failed");
return;
}
//Processing data and sending data
String url = "/macros/s/" + GAS_ID + "/exec?value1=" + t + "&value2=" + h;
Serial.print("requesting URL: ");
Serial.println(url);
client.print(String("GET ") + url + " HTTP/1.1\r\n" +
"Host: " + host + "\r\n" +
"User-Agent: BuildFailureDetectorESP8266\r\n" +
"Connection: close\r\n\r\n");
Serial.println("request sent");
//Checking whether the data was sent successfully or not
while (client.connected()) {
String line = client.readStringUntil('\n');
if (line == "\r") {
Serial.println("headers received");
break;
}
}
String line = client.readStringUntil('\n');
if (line.startsWith("{\"state\":\"success\"")) {
Serial.println("esp8266/Arduino CI successfull!");
} else {
Serial.println("esp8266/Arduino CI has failed");
}
Serial.print("reply was : ");
Serial.println(line);
Serial.println("closing connection");
Serial.println("==========");
Serial.println();
}
serial output
-> ==========
-> connecting to script.google.com
-> requesting URL: /macros/s/AKfyxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/exec?value1=23.45&value2=12.34
-> request sent
-> BSSL:read:failed
-> BSSL:read:failed
-> BSSL:read:failed
-> headers received
-> esp8266/Arduino CI has failed
-> reply was : 24e
-> closing connection
-> ==========