#include <WiFi.h>
#include <ArduinoHttpClient.h>
#include <LiquidCrystal_I2C.h>
char server[] = "script.google.com";
WiFiClient client;
HttpClient cliente = HttpClient(client, server, 80);
LiquidCrystal_I2C LCD = LiquidCrystal_I2C(0x27, 16, 2);
void spinner() {
static int8_t counter = 0;
const char* glyphs = "\xa1\xa5\xdb";
LCD.setCursor(15, 1);
LCD.print(glyphs[counter++]);
if (counter == strlen(glyphs)) {
counter = 0;
}
}
void setup() {
Serial.begin(115200);
while (!Serial) { }
LCD.init();
LCD.backlight();
LCD.clear();
WiFi.begin("Wokwi-GUEST", "");
LCD.setCursor(0, 0);
LCD.print("Conectando-se a ");
LCD.setCursor(0, 1);
LCD.print("Rede WiFi ");
while(WiFi.status() != WL_CONNECTED) {
delay(250);
spinner();
}
LCD.clear();
LCD.setCursor(0, 0);
LCD.print("Endereco IP: ");
LCD.setCursor(0, 1);
LCD.print(WiFi.localIP());
delay(1000);
}
void loop() {
LCD.setCursor(12, 1);
LCD.print("POST");
char payload[80];
sprintf(payload,"campo=100&campo2=200");
int contentLength = strlen(payload);
Serial.println("Requisicao: POST");
cliente.beginRequest();
cliente.post("/macros/s/AKfycbwPh8ItNENepueo5VozOpXc04C10o7OWuEfrRKZBqoLuFz1hnrb5YUlaYaEcjJ-j5p-Qw/exec");
cliente.sendHeader("Content-Type","application/x-www-form-urlencoded");
cliente.sendHeader("Content-Length",contentLength);
cliente.endRequest();
cliente.print(payload);
int statusCode = cliente.responseStatusCode();
String response = cliente.responseBody();
Serial.print("Status: ");
Serial.println(statusCode);
Serial.print("Retorno: ");
Serial.println(response);
Serial.println("");
delay(15000);
}