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"
|
||||
|
||||
|
||||
// Weather bits
|
||||
|
||||
// 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
|
||||
// BOM, see bom_rrd2.py
|
||||
const String ds_url = "http://pwarren.id.au/darksky/bom.json";
|
||||
|
||||
bool ds_done = false;
|
||||
|
@ -48,10 +35,16 @@ TimeChangeRule aEST = {"AEST", First, Sun, Apr, 3, 600}; // UTC + 10 hours
|
|||
Timezone ausET(aEDT, aEST);
|
||||
TimeChangeRule *tcr;
|
||||
|
||||
|
||||
// when to wake up the display and get going
|
||||
int wakeup_seconds = 50;
|
||||
|
||||
|
||||
// Network clients
|
||||
WiFiClient wfclient;
|
||||
WiFiUDP ntpUDP;
|
||||
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
|
||||
|
||||
|
@ -96,10 +89,11 @@ void setup() {
|
|||
wifi();
|
||||
timeClient.begin();
|
||||
ntpUpdate();
|
||||
epd_clear();
|
||||
weatherUpdate();
|
||||
/* weatherUpdate();
|
||||
printDateTime(1);
|
||||
|
||||
epd_update();
|
||||
wait(); */
|
||||
ledOff();
|
||||
}
|
||||
|
||||
|
@ -173,7 +167,7 @@ void disp_digit(int digit, int xpos){
|
|||
epd_disp_bitmap("9.JPG", dpos, ypos);
|
||||
break;
|
||||
}
|
||||
wait();
|
||||
// wait();
|
||||
}
|
||||
|
||||
void disp_time(int hours, int minutes) {
|
||||
|
@ -226,17 +220,16 @@ void printDateTime(int update_epd)
|
|||
char buf[64];
|
||||
|
||||
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)
|
||||
strcpy(m, monthShortStr(month(t)));
|
||||
|
||||
strncpy(m, monthShortStr(month(t)), 4);
|
||||
sprintf(buf, "%.2d:%.2d:%.2d", hour(t), minute(t), second(t));
|
||||
Serial.print(buf); Serial.print(" ");
|
||||
|
||||
if (update_epd > 0) {
|
||||
Serial.println("Adding Time");
|
||||
disp_time(hour(t), minute(t));
|
||||
wait();
|
||||
}
|
||||
|
||||
sprintf(buf, "%s %.2d %s %d",
|
||||
|
@ -248,27 +241,17 @@ void printDateTime(int update_epd)
|
|||
Serial.println(buf);
|
||||
|
||||
if (update_epd > 0) {
|
||||
Serial.println("Adding Date");
|
||||
epd_set_en_font(ASCII64);
|
||||
epd_disp_string(buf, 5, 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();
|
||||
}
|
||||
epd_disp_string(buf, 50, 225);
|
||||
}
|
||||
}
|
||||
|
||||
void weatherUpdate(void) {
|
||||
char buf[64];
|
||||
const size_t capacity = 4*JSON_OBJECT_SIZE(3) + JSON_OBJECT_SIZE(4) + 150;
|
||||
DynamicJsonBuffer jsonBuffer(capacity);
|
||||
http.begin(ds_url);
|
||||
http.begin(wfclient, ds_url);
|
||||
int httpCode = http.GET();
|
||||
|
||||
if (httpCode > 0) {
|
||||
|
@ -305,28 +288,29 @@ void weatherUpdate(void) {
|
|||
|
||||
//Today
|
||||
epd_disp_bitmap(today_icon, 0, 290);
|
||||
wait();
|
||||
epd_disp_string(today_day, 0, 536);
|
||||
wait();
|
||||
epd_disp_string(today_max, 75, 460);
|
||||
wait();
|
||||
|
||||
|
||||
//Tomorrow
|
||||
epd_disp_bitmap(tomorrow_icon, 267, 290);
|
||||
wait();
|
||||
epd_disp_string(tomorrow_day, 260, 536);
|
||||
wait();
|
||||
epd_disp_string(tomorrow_max, 352, 460);
|
||||
wait();
|
||||
|
||||
//Day After
|
||||
epd_disp_bitmap(day_after_icon, 533, 290);
|
||||
wait();
|
||||
epd_disp_string(day_after_day, 533, 536);
|
||||
wait();
|
||||
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 {
|
||||
|
@ -337,7 +321,6 @@ void weatherUpdate(void) {
|
|||
}
|
||||
|
||||
void loop() {
|
||||
int wakeup_seconds = 38;
|
||||
int sleep_seconds = 0;
|
||||
|
||||
Serial.println("Back from sleep!");
|
||||
|
@ -349,21 +332,21 @@ void loop() {
|
|||
ntpUpdate();
|
||||
|
||||
if (second(now()) >= wakeup_seconds) {
|
||||
//epd_wakeup();
|
||||
epd_wakeup();
|
||||
epd_clear();
|
||||
weatherUpdate();
|
||||
Serial.print("Weather details sent: ");
|
||||
//weatherUpdate();
|
||||
//Serial.print("Weather details sent: ");
|
||||
Serial.println(second(now()));
|
||||
|
||||
printDateTime(1);
|
||||
|
||||
while (second(now()) != 0) {
|
||||
delay(500);
|
||||
}
|
||||
printDateTime(1);
|
||||
epd_update();
|
||||
delay(3000);
|
||||
//epd_enter_stopmode();
|
||||
|
||||
}
|
||||
|
||||
epd_update();
|
||||
delay(1500);
|
||||
epd_enter_stopmode();
|
||||
|
||||
sleep_seconds = wakeup_seconds - second(now());
|
||||
|
||||
|
|
Loading…
Reference in New Issue