38 lines
928 B
C++
38 lines
928 B
C++
#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
|