#include <WiFi.h>
#include <HTTPClient.h>
#include <ArduinoJson.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
const char* ssid = "YOUR_WIFI_SSID";
const char* password = "YOUR_WIFI_PASSWORD";
const char* serverName = "http://10.35.15.230:5000/candidates"; // Replace with your PC IP
LiquidCrystal_I2C lcd(0x27, 16, 2); // Use (0x27, 20, 4) if 20x4 LCD
void setup() {
Serial.begin(115200);
WiFi.begin(ssid, password);
lcd.begin();
lcd.backlight();
lcd.setCursor(0, 0);
lcd.print("Connecting...");
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
lcd.clear();
lcd.print("WiFi Connected");
delay(1000);
}
void loop() {
if (WiFi.status() == WL_CONNECTED) {
HTTPClient http;
http.begin(serverName);
int httpCode = http.GET();
if (httpCode == 200) {
String payload = http.getString();
Serial.println(payload);
DynamicJsonDocument doc(1024);
deserializeJson(doc, payload);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("1:");
lcd.print(doc[0].as<String>());
lcd.setCursor(0, 1);
lcd.print("2:");
lcd.print(doc[1].as<String>());
// Add logic to scroll through all candidates if more than 2
} else {
lcd.clear();
lcd.print("Error: ");
lcd.print(httpCode);
}
http.end();
}
delay(10000); // refresh every 10 seconds
}