Compare commits
2 Commits
f025fd6ca1
...
5966c6249e
Author | SHA1 | Date |
---|---|---|
Paul Warren | 5966c6249e | |
Paul Warren | e657df2203 |
19
bom_rrd2.py
19
bom_rrd2.py
|
@ -18,25 +18,26 @@ from weather_au import api
|
||||||
# break
|
# break
|
||||||
outside_temp = 0
|
outside_temp = 0
|
||||||
|
|
||||||
bedroom = rrdtool.fetch("/media/media/mqtt/ESP_4c7682/temp.rrd", "AVERAGE")
|
bedroom = rrdtool.fetch("/media/media/mqtt/ESP_b3fe20/temp.rrd", "AVERAGE")
|
||||||
rows = bedroom[2][::-1]
|
rows = bedroom[2][::-1]
|
||||||
for data in rows:
|
for data in rows:
|
||||||
if data[0] is not None:
|
if data[0] is not None:
|
||||||
bedroom_temp = int(data[0])
|
bedroom_temp = int(data[0])
|
||||||
break
|
break
|
||||||
|
bedroom_temp = 0
|
||||||
|
|
||||||
lounge = rrdtool.fetch("/media/media/mqtt/ESP_b3fe20/temp.rrd", "AVERAGE")
|
lounge = rrdtool.fetch("/media/media/mqtt/ESP_4c7682/temp.rrd", "AVERAGE")
|
||||||
rows = lounge[2][::-1]
|
rows = lounge[2][::-1]
|
||||||
for data in rows:
|
for data in rows:
|
||||||
if data[0] is not None:
|
if data[0] is not None:
|
||||||
lounge_temp = data[0]
|
lounge_temp = int(data[0])
|
||||||
break
|
break
|
||||||
lounge_temp = 0
|
|
||||||
|
|
||||||
bom_icons = {
|
bom_icons = {
|
||||||
'sunny': 'SUNNY.JPG',
|
'sunny': 'SUNNY.JPG',
|
||||||
'clear': 'CLEAR.JPG',
|
'clear': 'CLEAR.JPG',
|
||||||
'partly_cloudy': 'PCLOUD.JPG',
|
'partly_cloudy': 'PCLOUD.JPG',
|
||||||
|
'mostly_sunny': 'PCLOUD.JPG',
|
||||||
'cloudy': 'CLOUDY.JPG',
|
'cloudy': 'CLOUDY.JPG',
|
||||||
'haze': 'HAZE.JPG',
|
'haze': 'HAZE.JPG',
|
||||||
'light_rain': 'LRAIN.JPG',
|
'light_rain': 'LRAIN.JPG',
|
||||||
|
@ -61,19 +62,19 @@ wdays_dict = w.forecasts_daily()
|
||||||
new = {}
|
new = {}
|
||||||
weather = {}
|
weather = {}
|
||||||
|
|
||||||
weather['today'] = wdays_dict[0]
|
|
||||||
weather['tomorrow'] = wdays_dict[1]
|
|
||||||
weather['day_after'] = wdays_dict[2]
|
|
||||||
|
|
||||||
# The first forecast period doesn't always have the temperature and other bits
|
# The first forecast period doesn't always have the temperature and other bits
|
||||||
# I get the overnight low and forecast to substitute when this happens.
|
# I get the overnight low and forecast to substitute when this happens.
|
||||||
|
|
||||||
if weather['today']['temp_min'] is None:
|
if wdays_dict[0]['temp_min'] is None:
|
||||||
night = 1
|
night = 1
|
||||||
|
weather['today'] = wdays_dict[0]
|
||||||
weather['tomorrow'] = wdays_dict[2]
|
weather['tomorrow'] = wdays_dict[2]
|
||||||
weather['day_after'] = wdays_dict[3]
|
weather['day_after'] = wdays_dict[3]
|
||||||
else:
|
else:
|
||||||
night = 0
|
night = 0
|
||||||
|
weather['today'] = wdays_dict[1]
|
||||||
|
weather['tomorrow'] = wdays_dict[2]
|
||||||
|
weather['day_after'] = wdays_dict[3]
|
||||||
|
|
||||||
if night:
|
if night:
|
||||||
for day in weather.keys():
|
for day in weather.keys():
|
||||||
|
|
93
esp_time.ino
93
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,30 +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 {
|
||||||
Serial.print("Error on HTTP Request: ");
|
Serial.print("Error on HTTP Request: ");
|
||||||
Serial.println(httpCode);
|
Serial.println(httpCode);
|
||||||
|
@ -337,7 +319,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 +330,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