#include <WiFi.h>
#include <LiquidCrystal_I2C.h>
#include <HTTPClient.h>
#include <ArduinoJson.h>
LiquidCrystal_I2C LCD = LiquidCrystal_I2C(0x27, 20, 4);
String getText() {
HTTPClient http;
http.useHTTP10(true);
http.begin("https://encrypt.ga/esp32.php");//link
http.GET();
String result = http.getString();
Serial.println(result);
DynamicJsonDocument doc(2048);
DeserializationError error = deserializeJson(doc, result);
// Test if parsing succeeds.
if (error) {
Serial.print("deserializeJson() failed: ");
Serial.println(error.c_str());
return "<error>";
}
String header = doc["header"].as<String>();//text
String body = doc["body"].as<String>();
http.end();
return header + " " + body;//output text
}
void spinner() {//loading purposes. animated square
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);
delay(10);
LCD.init();
LCD.backlight();
LCD.setCursor(0, 0);
LCD.print("Connecting to ");
LCD.setCursor(0, 1);
LCD.print("WiFi ");
WiFi.begin("Wokwi-GUEST", "");//wifi SSID, password
while (WiFi.status() != WL_CONNECTED) {
delay(250);
spinner();
}
Serial.println("");
Serial.println("WiFi connected");
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
LCD.clear();
LCD.setCursor(0, 0);
LCD.println("Online");
LCD.setCursor(0, 2);
LCD.println("Getting text...");
}
void loop() {
String text = getText();
LCD.clear();
//output the text to LCD
for (int line = 0; line < 4; line++) {
LCD.setCursor(0, line);
LCD.print(text.substring(line * 20, (line + 1) * 20));
}
delay(4000);
}