//Include required libraries
//https://iotdesignpro.com/articles/esp32-data-logging-to-google-sheets-with-google-scripts
#include "WiFi.h"
#include <HTTPClient.h>
const char* ssid = "Wokwi-GUEST";
const char* password = "";
String GOOGLE_SCRIPT_ID = "AKfycbw2ZFaYjQKRFUGL7ZUG-iM0FknZGhsFDZsC122s5GYYhc9YhXmqnVtU6aUlfkiBIQg";
int inPin = 19;
void setup() {
pinMode(inPin, INPUT);
delay(1000);
Serial.begin(115200);
delay(1000);
// connect to WiFi
Serial.println();
Serial.print("Connecting to wifi: ");
Serial.println(ssid);
Serial.flush();
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
}
void loop() {
if (digitalRead(inPin)==HIGH){
if (WiFi.status() == WL_CONNECTED) {
//String func="givegift";
String func="getgift";
String row="3";
String col="4";
String name="Jomi";
String gift="";
String urlFinal = "http://api.pushingbox.com/pushingbox?devid=vBB11C6F4259F247&func=" + func + "&row=" + row+ "&col=" + col+ "&name=" + name+ "&gift=" + gift;
Serial.print("POST data to spreadsheet:");
Serial.println(urlFinal);
HTTPClient http;
http.begin(urlFinal.c_str());
http.setFollowRedirects(HTTPC_STRICT_FOLLOW_REDIRECTS);
int httpCode = http.GET();
Serial.print("HTTP Status Code: ");
Serial.println(httpCode);
//---------------------------------------------------------------------
//getting response from google sheet
String payload;
if (httpCode > 0) {
payload = http.getString();
Serial.println("Payload: "+payload);
}
//---------------------------------------------------------------------
http.end();
}
delay(1000);
}
}