#include <WiFi.h>
#include <HTTPClient.h>
#include <LiquidCrystal.h>
LiquidCrystal lcd(23, 22, 12, 14, 27, 26);
const char *ssid = "Wokwi-GUEST";
const char *password = "";
String url = "";
void setup()
{
Serial.begin(9600);
lcd.begin(16,2);
WiFi.begin(ssid, password);
pinMode(15, OUTPUT);
Serial.println("Estabelecendo Conexão...");
Serial.println("\n");
while(WiFi.status() != WL_CONNECTED)
{
delay(500);
}
Serial.println("Rede Conectada!");
Serial.println("\n");
}
void loop()
{
if (WiFi.status() == WL_CONNECTED)
{
digitalWrite(15, HIGH);
HTTPClient http;
http.begin(url);
int httpCode = http.GET();
if(httpCode == HTTP_CODE_OK)
{
String resposta = http.getString();
Serial.println(resposta);
Serial.println("\n");
char *ptr = strstr((const char *)resposta.c_str(), "body");
String dogfact = &ptr[7];
Serial.print(dogfact);
Serial.println("\n");
dogfact.replace('"', '\0');
Serial.print(dogfact);
Serial.println("\n");
lcd.clear();
lcd.setCursor(0,0);
lcd.print(dogfact.c_str());
}
}
else
{
digitalWrite(15, LOW);
WiFi.begin(ssid, password);
Serial.println("Reestabelecendo a conexão...");
Serial.println("\n");
while(WiFi.status() != WL_CONNECTED)
{
delay(500);
}
}
delay(5000);
}