// Learn about the ESP32 WiFi simulation in
// https://docs.wokwi.com/guides/esp32-wifi
#include <WiFi.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
int x=125;
LiquidCrystal_I2C LCD = LiquidCrystal_I2C(0x27, 16, 2);
struct tm timeinfo;
const char* ntpServer = "pool.ntp.org";
const long gmtOffset_sec =10800; // 60*60* (+3 GMT) =10800 Jordan TimeZone
const int daylightOffset_sec = 1; //no Daylight saving in Jordan Currently
void spinner() {
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 printLocalTime() {
if (!getLocalTime(&timeinfo)) {
LCD.setCursor(0, 1);
LCD.println("Connection Err");
return;
}
/*LCD.setCursor(8, 0);
LCD.println(&timeinfo, "%H:%M:%S");
LCD.setCursor(0, 1);
LCD.println(&timeinfo, "%d/%m/%Y %Z");*/
}
void setup() {
Serial.begin(115200);
LCD.init();
LCD.backlight();
LCD.clear();
LCD.setCursor(0, 0);
/* LCD.print("Connecting to ");
LCD.setCursor(0, 1);
LCD.print("WiFi ");
*/
WiFi.begin("Wokwi-GUEST", "", 6);
while (WiFi.status() != WL_CONNECTED) {
delay(250);
spinner();
}
LCD.clear();
LCD.print("Connecting to ");
LCD.setCursor(0, 1);
LCD.print(WiFi.SSID());
delay(500);
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, 1);
LCD.println("Updating time...");
configTime(gmtOffset_sec, daylightOffset_sec, ntpServer);
}
void loop() {
/* printLocalTime();
//LCD.clear();
LCD.setCursor(0, 0);
LCD.println(x);
LCD.setCursor(0, 1);
LCD.println("Drn");
LCD.setCursor(4, 0);
LCD.println("125");
LCD.setCursor(4, 1);
LCD.println("Fll");
LCD.setCursor(8 ,0);
LCD.println(&timeinfo, "%r");
LCD.setCursor(8, 1);
LCD.println(&timeinfo, "%p");
LCD.setCursor(11, 1);
LCD.println(&timeinfo, "%a");*/
//7,0 7,1
//8,0 8,1
/*
LCD.setCursor(8, 0);
LCD.println(&timeinfo, "%H:%M:%S");
LCD.setCursor(0, 1);
LCD.println(&timeinfo, "%d/%m/%Y %Z");
}*/
printLocalTime();
char w[]="1%";
LCD.clear();
int f=10;
f=f+'%';
//LEFT
LCD.setCursor(0, 0);
LCD.println(f);
LCD.setCursor(0, 1);
LCD.println("Drn");
//Right
LCD.setCursor(4, 0);
LCD.println(w);
LCD.setCursor(4, 1);
LCD.println("Fll");
//Time
LCD.setCursor(8 ,0);
LCD.println(&timeinfo, "%r");
LCD.setCursor(8, 1);
LCD.println(&timeinfo, "%p");
LCD.setCursor(11, 1);
LCD.println(&timeinfo, "%a");
// for(int i =0;i<100;i++){
//delay (500);
//}
delay(1000);
LCD.clear();
LCD.setCursor(4, 0);
LCD.println("Local IP");
LCD.setCursor(2,1);
//LCD.println(WiFi.localIP());
LCD.println("192.168.1.220");
delay (1000);
LCD.clear();
LCD.setCursor(2, 0);
LCD.println("MAC Address");
LCD.setCursor(0,1);
LCD.println(WiFi.BSSIDstr());
delay (1000);
}