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