#include <LiquidCrystal.h>
#include<ArduinoJson.h>
#include<WiFi.h>
#include <HTTPClient.h>
const char* ssid = "Wokwi-GUEST";
const char* pass = "";
unsigned const long interval = 2000;
unsigned long zero = 0;
String name = "...";
String note = "...";
LiquidCrystal lcd(19, 23, 18, 17, 16, 15);
void setup(){
Serial.begin(115200);
WiFi.begin(ssid, pass);
while(WiFi.status() != WL_CONNECTED){
delay(100);
Serial.println(".");
}
Serial.println("WiFi Connected!");
Serial.println(WiFi.localIP());
lcd.begin(16, 2);
lcd.print("initializing");
}
void loop(){
if(millis()-zero > interval){
HTTPClient http;
http.begin("https://api.airtable.com/v0/appnyAhTwnrcviKMe/Table%201?api_key=keyPMGwKlx4THrjCm&fields%5B%5D=Name&fields%5B%5D=Notes");
int httpResponCode = http.GET();
Serial.println(httpResponCode);
if(httpResponCode > 0){
String payload = http.getString();
Serial.print(payload);
DynamicJsonDocument doc(1024);
deserializeJson(doc, payload);
const JsonArray& records = doc["records"].as<JsonArray>();
//Serial.println(doc["records"]);
String CreatedTime = "";
for(const auto& rec:records){
Serial.println(rec["fields"]["Name"].as<String>());
serializeJson(rec, Serial);
if(CreatedTime<rec["createdTime"]){
name = rec["fields"]["Name"].as<String>();
note = rec["fields"]["Notes"].as<String>();
}
}
}else{
Serial.print("error");
Serial.println(httpResponCode);
}
zero = millis();
}
lcd.begin(16, 2);
lcd.setCursor(0,0);
lcd.println(name);
lcd.setCursor(0,1);
lcd.print(note);
}