Skip to content
This repository was archived by the owner on May 24, 2022. It is now read-only.

Commit fdfb6a7

Browse files
committed
Switch to using modified weather client
Format files
1 parent 9fb8737 commit fdfb6a7

File tree

3 files changed

+30
-18
lines changed

3 files changed

+30
-18
lines changed

platformio.ini

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ framework = arduino
1515
monitor_speed = 115200
1616
lib_deps =
1717
https://github.com/mchestr/async-mqtt-client
18+
https://github.com/mchestr/esp8266-weather-station.git
1819
https://github.com/mchestr/homie-esp8266.git
1920
https://github.com/squix78/json-streaming-parser
2021
DallasTemperature
21-
ESP8266 Weather Station
2222
OneWire
2323
Mini Grafx
2424
simpleDSTadjust

src/main.cpp

+28-17
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ String moonAgeImage = "";
1919
uint32_t lastTemperatureSent = 0;
2020

2121
HomieNode temperatureNode("temperature", "temperature");
22-
HomieSetting<const char*> owApiKey("ow_api_key", "Open Weather API Key");
22+
HomieSetting<const char *> owApiKey("ow_api_key", "Open Weather API Key");
2323

2424
void initialize() {
2525
currentUpdate = true;
@@ -30,7 +30,8 @@ void initialize() {
3030
}
3131

3232
void temperatureLoop() {
33-
if (millis() - lastTemperatureSent >= TEMPERATURE_UPDATE * 1000 || lastTemperatureSent == 0) {
33+
if (millis() - lastTemperatureSent >= TEMPERATURE_UPDATE * 1000 ||
34+
lastTemperatureSent == 0) {
3435
sensors.requestTemperatures();
3536
insideTemp = sensors.getTempCByIndex(0);
3637
Homie.getLogger() << F("Temperature: ") << insideTemp << endl;
@@ -50,9 +51,15 @@ void setup() {
5051
gfx.fillBuffer(MINI_BLACK);
5152
gfx.commit();
5253

53-
updateCurrentTicker.attach(5 * 60 * 1000, []() {if (WiFi.status() == WL_CONNECTED) currentUpdate = true;});
54-
updateForecastTicker.attach(20 * 60 * 1000, []() {if (WiFi.status() == WL_CONNECTED) forecastUpdate = true;});
55-
updateAstronomyTicker.attach(60 * 60 * 1000, []() {if (WiFi.status() == WL_CONNECTED) astronomyUpdate = true;});
54+
updateCurrentTicker.attach(5 * 60 * 1000, []() {
55+
if (WiFi.status() == WL_CONNECTED) currentUpdate = true;
56+
});
57+
updateForecastTicker.attach(20 * 60 * 1000, []() {
58+
if (WiFi.status() == WL_CONNECTED) forecastUpdate = true;
59+
});
60+
updateAstronomyTicker.attach(60 * 60 * 1000, []() {
61+
if (WiFi.status() == WL_CONNECTED) astronomyUpdate = true;
62+
});
5663

5764
carousel.setFrames(frames, frameCount);
5865
carousel.disableAllIndicators();
@@ -62,7 +69,6 @@ void setup() {
6269
currentWeatherClient.setLanguage(OPEN_WEATHER_LANGUAGE);
6370
forecastClient.setMetric(IS_METRIC);
6471
forecastClient.setLanguage(OPEN_WEATHER_LANGUAGE);
65-
uint8_t allowedHours[] = {12, 0};
6672
forecastClient.setAllowedHours(allowedHours, sizeof(allowedHours));
6773

6874
Homie_setFirmware("weather-station", "0.0.1");
@@ -99,10 +105,10 @@ void onHomieEvent(const HomieEvent &event) {
99105
}
100106

101107
void loop() {
102-
// Handle OTA display first to ensure it is displaued before restarts
108+
// Handle OTA display first to ensure it is displayed before restarts
103109
switch (otaState) {
104110
case 1: // started
105-
if (!otaInitialDrawDone || otaProgress % 10 == 0) {
111+
if (!otaInitialDrawDone || otaProgress % 5 == 0) {
106112
drawProgress(otaProgress, F("Updating..."));
107113
otaInitialDrawDone = true;
108114
}
@@ -228,18 +234,22 @@ void drawCurrentWeather() {
228234

229235
gfx.setTransparentColor(MINI_BLACK);
230236
gfx.drawPalettedBitmapFromPgm(
231-
0, 55, getMeteoconIconFromProgmem(displayCurrent ? currentWeather.icon : "01n"));
237+
0, 55,
238+
getMeteoconIconFromProgmem(displayCurrent ? currentWeather.icon : "01n"));
232239

233240
gfx.setFont(ArialRoundedMTBold_14);
234241
gfx.setColor(MINI_BLUE);
235242
gfx.setTextAlignment(TEXT_ALIGN_RIGHT);
236-
gfx.drawString(220, 65, displayCurrent ? OPEN_WEATHER_DISPLAYED_CITY_NAME : "Inside");
243+
gfx.drawString(220, 65,
244+
displayCurrent ? OPEN_WEATHER_DISPLAYED_CITY_NAME : "Inside");
237245

238246
gfx.setFont(ArialRoundedMTBold_36);
239247
gfx.setColor(MINI_WHITE);
240248
gfx.setTextAlignment(TEXT_ALIGN_RIGHT);
241249

242-
gfx.drawString(220, 78, String(displayCurrent ? currentWeather.temp : insideTemp, 1) + (IS_METRIC ? "°C" : "°F"));
250+
gfx.drawString(220, 78,
251+
String(displayCurrent ? currentWeather.temp : insideTemp, 1) +
252+
(IS_METRIC ? "°C" : "°F"));
243253

244254
if (displayCurrent) {
245255
gfx.setFont(ArialRoundedMTBold_14);
@@ -351,17 +361,18 @@ void updateData() {
351361

352362
if (currentUpdate) {
353363
drawProgress(50, F("Updating conditions..."));
354-
currentWeatherClient.updateCurrentById(
364+
currentUpdate = !currentWeatherClient.updateCurrentById(
355365
&currentWeather, owApiKey.get(), OPEN_WEATHER_MAP_LOCATION_ID);
356-
currentUpdate = false;
366+
Homie.getLogger() << F("Current Forecast Successful? ")
367+
<< (currentUpdate ? F("False") : F("True")) << endl;
357368
}
358369

359370
if (forecastUpdate) {
360371
drawProgress(70, F("Updating forecasts..."));
361-
forecastClient.updateForecastsById(forecasts, owApiKey.get(),
362-
OPEN_WEATHER_MAP_LOCATION_ID,
363-
MAX_FORECASTS);
364-
forecastUpdate = false;
372+
forecastUpdate = !forecastClient.updateForecastsById(
373+
forecasts, owApiKey.get(), OPEN_WEATHER_MAP_LOCATION_ID, MAX_FORECASTS);
374+
Homie.getLogger() << F("Forcast Update Successful? ")
375+
<< (forecastUpdate ? F("False") : F("True")) << endl;
365376
}
366377

367378
if (astronomyUpdate) {

src/main.hpp

+1
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ OpenWeatherMapCurrent currentWeatherClient;
5050
OpenWeatherMapForecast forecastClient;
5151
Astronomy astronomy;
5252
Astronomy::MoonData moonData;
53+
uint8_t allowedHours[] = {12, 0};
5354

5455
OneWire oneWire(TEMP_PIN);
5556
DallasTemperature sensors(&oneWire);

0 commit comments

Comments
 (0)