LeventeDaradici

Network Time Protocol-Internet Clock-Wemos D1 & 1602 LCD display

Jun 19th, 2021 (edited)
533
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.55 KB | None | 0 0
  1. #include "NTPClient.h"
  2. #include "ESP8266WiFi.h"
  3. #include "WiFiUdp.h"
  4. #include "Wire.h"
  5. #include "LiquidCrystal_I2C.h"
  6.  
  7. WiFiClient client;
  8.  
  9. WiFiClientSecure sclient;
  10. LiquidCrystal_I2C lcd(0x27,16,2);
  11.  
  12. const char *ssid = "Your WIFI SSID";
  13. const char *password = "Your WIFI Password";
  14. const long utcOffsetInSeconds = 10800;
  15. int a = 0;
  16. char daysOfTheWeek[7][12] = {"Dumin", "Luni", "Marti", "Mierc", "Joi", "Vineri", "Sambata"};
  17. //Month names
  18. String months[12]={"Ian", "Feb", "Mar", "Apr", "Mai", "Iun", "Iul", "Aug", "Sep", "Oct", "Nov", "Dec"};
  19.  
  20. WiFiUDP ntpUDP;
  21. NTPClient timeClient(ntpUDP, "pool.ntp.org", utcOffsetInSeconds);
  22.  
  23. void setup()
  24. {
  25.   lcd.init();
  26.   lcd.backlight();
  27.   Serial.begin(115200);
  28.   lcd.clear();
  29.   lcd.setCursor(2,0);
  30.   lcd.print("NETWORK CLOCK");
  31.   lcd.setCursor(0,1);
  32.   lcd.print("satelit-info.com");
  33.   delay(3000);
  34.   lcd.clear();
  35.   lcd.setCursor(1,0);
  36.   lcd.print("Conectare WIFI");
  37.   lcd.setCursor(0,1);
  38.   WiFi.begin(ssid, password);
  39.  
  40.   while ( WiFi.status() != WL_CONNECTED )
  41.         {
  42.           delay ( 1000 );
  43.           lcd.setCursor(a,1);
  44.           lcd.print(".");
  45.           a = a+1;
  46.         }
  47.   lcd.clear();
  48.   lcd.setCursor(0,0);
  49.   lcd.print("Conectat la");
  50.   lcd.setCursor(0,1);
  51.   lcd.print(ssid);
  52.   delay(2000);
  53.   timeClient.begin();
  54.   lcd.clear();
  55.   lcd.setCursor(0,0);
  56.   lcd.print("IP-ul meu: ");
  57.   lcd.setCursor(0,1);
  58.   lcd.println(WiFi.localIP());
  59.   delay(4000);
  60.   lcd.clear();
  61. }
  62.  
  63. void loop()
  64. {
  65.               timeClient.update();
  66.                   unsigned long epochTime = timeClient.getEpochTime();
  67.                   struct tm *ptm = gmtime ((time_t *)&epochTime);
  68.                   int monthDay = ptm->tm_mday;
  69.                   int currentMonth = ptm->tm_mon+1;
  70.                   int currentYear = ptm->tm_year+1900;
  71.                   String currentMonthName = months[currentMonth-1];
  72.               lcd.setCursor(0,1);
  73.               lcd.print(daysOfTheWeek[timeClient.getDay()]);
  74.               lcd.setCursor(8,1);
  75.               lcd.print(timeClient.getFormattedTime());    
  76.               lcd.setCursor(0,0);
  77.               lcd.print(monthDay);
  78.               lcd.setCursor(2,0);
  79.               lcd.print("-");
  80.               lcd.setCursor(3,0);
  81.               lcd.print(currentMonthName);
  82.               lcd.setCursor(6,0);
  83.               lcd.print("-");
  84.               lcd.setCursor(7,0);
  85.               lcd.print(currentYear);
  86.               delay(1000);
  87.               if (timeClient.getFormattedTime() == "00:00:01")
  88.                {
  89.                   lcd.clear();
  90.                }
  91.  
  92. }
Add Comment
Please, Sign In to add comment