-
Notifications
You must be signed in to change notification settings - Fork 0
/
ONE
122 lines (107 loc) · 4.72 KB
/
ONE
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
//Thanks to HeikkiHietala/ESP32-OLED-NTP-clock for original code.
//Included Canadian NTP pool. PSRAM Disabled
//Connected to NTP via wifi and shows date, day of week, and time (12hr) along with MAC address. Time zone info, UTC offset, AM/PM
//During log on it shows ssid and IP address. Hours + Minutes larger (24pt) Seconds smaller (10pt)font.
//Screen brightness, flip screen, Now shows your time zone info, will see if it knows when to change times
#include <WiFi.h>
#include "time.h"
#include <Wire.h>
#include "heltec.h"
// Replace with your network credentials
const char* ssid = "YOURSSID";
const char* password = "YOURSSIDPASSWORD";
const char* Timezone = "MST7MDT,M3.2.0,M11.1.0"; // YOUR TIMEZONE INFORMATION This example is Mountain Standard Time
void setup() {
Heltec.begin(true /*DisplayEnable Enable*/, false /*LoRa Enable*/, true /*Serial Enable*/);
Heltec.display->init();
Heltec.display->clear();
Heltec.display->flipScreenVertically();
Heltec.display->setBrightness(25); //0 is dim but visible, 255 is max bright
Heltec.display->setTextAlignment(TEXT_ALIGN_LEFT);
Heltec.display->setFont(ArialMT_Plain_10);
Heltec.display->drawString(2, 15, "Connecting to ssid: ");
Heltec.display->drawString(28, 30, ssid);
Heltec.display->display();
delay(100);
WiFi.begin(ssid, password);
delay(100);
while (WiFi.status() != WL_CONNECTED) {
delay(100);
}
// Display IP address
Heltec.display->clear();
Heltec.display->setBrightness(100); //0 is dim but visible, 255 is max bright
Heltec.display->setFont(ArialMT_Plain_10);
Heltec.display->drawString(2, 0, "< WiFi connected >");
Heltec.display->drawString(2, 15, "IP address: ");
Heltec.display->drawString(2, 30, WiFi.localIP().toString());
Heltec.display->drawString(2, 45, "ssid>");
Heltec.display->drawString(28, 45, ssid);
Serial.println(WiFi.localIP());
Heltec.display->display();
Heltec.display->clear();
delay(2000);
// Initialize NTPClient
configTime(0, 0, "0.ca.pool.ntp.org");
printLocalTime();
setenv("TZ", Timezone, 1);
delay(8000); // Wait for time services, displays UTC time for 8 sec then corrects to your TZ
WiFi.disconnect();
}
void loop() {
Heltec.display -> clear();
printLocalTime();
delay(100);
}
void printLocalTime() {
struct tm timeinfo;
if (!getLocalTime(&timeinfo)) {
Heltec.display->setFont(ArialMT_Plain_10);
Heltec.display->drawString(2, 25, "FAIL connect NTP Server");
Heltec.display->display();
Heltec.display->clear();
return;
}
//this routine makes the strings for the digital display
Serial.println(&timeinfo, "%d.%m.%Y %H:%M:%S");
char timeStringBuff[50];
char dateStringBuff[50];
char secStringBuff[4];
char minStringBuff[3];
char hourStringBuff[3];
char ampmStringBuff[3];
char tzStringBuff[4];
char offsetStringBuff[4];
strftime(timeStringBuff, sizeof(timeStringBuff), "%I:%M ", &timeinfo); // %I shows 12hr clock replace with %H for 24hr clock
strftime(dateStringBuff, sizeof(dateStringBuff), "#%j %a %b %d, %y", &timeinfo);
//[%a] shows short day of week | %b shows short month change to %m for month number | %j shows day of the year
strftime(secStringBuff, sizeof(secStringBuff), ":%S", &timeinfo);
strftime(minStringBuff, sizeof(minStringBuff), "%M", &timeinfo);
strftime(hourStringBuff, sizeof(hourStringBuff), "%H", &timeinfo);
strftime(ampmStringBuff, sizeof(ampmStringBuff), "%p", &timeinfo); // comment out line if you change to 24 hr clock (removes am/pm)
strftime(tzStringBuff, sizeof(tzStringBuff), "%Z", &timeinfo); // Shows time zone info if available
strftime(offsetStringBuff, sizeof(offsetStringBuff), "%z", &timeinfo); // Shows UTC time offset
String TimeAsString(timeStringBuff);
String DateAsString(dateStringBuff);
String SecAsString(secStringBuff);
String MinAsString(minStringBuff);
String HourAsString(hourStringBuff);
String AmpmAsString(ampmStringBuff);
String TzAsString(tzStringBuff);
String OffsetAsString(offsetStringBuff);
Heltec.display->clear();
Heltec.display->setBrightness(180); //0 is dim but visible, 255 is max bright
Heltec.display->setTextAlignment(TEXT_ALIGN_CENTER);
Heltec.display->setFont(ArialMT_Plain_24);
Heltec.display->drawString(64, 20, TimeAsString);
Heltec.display->setFont(ArialMT_Plain_10);
Heltec.display->drawString(64, 2, DateAsString);
Heltec.display->drawString(99, 21, SecAsString);
Heltec.display->drawString(99, 32, AmpmAsString);
Heltec.display->drawString(64, 53, WiFi.macAddress()); // mac address shown
Heltec.display->setTextAlignment(TEXT_ALIGN_LEFT);
Heltec.display->drawString(0, 17, TzAsString);
Heltec.display->drawString(2, 28, OffsetAsString);
Heltec.display->drawString(0, 39, "UTC");
Heltec.display->display();
}