added weather forecast fetch from open-meteo
This commit is contained in:
+3
-1
@@ -5,6 +5,7 @@
|
||||
|
||||
#include "am2302_sensor.h"
|
||||
#include "internet_time.h"
|
||||
#include "weather_forecast.h"
|
||||
#include "wifi_connection.h"
|
||||
|
||||
void setInternetTimeInfo(InternetTimeInfo timeInfo);
|
||||
@@ -13,6 +14,7 @@ void drawHelloWorldScreen(U8G2 &u8g2);
|
||||
void drawInternetConnectionScreen(U8G2 &u8g2, WifiConnectionInfo wifiInfo);
|
||||
void setEnvironmentReading(Am2302Reading reading);
|
||||
void drawEnvironmentScreen(U8G2 &u8g2);
|
||||
void drawWeatherIconScreen(U8G2 &u8g2);
|
||||
void setWeatherForecastInfo(WeatherForecastInfo forecastInfo);
|
||||
void drawWeatherForecastScreen(U8G2 &u8g2);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
#ifndef WEATHER_FORECAST_H
|
||||
#define WEATHER_FORECAST_H
|
||||
|
||||
#include <Arduino.h>
|
||||
|
||||
struct WeatherForecastInfo
|
||||
{
|
||||
bool valid;
|
||||
float currentTemperatureC;
|
||||
float minTemperatureC;
|
||||
float maxTemperatureC;
|
||||
float precipitationMm;
|
||||
uint8_t precipitationProbabilityPercent;
|
||||
int weatherCode;
|
||||
};
|
||||
|
||||
class WeatherForecast
|
||||
{
|
||||
public:
|
||||
WeatherForecast();
|
||||
void update(unsigned long now, bool wifiConnected);
|
||||
WeatherForecastInfo info() const;
|
||||
bool consumeDirty();
|
||||
|
||||
private:
|
||||
void fetch(unsigned long now);
|
||||
bool readResponse(String &body);
|
||||
bool parseForecast(const String &body, WeatherForecastInfo &forecast) const;
|
||||
bool parseFloatArray(const String &body, const char *name, float *values, size_t maxCount, size_t &count) const;
|
||||
bool parseIntArray(const String &body, const char *name, int *values, size_t maxCount, size_t &count) const;
|
||||
|
||||
WeatherForecastInfo current_;
|
||||
unsigned long nextAttempt_;
|
||||
bool dirty_;
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -7,4 +7,8 @@ const char WIFI_PASSWORD[] = "your-wifi-password";
|
||||
// Offset from UTC in seconds. Examples: Finland winter 7200, Finland summer 10800.
|
||||
#define TIME_UTC_OFFSET_SECONDS 0
|
||||
|
||||
// Coordinates used for the weather forecast.
|
||||
#define WEATHER_LATITUDE 60.1699
|
||||
#define WEATHER_LONGITUDE 24.9384
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user