Compare commits

...

2 Commits

2 changed files with 47 additions and 65 deletions

View File

@ -18,25 +18,26 @@ from weather_au import api
# break
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]
for data in rows:
if data[0] is not None:
bedroom_temp = int(data[0])
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]
for data in rows:
if data[0] is not None:
lounge_temp = data[0]
lounge_temp = int(data[0])
break
lounge_temp = 0
bom_icons = {
'sunny': 'SUNNY.JPG',
'clear': 'CLEAR.JPG',
'partly_cloudy': 'PCLOUD.JPG',
'mostly_sunny': 'PCLOUD.JPG',
'cloudy': 'CLOUDY.JPG',
'haze': 'HAZE.JPG',
'light_rain': 'LRAIN.JPG',
@ -61,19 +62,19 @@ wdays_dict = w.forecasts_daily()
new = {}
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
# 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
weather['today'] = wdays_dict[0]
weather['tomorrow'] = wdays_dict[2]
weather['day_after'] = wdays_dict[3]
else:
night = 0
weather['today'] = wdays_dict[1]
weather['tomorrow'] = wdays_dict[2]
weather['day_after'] = wdays_dict[3]
if night:
for day in weather.keys():

View File

@ -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,30 +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 {
Serial.print("Error on HTTP Request: ");
Serial.println(httpCode);
@ -337,7 +319,6 @@ void weatherUpdate(void) {
}
void loop() {
int wakeup_seconds = 38;
int sleep_seconds = 0;
Serial.println("Back from sleep!");
@ -349,21 +330,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());