Adjust for BOM weather
This commit is contained in:
parent
738447212b
commit
589d99f723
2 changed files with 63 additions and 55 deletions
112
esp_time.ino
112
esp_time.ino
|
@ -24,9 +24,11 @@
|
|||
// 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 API key from credential.h
|
||||
// substitute decimal latitude and longitude in ds_ll
|
||||
const String ds_url = "http://pwarren.id.au/darksky/darksky.json";
|
||||
// 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";
|
||||
|
||||
bool ds_done = false;
|
||||
|
||||
|
@ -78,7 +80,6 @@ void setup() {
|
|||
Serial.println("\r\n\r\nSTARTING\r\n");
|
||||
|
||||
wifi();
|
||||
printDateTime(0);
|
||||
timeClient.begin();
|
||||
ntpUpdate();
|
||||
epd_clear();
|
||||
|
@ -158,7 +159,7 @@ void disp_digit(int digit, int xpos){
|
|||
epd_disp_bitmap("9.JPG", dpos, ypos);
|
||||
break;
|
||||
}
|
||||
delay(500);
|
||||
wait();
|
||||
}
|
||||
|
||||
void disp_time(int hours, int minutes) {
|
||||
|
@ -230,79 +231,76 @@ void printDateTime(int update_epd)
|
|||
if (update_epd > 0) {
|
||||
epd_set_en_font(ASCII64);
|
||||
epd_disp_string(buf, 150, 225);
|
||||
delay(500);
|
||||
Serial.println("Screen Updated");
|
||||
wait();
|
||||
}
|
||||
}
|
||||
|
||||
void weatherUpdate(void) {
|
||||
const size_t capacity = 4*JSON_OBJECT_SIZE(2) + JSON_OBJECT_SIZE(4) + 150;
|
||||
const size_t capacity = 4*JSON_OBJECT_SIZE(3) + 150;
|
||||
DynamicJsonBuffer jsonBuffer(capacity);
|
||||
|
||||
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"];
|
||||
http.end();
|
||||
|
||||
JsonObject& today = root["today"];
|
||||
const char* today_day = today["day"]; // "Wednesday"
|
||||
const char* today_icon = today["icon"]; // "sunny.jpg"
|
||||
const char* today_max = today["max"]; // "27"
|
||||
|
||||
JsonObject& tomorrow = root["tomorrow"];
|
||||
const char* tomorrow_day = tomorrow["day"]; // "Thursday"
|
||||
const char* tomorrow_icon = tomorrow["icon"]; // "sunny.jpg"
|
||||
const char* tomorrow_max = tomorrow["max"]; // "31"
|
||||
|
||||
JsonObject& day_after = root["day_after"];
|
||||
const char* day_after_day = day_after["day"]; // "Friday"
|
||||
const char* day_after_icon = day_after["icon"]; // "pcloud.jpg"
|
||||
const char* day_after_max = day_after["max"]; // "33"
|
||||
|
||||
Serial.println("Updating EPD");
|
||||
|
||||
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);
|
||||
epd_disp_string(today_day, 0, 536);
|
||||
wait();
|
||||
epd_disp_string(today_max, 20, 422);
|
||||
wait();
|
||||
epd_disp_bitmap(today_icon, 0, 318);
|
||||
wait();
|
||||
|
||||
//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);
|
||||
epd_disp_string(tomorrow_day, 267, 536);
|
||||
wait();
|
||||
epd_disp_string(tomorrow_max, 297, 422);
|
||||
wait();
|
||||
epd_disp_bitmap(tomorrow_icon, 267, 318);
|
||||
wait();
|
||||
|
||||
//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);
|
||||
|
||||
//Day After
|
||||
epd_disp_string(day_after_day, 533, 536);
|
||||
wait();
|
||||
epd_disp_string(day_after_max, 563, 422);
|
||||
wait();
|
||||
epd_disp_bitmap(day_after_icon, 533, 318);
|
||||
wait();
|
||||
|
||||
} else {
|
||||
Serial.print("Error on HTTP Request: ");
|
||||
Serial.println(httpCode);
|
||||
}
|
||||
http.end();
|
||||
|
||||
}
|
||||
|
||||
void loop() {
|
||||
int wakeup_seconds = 43;
|
||||
int sleep_seconds = 0;
|
||||
|
||||
Serial.println("Back from sleep!");
|
||||
|
@ -313,21 +311,25 @@ void loop() {
|
|||
|
||||
ntpUpdate();
|
||||
|
||||
if (second(now()) >= 55) {
|
||||
if (second(now()) >= wakeup_seconds) {
|
||||
epd_wakeup();
|
||||
while (second(now()) != 57) {
|
||||
delay(500);
|
||||
}
|
||||
epd_clear();
|
||||
weatherUpdate();
|
||||
Serial.print("Weather details sent: ");
|
||||
Serial.println(second(now()));
|
||||
|
||||
while (second(now()) != 0) {
|
||||
delay(500);
|
||||
}
|
||||
printDateTime(1);
|
||||
epd_update();
|
||||
delay(5000);
|
||||
delay(3000);
|
||||
epd_enter_stopmode();
|
||||
}
|
||||
|
||||
|
||||
sleep_seconds = 55 - second(now());
|
||||
sleep_seconds = wakeup_seconds - second(now());
|
||||
|
||||
Serial.print("Sleeping for: ");
|
||||
Serial.println(sleep_seconds);
|
||||
|
||||
|
|
|
@ -3,7 +3,9 @@
|
|||
from PIL import Image, ImageDraw, ImageFont
|
||||
|
||||
fnt = ImageFont.truetype('/Library/Fonts/FreeMono.ttf', 336)
|
||||
sfnt= ImageFont.truetype('/Library/Fonts/FreeMono.ttf', 168)
|
||||
|
||||
# Large numerals
|
||||
|
||||
for I in ("1", "2", "3", "4", "5", "6", "7", "8", "9", "0"):
|
||||
img = Image.new('RGB', (185, 224), color = (255, 255, 255))
|
||||
|
@ -11,6 +13,10 @@ for I in ("1", "2", "3", "4", "5", "6", "7", "8", "9", "0"):
|
|||
d.text((0,-60), I, font=fnt, fill=(0,0,0))
|
||||
img.save("%s.jpg" % (I))
|
||||
|
||||
imgs = Image.new("RGB", (92, 112), color = (255, 255, 255))
|
||||
d = ImageDraw.Draw(imgs)
|
||||
d.text((0,-30), I, font=sfnt, fill=(0,0,0))
|
||||
imgs.save(I+"s.jpg")
|
||||
|
||||
img = Image.new('RGB', (60,224), color = (255, 255, 255))
|
||||
d = ImageDraw.Draw(img)
|
Loading…
Reference in a new issue