// WORK IN PROGRESS
// Learn about the ESP32 WiFi simulation in
// https://docs.wokwi.com/guides/esp32-wifi
#include <WiFi.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <TM1637.h>
#include "esp_sntp.h"
#include <MD_Parola.h>
#include <MD_MAX72xx.h>
#include <SPI.h>
LiquidCrystal_I2C LCD = LiquidCrystal_I2C(0x27, 16, 2);
const int CLK = 13; //Set the CLK pin connection to the display
const int DIO = 12; //Set the DIO pin connection to the display
TM1637 TM1;
// Replace with your network credentials
const char* ssid = "REPLACE_WITH_YOUR_SSID";
const char* password = "REPLACE_WITH_YOUR_PASSWORD";
#define NTP_SERVER "pool.ntp.org"
#define UTC_OFFSET 0
#define UTC_OFFSET_DST 0
int UpdateTime = 15;
boolean colon = 0;
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() {
struct tm timeinfo;
if (!getLocalTime(&timeinfo)) {
LCD.setCursor(0, 1);
LCD.println("Connection Err");
TM1.displayPChar("Err ");
Serial.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");
Serial.println(&timeinfo, "%H:%M:%S %d/%m/%Y %Z");
char timeHours[3];
strftime(timeHours,3, "%H", &timeinfo);
char timeMinutes[3];
strftime(timeMinutes,3, "%M", &timeinfo);
colon = 1 - colon;
TM1.displayTime(atoi(timeHours), atoi(timeMinutes), colon);
}
void setup() {
Serial.begin(115200);
TM1.begin(CLK, DIO, 4); //set up the 4-Digit Display.
TM1.displayPChar("init");
LCD.init();
LCD.backlight();
LCD.setCursor(0, 0);
LCD.print("Connecting to ");
LCD.setCursor(0, 1);
LCD.print("WiFi ");
TM1.displayPChar("WiFi");
WiFi.begin("Wokwi-GUEST", "", 6);
while (WiFi.status() != WL_CONNECTED) {
delay(250);
spinner();
}
Serial.println("");
Serial.println("WiFi connected");
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
TM1.displayPChar("Conn");
LCD.clear();
LCD.setCursor(0, 0);
LCD.println("Online");
LCD.setCursor(0, 1);
LCD.println("Updating time...");
TM1.displayPChar("UpdA");
configTime(UTC_OFFSET, UTC_OFFSET_DST, NTP_SERVER);
configTzTime("CET-1CEST-2,M3.5.0/02:00:00,M10.5.0/03:00:00", NTP_SERVER); // Local Time Zone : Paris, France
sntp_set_sync_interval(900000);
Serial.print("Sync time in ms : ");
Serial.println(sntp_get_sync_interval());
}
void loop() {
printLocalTime();
delay(500);
}