|
| 1 | +#pragma once |
| 2 | +#include "secrets.h" |
| 3 | +#include <ArduinoJson.h> //https://github.com/bblanchon/ArduinoJson |
| 4 | + |
| 5 | +typedef struct OpenWeatherMapCurrentData { |
| 6 | + // "lon": 8.54, |
| 7 | + float lon; |
| 8 | + // "lat": 47.37 |
| 9 | + float lat; |
| 10 | + // "id": 521, |
| 11 | + uint16_t weatherId; |
| 12 | + // "main": "Rain", |
| 13 | + String main; |
| 14 | + // "description": "shower rain", |
| 15 | + String description; |
| 16 | + // "icon": "09d" |
| 17 | + String icon; |
| 18 | + String iconMeteoCon; |
| 19 | + // "temp": 290.56, |
| 20 | + float temp; |
| 21 | + // "pressure": 1013, |
| 22 | + uint16_t pressure; |
| 23 | + // "humidity": 87, |
| 24 | + uint8_t humidity; |
| 25 | + // "temp_min": 289.15, |
| 26 | + float tempMin; |
| 27 | + // "temp_max": 292.15 |
| 28 | + float tempMax; |
| 29 | + // visibility: 10000, |
| 30 | + uint16_t visibility; |
| 31 | + // "wind": {"speed": 1.5}, |
| 32 | + float windSpeed; |
| 33 | + // "wind": {deg: 226.505}, |
| 34 | + float windDeg; |
| 35 | + // "clouds": {"all": 90}, |
| 36 | + uint8_t clouds; |
| 37 | + // "dt": 1527015000, |
| 38 | + time_t observationTime; |
| 39 | + // "country": "CH", |
| 40 | + String country; |
| 41 | + // "sunrise": 1526960448, |
| 42 | + time_t sunrise; |
| 43 | + // "sunset": 1527015901 |
| 44 | + time_t sunset; |
| 45 | + // "name": "Zurich", |
| 46 | + String cityName; |
| 47 | + time_t timezone; |
| 48 | +} OpenWeatherMapCurrentData; |
| 49 | + |
| 50 | +typedef struct OpenWeatherMapForecastData { |
| 51 | + // {"dt":1527066000, |
| 52 | + time_t observationTime; |
| 53 | + // "main":{ |
| 54 | + // "temp":17.35, |
| 55 | + float temp; |
| 56 | + // "temp_min":16.89, |
| 57 | + float tempMin; |
| 58 | + // "temp_max":17.35, |
| 59 | + float tempMax; |
| 60 | + // "pressure":970.8, |
| 61 | + float pressure; |
| 62 | + // "sea_level":1030.62, |
| 63 | + float pressureSeaLevel; |
| 64 | + // "grnd_level":970.8, |
| 65 | + float pressureGroundLevel; |
| 66 | + // "humidity":97, |
| 67 | + uint8_t humidity; |
| 68 | + // "temp_kf":0.46 |
| 69 | + // },"weather":[{ |
| 70 | + // "id":802, |
| 71 | + uint16_t weatherId; |
| 72 | + // "main":"Clouds", |
| 73 | + String main; |
| 74 | + // "description":"scattered clouds", |
| 75 | + String description; |
| 76 | + // "icon":"03d" |
| 77 | + String icon; |
| 78 | + String iconMeteoCon; |
| 79 | + // }],"clouds":{"all":44}, |
| 80 | + uint8_t clouds; |
| 81 | + // "wind":{ |
| 82 | + // "speed":1.77, |
| 83 | + float windSpeed; |
| 84 | + // "deg":207.501 |
| 85 | + float windDeg; |
| 86 | + // rain: {3h: 0.055}, |
| 87 | + float rain; |
| 88 | + // },"sys":{"pod":"d"} |
| 89 | + // dt_txt: "2018-05-23 09:00:00" |
| 90 | + String observationTimeText; |
| 91 | + |
| 92 | +} OpenWeatherMapForecastData; |
| 93 | + |
| 94 | +class AirliftOpenWeatherMap{ |
| 95 | + private: |
| 96 | + Stream *Serial; |
| 97 | + String currentKey; |
| 98 | + String currentParent; |
| 99 | + //OpenWeatherMapCurrentData *data; |
| 100 | + uint8_t weatherItemCounter = 0; |
| 101 | + bool metric = true; |
| 102 | + String language; |
| 103 | + String _error; |
| 104 | + |
| 105 | + public: |
| 106 | + AirliftOpenWeatherMap(Stream *serial){Serial = serial;}; |
| 107 | + String buildUrlCurrent(String appId, String locationParameter); |
| 108 | + String buildUrlForecast(String appId, String locationParameter); |
| 109 | + bool updateCurrent(OpenWeatherMapCurrentData &data,String json); |
| 110 | + bool updateForecast(OpenWeatherMapForecastData &data,String json, int day = 0); |
| 111 | + |
| 112 | + void setMetric(bool metric) {this->metric = metric;} |
| 113 | + bool isMetric() { return metric; } |
| 114 | + void setLanguage(String language) { this->language = language; } |
| 115 | + String getLanguage() { return language; } |
| 116 | + void setError(String error){_error = error;} |
| 117 | + String getError(){return _error;} |
| 118 | + |
| 119 | + String getMeteoconIcon(String icon); |
| 120 | + |
| 121 | +}; |
0 commit comments