1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
|
#include <Arduino.h>
#include <Wire.h>
#include <Timezone.h> // https://github.com/JChristensen/Timezone
#include <TimeLib.h> // https://github.com/PaulStoffregen/Time
#include <DS1307RTC.h> // https://github.com/PaulStoffregen/DS1307RTC
#include <NTPClient.h> // https://github.com/arduino-libraries/NTPClient
#include <TM1637Display.h> // https://github.com/avishorp/TM1637
#include <WiFiManager.h>//https://github.com/tzapu/WiFiManager
#include <ESP8266WiFi.h>
#include <ESP8266WiFiMulti.h>
#include <WiFiUdp.h>
#include <ArduinoOTA.h>
// Central European Time (Frankfurt, Paris)
TimeChangeRule CEST = {"CEST", Last, Sun, Mar, 2, 120}; // Central European Summer Time
TimeChangeRule CET = {"CET ", Last, Sun, Oct, 3, 60}; // Central European Standard Time
Timezone CE(CEST, CET);
// NTP
WiFiUDP ntpUDP;
NTPClient timeClient(ntpUDP, "europe.pool.ntp.org", 0, 600000);
// timelib
time_t utc;
time_t local;
// display
//TM1637Display display(1, 3);
TM1637Display display(D8, D7); // pinClk, pinDIO
uint8_t data[] = { 0xff, 0xff, 0xff, 0xff };
uint8_t blank[] = { 0x00, 0x00, 0x00, 0x00 };
char buf[4];
char prev[4];
void setup() {
WiFi.mode(WIFI_STA);
WiFiManager wifiManager;
wifiManager.setTimeout(600);
if(!wifiManager.autoConnect("clock")) {
ESP.reset();
}
ArduinoOTA.begin();
ESP.wdtEnable(WDTO_8S);
// put your setup code here, to run once:
//Wire.begin(0,2); // 00-sda,02-sdl
Wire.begin(D2,D1);
timeClient.begin();
setSyncProvider(RTC.get);
display.clear();
}
void loop() {
ESP.wdtFeed();
ArduinoOTA.handle();
yield();
// put your main code here, to run repeatedly:
if(timeClient.update()) {
RTC.set(timeClient.getEpochTime());
}
yield();
utc = now();
local = CE.toLocal(utc);
yield();
sprintf(buf, "%.2d%.2d",hour(local), minute(local));
data[0] = display.encodeDigit(buf[0] - '0');
data[1] = display.encodeDigit(buf[1] - '0');
data[2] = display.encodeDigit(buf[2] - '0');
data[3] = display.encodeDigit(buf[3] - '0');
if(strcmp(buf, prev) != 0) {
display.setSegments(data);
strcpy(prev , buf);
}
yield();
}
|