// ESP32 OTA Demo + I2C LCD — Video Simulation
// LED: GPIO 5 (220 ohm) | LCD: SDA=21 SCL=22 VCC=VIN
// Hostname: bluegrays-ota.local
// Bilingual TR/EN display
#include <WiFi.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
const char* WIFI_SSID = "Wokwi-GUEST";
const char* WIFI_PASS = "";
const char* HOSTNAME = "bluegrays-ota";
#define LED_PIN 5
#define I2C_SDA 21
#define I2C_SCL 22
LiquidCrystal_I2C lcd(0x27, 16, 2);
String currentIP = "0.0.0.0";
void lcdLine(uint8_t row, const String &text) {
lcd.setCursor(0, row);
String t = text;
while (t.length() < 16) t += " ";
lcd.print(t.substring(0, 16));
}
void showScreen(const String &tr, const String &en) {
lcdLine(0, tr);
lcdLine(1, en);
}
// Idle ekran + LED heartbeat / Idle screen with heartbeat
void heartbeat(unsigned long durationMs) {
showScreen("OTA hazir", "Waiting upload");
unsigned long start = millis();
unsigned long lastBeat = 0;
while (millis() - start < durationMs) {
if (millis() - lastBeat > 2000) {
lastBeat = millis();
digitalWrite(LED_PIN, HIGH);
delay(50);
digitalWrite(LED_PIN, LOW);
}
delay(10);
}
}
// Sahte upload akisi / Fake upload sequence
void simulateUpload() {
// 1) Arduino IDE baglaniyor
showScreen("Arduino IDE", "Connecting...");
digitalWrite(LED_PIN, HIGH);
delay(1500);
// 2) Yetkilendirme
showScreen("Yetkilendirme", "Authenticating");
delay(1200);
// 3) OTA basladi
showScreen("OTA basladi!", "Upload started");
delay(1500);
// 4) Progress 0 → 100 (8 sn)
for (int pct = 0; pct <= 100; pct++) {
lcdLine(0, "Yukleme: %" + String(pct));
lcdLine(1, "Uploading: " + String(pct) + "%");
if (pct % 4 == 0) digitalWrite(LED_PIN, !digitalRead(LED_PIN));
delay(80);
}
// 5) Tamamlandi
digitalWrite(LED_PIN, HIGH);
showScreen("Tamamlandi!", "Upload complete");
delay(2000);
// 6) Reboot countdown (3 → 1)
for (int i = 3; i > 0; i--) {
showScreen("Yeniden baslat", "Reboot in " + String(i) + "s..");
delay(1000);
}
// 7) Yeniden basladi efekti — 3x hizli blink
digitalWrite(LED_PIN, LOW);
for (int j = 0; j < 3; j++) {
digitalWrite(LED_PIN, HIGH); delay(150);
digitalWrite(LED_PIN, LOW); delay(150);
}
// 8) Yeni firmware mesaji
showScreen("Yeni firmware!", "New firmware!");
delay(2500);
// 9) Versiyon goster
showScreen("Versiyon: v1.1", "Version: v1.1");
delay(2500);
}
void setup() {
pinMode(LED_PIN, OUTPUT);
digitalWrite(LED_PIN, LOW);
// LCD baslat
Wire.begin(I2C_SDA, I2C_SCL);
lcd.init();
lcd.backlight();
// Splash 3sn
showScreen(" BlueGrays", " OTA v1.0");
delay(3000);
// WiFi 20sn timeout
showScreen("WiFi baglaniyor", "Connecting WiFi");
WiFi.mode(WIFI_STA);
WiFi.begin(WIFI_SSID, WIFI_PASS);
unsigned long startWifi = millis();
while (WiFi.status() != WL_CONNECTED && millis() - startWifi < 20000) {
delay(400);
}
if (WiFi.status() == WL_CONNECTED) {
currentIP = WiFi.localIP().toString();
showScreen("WiFi baglandi", "WiFi connected");
delay(2000);
showScreen("IP adresi:", currentIP);
delay(2000);
showScreen("Hostname:", String(HOSTNAME) + ".lo");
delay(2500);
showScreen("Port: 3232", "OTA port: 3232");
delay(2000);
} else {
currentIP = "10.0.0.42";
showScreen("WiFi baglanmadi", "WiFi failed");
delay(2000);
showScreen("Offline modu", "Offline mode");
delay(2000);
}
}
void loop() {
// 5sn idle (heartbeat)
heartbeat(5000);
// Sahte upload akisi calistir
simulateUpload();
// Donguye gen don — idle yeniden
}