|
|
|
@ -8,10 +8,12 @@
|
|
|
|
|
#include <WiFiUdp.h>
|
|
|
|
|
#include <NTPClient.h>
|
|
|
|
|
#include <Timezone.h>
|
|
|
|
|
#include <ArduinoJson.h>
|
|
|
|
|
|
|
|
|
|
#include "epd.h"
|
|
|
|
|
#include "credential.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Weather bits
|
|
|
|
|
|
|
|
|
|
// Australian BOM bits, Belconnen is mine.
|
|
|
|
@ -20,10 +22,13 @@
|
|
|
|
|
//const char* bom_url = "ftp://ftp.bom.gov.au/anon/gen/fwo/IDN11060.xml";
|
|
|
|
|
|
|
|
|
|
// openweathermap, api_key from credential.h
|
|
|
|
|
//
|
|
|
|
|
// Maybe try String types?
|
|
|
|
|
const String owm_url = "http://api.openweathermap.org/data/2.5/weather?q=Belconnen,AU&APPID=";
|
|
|
|
|
// const String owm_url = "http://api.openweathermap.org/data/2.5/weather?q=Belconnen,AU&units=metric&APPID=";
|
|
|
|
|
|
|
|
|
|
// DarkSky API key from credential.h
|
|
|
|
|
// substitute decimal latitude and longitude in ds_ll
|
|
|
|
|
const String ds_url = "http://pwarren.id.au/darksky/darksky.json";
|
|
|
|
|
|
|
|
|
|
bool ds_done = false;
|
|
|
|
|
|
|
|
|
|
// Timezone bits
|
|
|
|
|
|
|
|
|
@ -35,11 +40,10 @@ TimeChangeRule *tcr;
|
|
|
|
|
|
|
|
|
|
// Network clients
|
|
|
|
|
WiFiUDP ntpUDP;
|
|
|
|
|
|
|
|
|
|
HTTPClient http;
|
|
|
|
|
|
|
|
|
|
NTPClient timeClient(ntpUDP, "raspberrypi.lan", 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
|
|
|
|
|
|
|
|
|
|
// defined in "credentials.h"
|
|
|
|
|
const char* ssid = ssid_name; // The SSID (name) of your Wi-Fi network
|
|
|
|
@ -47,14 +51,14 @@ const char* password = ssid_pass; // The password of the Wi-Fi network
|
|
|
|
|
|
|
|
|
|
const int led = LED_BUILTIN;
|
|
|
|
|
|
|
|
|
|
// Font width
|
|
|
|
|
int dwidth = 185;
|
|
|
|
|
|
|
|
|
|
// yes this seems backwards but it works...
|
|
|
|
|
void ledOn(void) { digitalWrite(led, LOW);}
|
|
|
|
|
void ledOff(void) { digitalWrite(led, HIGH);}
|
|
|
|
|
void wait(void) { delay(1500);}
|
|
|
|
|
|
|
|
|
|
// Font width
|
|
|
|
|
int dwidth = 185;
|
|
|
|
|
|
|
|
|
|
void setup() {
|
|
|
|
|
pinMode(led, OUTPUT);
|
|
|
|
|
ledOff();
|
|
|
|
@ -78,7 +82,9 @@ void setup() {
|
|
|
|
|
timeClient.begin();
|
|
|
|
|
ntpUpdate();
|
|
|
|
|
epd_clear();
|
|
|
|
|
weatherUpdate();
|
|
|
|
|
printDateTime(1);
|
|
|
|
|
epd_update();
|
|
|
|
|
ledOff();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -104,8 +110,9 @@ void wifi() {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ntpUpdate() {
|
|
|
|
|
timeClient.update();
|
|
|
|
|
setTime(timeClient.getEpochTime());
|
|
|
|
|
if (timeClient.update()) {
|
|
|
|
|
setTime(timeClient.getEpochTime());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -151,12 +158,11 @@ void disp_digit(int digit, int xpos){
|
|
|
|
|
epd_disp_bitmap("9.JPG", dpos, ypos);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
delay(500);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void disp_time(int hours, int minutes) {
|
|
|
|
|
|
|
|
|
|
epd_clear();
|
|
|
|
|
|
|
|
|
|
// first digit of hours
|
|
|
|
|
if (hours > 19) {
|
|
|
|
|
disp_digit(2, 1);
|
|
|
|
@ -172,6 +178,7 @@ void disp_time(int hours, int minutes) {
|
|
|
|
|
disp_digit(hours, 2);
|
|
|
|
|
|
|
|
|
|
epd_disp_bitmap("COLO.JPG", 2 * dwidth, 0);
|
|
|
|
|
delay(500);
|
|
|
|
|
|
|
|
|
|
// first minutes digit
|
|
|
|
|
if (minutes > 49) {
|
|
|
|
@ -195,7 +202,7 @@ void disp_time(int hours, int minutes) {
|
|
|
|
|
|
|
|
|
|
// second minutes digit
|
|
|
|
|
disp_digit(minutes, 4);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -203,10 +210,9 @@ void printDateTime(int update_epd)
|
|
|
|
|
{
|
|
|
|
|
char buf[64];
|
|
|
|
|
|
|
|
|
|
time_t t;
|
|
|
|
|
|
|
|
|
|
time_t t;
|
|
|
|
|
t = ausET.toLocal(now(), &tcr);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
char m[4]; // temporary storage for month string (DateStrings.cpp uses shared buffer)
|
|
|
|
|
strcpy(m, monthShortStr(month(t)));
|
|
|
|
|
|
|
|
|
@ -215,6 +221,7 @@ void printDateTime(int update_epd)
|
|
|
|
|
|
|
|
|
|
if (update_epd > 0) {
|
|
|
|
|
disp_time(hour(t), minute(t));
|
|
|
|
|
wait();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sprintf(buf, "%s %.2d %s %d %s", dayShortStr(weekday(t)), day(t), m, year(t), &tcr -> abbrev);
|
|
|
|
@ -222,29 +229,77 @@ void printDateTime(int update_epd)
|
|
|
|
|
|
|
|
|
|
if (update_epd > 0) {
|
|
|
|
|
epd_set_en_font(ASCII64);
|
|
|
|
|
epd_disp_string(buf, 150, 290);
|
|
|
|
|
epd_update();
|
|
|
|
|
delay(1500);
|
|
|
|
|
epd_disp_string(buf, 150, 225);
|
|
|
|
|
delay(500);
|
|
|
|
|
Serial.println("Screen Updated");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void weatherUpdate(void) {
|
|
|
|
|
const size_t capacity = 4*JSON_OBJECT_SIZE(2) + JSON_OBJECT_SIZE(4) + 150;
|
|
|
|
|
DynamicJsonBuffer jsonBuffer(capacity);
|
|
|
|
|
|
|
|
|
|
http.begin(owm_url + api_key);
|
|
|
|
|
time_t t;
|
|
|
|
|
|
|
|
|
|
char buf[96] = {};
|
|
|
|
|
const char* nstr = "Now";
|
|
|
|
|
const char* tstr = "Today";
|
|
|
|
|
const char* tmstr = "Tomorrow";
|
|
|
|
|
|
|
|
|
|
http.begin(ds_url);
|
|
|
|
|
int httpCode = http.GET();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (httpCode > 0) {
|
|
|
|
|
JsonObject& root = jsonBuffer.parseObject(http.getString());
|
|
|
|
|
|
|
|
|
|
if (!root.success()) {
|
|
|
|
|
Serial.print(F("parseObject() failed: "));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
float current_temp = root["current"]["temp"];
|
|
|
|
|
const char* current_icon = root["current"]["icon"];
|
|
|
|
|
|
|
|
|
|
float today_max = root["today"]["max"];
|
|
|
|
|
const char* today_icon = root["today"]["icon"];
|
|
|
|
|
|
|
|
|
|
float tomorrow_max = root["tomorrow"]["max"];
|
|
|
|
|
const char* tomorrow_icon = root["tomorrow"]["icon"];
|
|
|
|
|
|
|
|
|
|
float day_after_max = root["day_after"]["max"];
|
|
|
|
|
const char* day_after_icon = root["day_after"]["icon"];
|
|
|
|
|
|
|
|
|
|
String payload = http.getString();
|
|
|
|
|
Serial.println(httpCode);
|
|
|
|
|
Serial.println(payload);
|
|
|
|
|
|
|
|
|
|
epd_set_en_font(ASCII64);
|
|
|
|
|
|
|
|
|
|
//Today
|
|
|
|
|
t = ausET.toLocal(now());
|
|
|
|
|
epd_disp_string(dayStr(weekday(t)), 0, 536);
|
|
|
|
|
delay(500);
|
|
|
|
|
(String(today_max, 1)).toCharArray(buf,64);
|
|
|
|
|
epd_disp_string(buf, 0, 472);
|
|
|
|
|
delay(500);
|
|
|
|
|
|
|
|
|
|
//Tomorrow
|
|
|
|
|
t = ausET.toLocal(now() + 86400, &tcr);
|
|
|
|
|
epd_disp_string(dayStr(weekday(t)), 267, 536);
|
|
|
|
|
delay(500);
|
|
|
|
|
(String(tomorrow_max, 1)).toCharArray(buf,64);
|
|
|
|
|
epd_disp_string(buf, 267, 472);
|
|
|
|
|
delay(500);
|
|
|
|
|
|
|
|
|
|
//Day after Tomorrow
|
|
|
|
|
t = ausET.toLocal(now() + 86400 + 86400);
|
|
|
|
|
epd_disp_string(dayStr(weekday(t)), 533, 536);
|
|
|
|
|
delay(500);
|
|
|
|
|
(String(day_after_max, 1)).toCharArray(buf,64);
|
|
|
|
|
epd_disp_string(buf, 533, 472);
|
|
|
|
|
delay(500);
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
Serial.print("Error on HTTP Request: ");
|
|
|
|
|
Serial.println(httpCode);
|
|
|
|
|
|
|
|
|
|
http.end();
|
|
|
|
|
}
|
|
|
|
|
http.end();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void loop() {
|
|
|
|
@ -257,20 +312,22 @@ void loop() {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ntpUpdate();
|
|
|
|
|
//weatherUpdate();
|
|
|
|
|
|
|
|
|
|
if (second(now()) >= 49) {
|
|
|
|
|
if (second(now()) >= 55) {
|
|
|
|
|
epd_wakeup();
|
|
|
|
|
while (second(now()) != 0) {
|
|
|
|
|
while (second(now()) != 57) {
|
|
|
|
|
delay(500);
|
|
|
|
|
}
|
|
|
|
|
epd_clear();
|
|
|
|
|
weatherUpdate();
|
|
|
|
|
printDateTime(1);
|
|
|
|
|
delay(4000);
|
|
|
|
|
epd_update();
|
|
|
|
|
delay(5000);
|
|
|
|
|
epd_enter_stopmode();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
sleep_seconds = 49 - second(now());
|
|
|
|
|
sleep_seconds = 55 - second(now());
|
|
|
|
|
Serial.print("Sleeping for: ");
|
|
|
|
|
Serial.println(sleep_seconds);
|
|
|
|
|
|
|
|
|
|