|
@@ -16,6 +16,30 @@
|
|
|
// Generic ESP8266
|
|
|
// BUSY -> GPIO4, RST -> GPIO2, DC -> GPIO0, CS -> GPIO15, CLK -> GPIO14, DIN -> GPIO13, GND -> GND, 3.3V -> 3.3V
|
|
|
|
|
|
+/*
|
|
|
+ Power Settings
|
|
|
+
|
|
|
+ If your device is designed to be plugged in
|
|
|
+ set LOW_POWER_MODE to false
|
|
|
+
|
|
|
+ If your device is powered with battery and
|
|
|
+ GPIO16 / D0 is connected to RST with a resistor
|
|
|
+ (resistor value depends on development board)
|
|
|
+ set LOW_POWER_MODE to true
|
|
|
+
|
|
|
+ If yout are not sure, set it to false
|
|
|
+*/
|
|
|
+#define LOW_POWER_MODE true
|
|
|
+
|
|
|
+/*
|
|
|
+ Display refresh interval
|
|
|
+
|
|
|
+ Too frequent interval in low power mode might results getting ban by weather API / NTP servers
|
|
|
+*/
|
|
|
+#define REFRESH_INTERVAL 900e6 //900 seconds, aka 15 minutes
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
/* Display Libraries */
|
|
|
#include <GxEPD.h>
|
|
|
#include <GxGDEW075Z09/GxGDEW075Z09.h> // 7.5" b/w/r
|
|
@@ -41,20 +65,7 @@
|
|
|
#include <TaskScheduler.h>
|
|
|
|
|
|
|
|
|
-/*
|
|
|
- Power Settings
|
|
|
-
|
|
|
- If your device is designed to be plugged in
|
|
|
- set LOW_POWER_MODE to false
|
|
|
-
|
|
|
- If your device is powered with battery and
|
|
|
- GPIO16 / D0 is connected to RST with a resistor
|
|
|
- (resistor value depends on development board)
|
|
|
- set LOW_POWER_MODE to true
|
|
|
|
|
|
- If yout are not sure, set it to false
|
|
|
-*/
|
|
|
-#define LOW_POWER_MODE true
|
|
|
|
|
|
/* WiFi and Connections */
|
|
|
WiFiManager wifiManager;
|
|
@@ -69,6 +80,9 @@ GxEPD_Class display(io, /*RST=D4*/ 2, /*BUSY=D2*/ 4); // default selection of D4
|
|
|
const String weekDays[7] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};
|
|
|
const String weeksDaysFull[7] = { "SUNDAY", "MONDAY", "TUESDAY", "WEDNESDAY", "THURSDAY", "FRIDAY", "SATURDAY" };
|
|
|
const String months[12] = {"JANUARY", "FEBRUARY", "MARCH", "APRIL", "MAY", "JUNE", "JULY", "AUGUST", "SEPTEMBER", "OCTOBER", "NOVEMBER", "DECEMBER"};
|
|
|
+
|
|
|
+/* NTP Servers*/
|
|
|
+//Add more if you want to refresh more frequently in low power mode
|
|
|
const char* ntpServers[] = {
|
|
|
"0.debian.pool.ntp.org",
|
|
|
"1.debian.pool.ntp.org",
|
|
@@ -82,8 +96,16 @@ const char* ntpServers[] = {
|
|
|
"0.arch.pool.ntp.org",
|
|
|
"1.arch.pool.ntp.org",
|
|
|
"2.arch.pool.ntp.org",
|
|
|
- "3.arch.pool.ntp.org"
|
|
|
+ "3.arch.pool.ntp.org",
|
|
|
+ "time.google.com",
|
|
|
+ "time.cloudflare.com",
|
|
|
+ "time.windows.com",
|
|
|
+ "time.apple.com",
|
|
|
+ "time-a-wwv.nist.gov",
|
|
|
+ "time-b-wwv.nist.gov",
|
|
|
+ "time-c-wwv.nist.gov"
|
|
|
};
|
|
|
+const int ntpServerCounts = 20;
|
|
|
|
|
|
/* Global Variables */
|
|
|
const String deviceName = "InkyDash v1.0";
|
|
@@ -95,7 +117,7 @@ float minTemp = 0.0;
|
|
|
|
|
|
/* Schedulers */
|
|
|
void datetimeUpdateCallback();
|
|
|
-Task t_dt(1800000, TASK_FOREVER, &datetimeUpdateCallback); //Frame update
|
|
|
+Task t_dt(1800000, TASK_FOREVER, &datetimeUpdateCallback); //Frame update
|
|
|
Scheduler runner;
|
|
|
|
|
|
void setup() {
|
|
@@ -105,6 +127,9 @@ void setup() {
|
|
|
Serial.println("Starting up InkyDash");
|
|
|
display.init(115200);
|
|
|
|
|
|
+ //Set D0 to wakeup pin
|
|
|
+ pinMode(D0,WAKEUP_PULLUP);
|
|
|
+
|
|
|
//Draw starting frame
|
|
|
display.setRotation(3);
|
|
|
if (!LOW_POWER_MODE) {
|
|
@@ -114,21 +139,21 @@ void setup() {
|
|
|
|
|
|
// Connect to Wi-Fi
|
|
|
/*
|
|
|
- //Hard code version
|
|
|
- WiFi.begin("SSID", "password");
|
|
|
- while (WiFi.status() != WL_CONNECTED) {
|
|
|
+ //Hard code version
|
|
|
+ WiFi.begin("SSID", "password");
|
|
|
+ while (WiFi.status() != WL_CONNECTED) {
|
|
|
delay(500);
|
|
|
Serial.print('.');
|
|
|
- }
|
|
|
- Serial.println('\n');
|
|
|
- Serial.println("Connection established!");
|
|
|
- Serial.print("IP address:\t");
|
|
|
- Serial.println(WiFi.localIP());
|
|
|
+ }
|
|
|
+ Serial.println('\n');
|
|
|
+ Serial.println("Connection established!");
|
|
|
+ Serial.print("IP address:\t");
|
|
|
+ Serial.println(WiFi.localIP());
|
|
|
*/
|
|
|
-
|
|
|
+
|
|
|
wifiManager.setAPCallback(configModeCallback);
|
|
|
wifiManager.autoConnect("InkyDash");
|
|
|
-
|
|
|
+
|
|
|
if (WiFi.status() == WL_CONNECTED) {
|
|
|
Serial.println("WiFi Connected");
|
|
|
} else {
|
|
@@ -138,9 +163,9 @@ void setup() {
|
|
|
}
|
|
|
|
|
|
delay(1000);
|
|
|
-
|
|
|
- //Randomly get one of the NTP server from the list
|
|
|
- const char* randomNtpServer = getRandomNtpServer(ntpServers, 13);
|
|
|
+
|
|
|
+ //Randomly get one of the NTP server from the list and request time
|
|
|
+ const char* randomNtpServer = getRandomNtpServer(ntpServers);
|
|
|
Serial.println("Using NTP Server: " + String(randomNtpServer));
|
|
|
NTPClient timeClient(UDPconn, randomNtpServer);
|
|
|
ntpClient.begin();
|
|
@@ -153,8 +178,8 @@ void setup() {
|
|
|
//Render the calender page
|
|
|
display.drawPaged(drawHomeFrame);
|
|
|
Serial.println("Display updated. Entering deep sleep mode");
|
|
|
- ESP.deepSleep(1800e6);
|
|
|
- delay(10);
|
|
|
+ ESP.deepSleep(REFRESH_INTERVAL);
|
|
|
+ delay(100);
|
|
|
//After deep sleep mode, device will reset and not entering the loop() session
|
|
|
} else {
|
|
|
runner.init();
|