Cleanups, Time and Date setting works reliably now
This commit is contained in:
parent
f025fd6ca1
commit
e657df2203
95
esp_time.ino
95
esp_time.ino
|
@ -22,20 +22,7 @@
|
||||||
#include "credential.h"
|
#include "credential.h"
|
||||||
|
|
||||||
|
|
||||||
// Weather bits
|
// BOM, see bom_rrd2.py
|
||||||
|
|
||||||
// Australian BOM bits, Belconnen is mine.
|
|
||||||
// see http://www.bom.gov.au/catalogue/data-feeds.shtml
|
|
||||||
//const char* aac = "NSW_PT254";
|
|
||||||
//const char* bom_url = "ftp://ftp.bom.gov.au/anon/gen/fwo/IDN11060.xml";
|
|
||||||
|
|
||||||
// openweathermap, api_key from credential.h
|
|
||||||
// const String owm_url = "http://api.openweathermap.org/data/2.5/weather?q=Belconnen,AU&units=metric&APPID=";
|
|
||||||
|
|
||||||
// DarkSky see darksky.py
|
|
||||||
//const String ds_url = "http://pwarren.id.au/darksky/darksy.json";
|
|
||||||
|
|
||||||
// BOM, see bom_xml.py
|
|
||||||
const String ds_url = "http://pwarren.id.au/darksky/bom.json";
|
const String ds_url = "http://pwarren.id.au/darksky/bom.json";
|
||||||
|
|
||||||
bool ds_done = false;
|
bool ds_done = false;
|
||||||
|
@ -48,10 +35,16 @@ TimeChangeRule aEST = {"AEST", First, Sun, Apr, 3, 600}; // UTC + 10 hours
|
||||||
Timezone ausET(aEDT, aEST);
|
Timezone ausET(aEDT, aEST);
|
||||||
TimeChangeRule *tcr;
|
TimeChangeRule *tcr;
|
||||||
|
|
||||||
|
|
||||||
|
// when to wake up the display and get going
|
||||||
|
int wakeup_seconds = 50;
|
||||||
|
|
||||||
|
|
||||||
// Network clients
|
// Network clients
|
||||||
|
WiFiClient wfclient;
|
||||||
WiFiUDP ntpUDP;
|
WiFiUDP ntpUDP;
|
||||||
HTTPClient http;
|
HTTPClient http;
|
||||||
NTPClient timeClient(ntpUDP, "pi2.lan", 9, 60000); //use internal ntp server, update every 10 minutes, taking in to account the 9 seconds it takes to update the screen for the current time
|
NTPClient timeClient(ntpUDP, "pi.lan", 0, 60000); //use internal ntp server, update every 10 minutes, taking in to account the 9 seconds it takes to update the screen for the current time
|
||||||
|
|
||||||
//NTPClient timeClient(ntpUDP, "au.pool.ntp.org", 0, 60000); //use internal ntp server, update every 10 minutes
|
//NTPClient timeClient(ntpUDP, "au.pool.ntp.org", 0, 60000); //use internal ntp server, update every 10 minutes
|
||||||
|
|
||||||
|
@ -96,10 +89,11 @@ void setup() {
|
||||||
wifi();
|
wifi();
|
||||||
timeClient.begin();
|
timeClient.begin();
|
||||||
ntpUpdate();
|
ntpUpdate();
|
||||||
epd_clear();
|
/* weatherUpdate();
|
||||||
weatherUpdate();
|
|
||||||
printDateTime(1);
|
printDateTime(1);
|
||||||
|
|
||||||
epd_update();
|
epd_update();
|
||||||
|
wait(); */
|
||||||
ledOff();
|
ledOff();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -173,7 +167,7 @@ void disp_digit(int digit, int xpos){
|
||||||
epd_disp_bitmap("9.JPG", dpos, ypos);
|
epd_disp_bitmap("9.JPG", dpos, ypos);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
wait();
|
// wait();
|
||||||
}
|
}
|
||||||
|
|
||||||
void disp_time(int hours, int minutes) {
|
void disp_time(int hours, int minutes) {
|
||||||
|
@ -226,17 +220,16 @@ void printDateTime(int update_epd)
|
||||||
char buf[64];
|
char buf[64];
|
||||||
|
|
||||||
time_t t;
|
time_t t;
|
||||||
t = ausET.toLocal(now(), &tcr);
|
t = ausET.toLocal(now()+60, &tcr);
|
||||||
|
|
||||||
char m[4]; // temporary storage for month string (DateStrings.cpp uses shared buffer)
|
char m[4]; // temporary storage for month string (DateStrings.cpp uses shared buffer)
|
||||||
strcpy(m, monthShortStr(month(t)));
|
strncpy(m, monthShortStr(month(t)), 4);
|
||||||
|
|
||||||
sprintf(buf, "%.2d:%.2d:%.2d", hour(t), minute(t), second(t));
|
sprintf(buf, "%.2d:%.2d:%.2d", hour(t), minute(t), second(t));
|
||||||
Serial.print(buf); Serial.print(" ");
|
Serial.print(buf); Serial.print(" ");
|
||||||
|
|
||||||
if (update_epd > 0) {
|
if (update_epd > 0) {
|
||||||
|
Serial.println("Adding Time");
|
||||||
disp_time(hour(t), minute(t));
|
disp_time(hour(t), minute(t));
|
||||||
wait();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sprintf(buf, "%s %.2d %s %d",
|
sprintf(buf, "%s %.2d %s %d",
|
||||||
|
@ -248,27 +241,17 @@ void printDateTime(int update_epd)
|
||||||
Serial.println(buf);
|
Serial.println(buf);
|
||||||
|
|
||||||
if (update_epd > 0) {
|
if (update_epd > 0) {
|
||||||
|
Serial.println("Adding Date");
|
||||||
epd_set_en_font(ASCII64);
|
epd_set_en_font(ASCII64);
|
||||||
epd_disp_string(buf, 5, 225);
|
epd_disp_string(buf, 50, 225);
|
||||||
wait();
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
sprintf(buf, "E: %s I: %s",
|
|
||||||
current_outside,
|
|
||||||
current_lounge);
|
|
||||||
Serial.println(buf);
|
|
||||||
|
|
||||||
if (update_epd > 0) {
|
|
||||||
epd_disp_string(buf, 500, 225);
|
|
||||||
wait();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void weatherUpdate(void) {
|
void weatherUpdate(void) {
|
||||||
|
char buf[64];
|
||||||
const size_t capacity = 4*JSON_OBJECT_SIZE(3) + JSON_OBJECT_SIZE(4) + 150;
|
const size_t capacity = 4*JSON_OBJECT_SIZE(3) + JSON_OBJECT_SIZE(4) + 150;
|
||||||
DynamicJsonBuffer jsonBuffer(capacity);
|
DynamicJsonBuffer jsonBuffer(capacity);
|
||||||
http.begin(ds_url);
|
http.begin(wfclient, ds_url);
|
||||||
int httpCode = http.GET();
|
int httpCode = http.GET();
|
||||||
|
|
||||||
if (httpCode > 0) {
|
if (httpCode > 0) {
|
||||||
|
@ -305,28 +288,29 @@ void weatherUpdate(void) {
|
||||||
|
|
||||||
//Today
|
//Today
|
||||||
epd_disp_bitmap(today_icon, 0, 290);
|
epd_disp_bitmap(today_icon, 0, 290);
|
||||||
wait();
|
|
||||||
epd_disp_string(today_day, 0, 536);
|
epd_disp_string(today_day, 0, 536);
|
||||||
wait();
|
|
||||||
epd_disp_string(today_max, 75, 460);
|
epd_disp_string(today_max, 75, 460);
|
||||||
wait();
|
|
||||||
|
|
||||||
|
|
||||||
//Tomorrow
|
//Tomorrow
|
||||||
epd_disp_bitmap(tomorrow_icon, 267, 290);
|
epd_disp_bitmap(tomorrow_icon, 267, 290);
|
||||||
wait();
|
|
||||||
epd_disp_string(tomorrow_day, 260, 536);
|
epd_disp_string(tomorrow_day, 260, 536);
|
||||||
wait();
|
|
||||||
epd_disp_string(tomorrow_max, 352, 460);
|
epd_disp_string(tomorrow_max, 352, 460);
|
||||||
wait();
|
|
||||||
|
|
||||||
//Day After
|
//Day After
|
||||||
epd_disp_bitmap(day_after_icon, 533, 290);
|
epd_disp_bitmap(day_after_icon, 533, 290);
|
||||||
wait();
|
|
||||||
epd_disp_string(day_after_day, 533, 536);
|
epd_disp_string(day_after_day, 533, 536);
|
||||||
wait();
|
|
||||||
epd_disp_string(day_after_max, 615, 460);
|
epd_disp_string(day_after_max, 615, 460);
|
||||||
wait();
|
|
||||||
|
|
||||||
|
Serial.println("Adding Temps");
|
||||||
|
sprintf(buf, "E: %s I: %s",
|
||||||
|
current_outside,
|
||||||
|
current_lounge);
|
||||||
|
Serial.println(buf);
|
||||||
|
|
||||||
|
epd_disp_string(buf, 500, 225);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
@ -337,7 +321,6 @@ void weatherUpdate(void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
int wakeup_seconds = 38;
|
|
||||||
int sleep_seconds = 0;
|
int sleep_seconds = 0;
|
||||||
|
|
||||||
Serial.println("Back from sleep!");
|
Serial.println("Back from sleep!");
|
||||||
|
@ -349,21 +332,21 @@ void loop() {
|
||||||
ntpUpdate();
|
ntpUpdate();
|
||||||
|
|
||||||
if (second(now()) >= wakeup_seconds) {
|
if (second(now()) >= wakeup_seconds) {
|
||||||
//epd_wakeup();
|
epd_wakeup();
|
||||||
epd_clear();
|
epd_clear();
|
||||||
weatherUpdate();
|
//weatherUpdate();
|
||||||
Serial.print("Weather details sent: ");
|
//Serial.print("Weather details sent: ");
|
||||||
Serial.println(second(now()));
|
Serial.println(second(now()));
|
||||||
|
printDateTime(1);
|
||||||
|
|
||||||
while (second(now()) != 0) {
|
while (second(now()) != 0) {
|
||||||
delay(500);
|
delay(500);
|
||||||
}
|
}
|
||||||
printDateTime(1);
|
|
||||||
epd_update();
|
|
||||||
delay(3000);
|
|
||||||
//epd_enter_stopmode();
|
|
||||||
}
|
}
|
||||||
|
epd_update();
|
||||||
|
delay(1500);
|
||||||
|
epd_enter_stopmode();
|
||||||
|
|
||||||
sleep_seconds = wakeup_seconds - second(now());
|
sleep_seconds = wakeup_seconds - second(now());
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue