Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "NTPClient.h"
- #include "ESP8266WiFi.h"
- #include "WiFiUdp.h"
- #include "Wire.h"
- #include "LiquidCrystal_I2C.h"
- WiFiClient client;
- WiFiClientSecure sclient;
- LiquidCrystal_I2C lcd(0x27,16,2);
- const char *ssid = "Your WIFI SSID";
- const char *password = "Your WIFI Password";
- const long utcOffsetInSeconds = 10800;
- int a = 0;
- char daysOfTheWeek[7][12] = {"Dumin", "Luni", "Marti", "Mierc", "Joi", "Vineri", "Sambata"};
- //Month names
- String months[12]={"Ian", "Feb", "Mar", "Apr", "Mai", "Iun", "Iul", "Aug", "Sep", "Oct", "Nov", "Dec"};
- WiFiUDP ntpUDP;
- NTPClient timeClient(ntpUDP, "pool.ntp.org", utcOffsetInSeconds);
- void setup()
- {
- lcd.init();
- lcd.backlight();
- Serial.begin(115200);
- lcd.clear();
- lcd.setCursor(2,0);
- lcd.print("NETWORK CLOCK");
- lcd.setCursor(0,1);
- lcd.print("satelit-info.com");
- delay(3000);
- lcd.clear();
- lcd.setCursor(1,0);
- lcd.print("Conectare WIFI");
- lcd.setCursor(0,1);
- WiFi.begin(ssid, password);
- while ( WiFi.status() != WL_CONNECTED )
- {
- delay ( 1000 );
- lcd.setCursor(a,1);
- lcd.print(".");
- a = a+1;
- }
- lcd.clear();
- lcd.setCursor(0,0);
- lcd.print("Conectat la");
- lcd.setCursor(0,1);
- lcd.print(ssid);
- delay(2000);
- timeClient.begin();
- lcd.clear();
- lcd.setCursor(0,0);
- lcd.print("IP-ul meu: ");
- lcd.setCursor(0,1);
- lcd.println(WiFi.localIP());
- delay(4000);
- lcd.clear();
- }
- void loop()
- {
- timeClient.update();
- unsigned long epochTime = timeClient.getEpochTime();
- struct tm *ptm = gmtime ((time_t *)&epochTime);
- int monthDay = ptm->tm_mday;
- int currentMonth = ptm->tm_mon+1;
- int currentYear = ptm->tm_year+1900;
- String currentMonthName = months[currentMonth-1];
- lcd.setCursor(0,1);
- lcd.print(daysOfTheWeek[timeClient.getDay()]);
- lcd.setCursor(8,1);
- lcd.print(timeClient.getFormattedTime());
- lcd.setCursor(0,0);
- lcd.print(monthDay);
- lcd.setCursor(2,0);
- lcd.print("-");
- lcd.setCursor(3,0);
- lcd.print(currentMonthName);
- lcd.setCursor(6,0);
- lcd.print("-");
- lcd.setCursor(7,0);
- lcd.print(currentYear);
- delay(1000);
- if (timeClient.getFormattedTime() == "00:00:01")
- {
- lcd.clear();
- }
- }
Add Comment
Please, Sign In to add comment