Skip to content

Commit 56a9c24

Browse files
authored
Merge pull request #42 from count023/wunderground-url-scheme-change
Wunderground url scheme change
2 parents e417ae2 + 034a718 commit 56a9c24

File tree

4 files changed

+141
-0
lines changed

4 files changed

+141
-0
lines changed

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,8 @@
44
.DS_Store
55

66
examples/.DS_Store
7+
8+
.metadata
9+
.project
10+
RemoteSystemsTempFiles
11+

WundergroundClient.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,13 @@ void WundergroundClient::updateConditions(String apiKey, String language, String
3838
doUpdate("/api/" + apiKey + "/conditions/lang:" + language + "/q/" + country + "/" + city + ".json");
3939
}
4040

41+
// wunderground change the API URL scheme:
42+
// http://api.wunderground.com/api/<API-KEY>/conditions/lang:de/q/zmw:00000.215.10348.json
43+
void WundergroundClient::updateConditions(String apiKey, String language, String zmwCode) {
44+
isForecast = false;
45+
doUpdate("/api/" + apiKey + "/conditions/lang:" + language + "/q/zmw:" + zmwCode + ".json");
46+
}
47+
4148
void WundergroundClient::updateForecast(String apiKey, String language, String country, String city) {
4249
isForecast = true;
4350
doUpdate("/api/" + apiKey + "/forecast10day/lang:" + language + "/q/" + country + "/" + city + ".json");

WundergroundClient.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ class WundergroundClient: public JsonListener {
7171
public:
7272
WundergroundClient(boolean isMetric);
7373
void updateConditions(String apiKey, String language, String country, String city);
74+
void updateConditions(String apiKey, String language, String zmwCode);
7475
void updateForecast(String apiKey, String language, String country, String city);
7576
void updateAstronomy(String apiKey, String language, String country, String city);
7677
// JJG added
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
/**The MIT License (MIT)
2+
3+
Copyright (c) 2016 by Count023 -> https://github.com/count023
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.
22+
23+
*/
24+
25+
#include <Arduino.h>
26+
27+
#include <ESP8266WiFi.h>
28+
#include <JsonListener.h>
29+
#include "WundergroundClient.h"
30+
31+
/**
32+
* Wunderground Settings
33+
*/
34+
const String WUNDERGRROUND_API_KEY = "<YOUR-WUNDERGROUND-API-KEY>";
35+
const boolean IS_METRIC = true;
36+
// to retrieve the ZMW-Code use
37+
// http://api.wunderground.com/api/<API-KEY>/conditions/q/<COUNTRY-CODE>/<CITY-NAME>.json
38+
// for example and grab for the zmw ...
39+
const String WUNDERGROUND_ZMW_CODE = "00000.215.10348"; // Braunschweig-Flughafen -> EDVE
40+
const String WUNDERGRROUND_LANGUAGE = "DL";
41+
42+
// initiate the WundergoundClient
43+
WundergroundClient wunderground(IS_METRIC);
44+
45+
46+
/**
47+
* WiFi Settings
48+
*/
49+
const char* ESP_HOST_NAME = "esp-" + ESP.getFlashChipId();
50+
const char* WIFI_SSID = "<YOUR-WIFI-SSID>";
51+
const char* WIFI_PASSWORD = "<YOUR-WIFI-PASSWORD>";
52+
53+
// initiate the WifiClient
54+
WiFiClient wifiClient;
55+
56+
57+
58+
/**
59+
* Helping funtions
60+
*/
61+
void connectWifi() {
62+
WiFi.hostname(ESP_HOST_NAME);
63+
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
64+
delay(20);
65+
Serial.print("Connecting to ");
66+
Serial.println(WIFI_SSID);
67+
while (WiFi.status() != WL_CONNECTED) {
68+
delay(500);
69+
Serial.print(".");
70+
}
71+
Serial.println("");
72+
Serial.println("WiFi connected!");
73+
Serial.println();
74+
}
75+
76+
77+
/**
78+
* SETUP
79+
*/
80+
void setup() {
81+
82+
Serial.begin(115200);
83+
84+
connectWifi();
85+
86+
}
87+
88+
89+
/**
90+
* LOOP
91+
*/
92+
void loop() {
93+
94+
if ((millis() % (60 * 1000)) == 0) { // just call once a minute @see: https://www.wunderground.com/weather/api/d/pricing.html
95+
Serial.println();
96+
Serial.println("\n\nNext Loop-Step: " + String(millis()) + ":");
97+
98+
wunderground.updateConditions(WUNDERGRROUND_API_KEY, WUNDERGRROUND_LANGUAGE, WUNDERGROUND_ZMW_CODE);
99+
100+
Serial.println("wundergroundHours: " + wunderground.getHours());
101+
Serial.println("wundergroundMinutes: " + wunderground.getMinutes());
102+
Serial.println("wundergroundSeconds: " + wunderground.getSeconds());
103+
Serial.println("wundergroundDate: " + wunderground.getDate());
104+
105+
Serial.println("wundergroundMoonPctIlum: " + wunderground.getMoonPctIlum());
106+
Serial.println("wundergroundMoonAge: " + wunderground.getMoonAge());
107+
Serial.println("wundergroundMoonPhase: " + wunderground.getMoonPhase());
108+
Serial.println("wundergroundSunriseTime: " + wunderground.getSunriseTime());
109+
Serial.println("wundergroundSunsetTime: " + wunderground.getSunsetTime());
110+
Serial.println("wundergroundMoonriseTime: " + wunderground.getMoonriseTime());
111+
Serial.println("wundergroundMoonsetTime: " + wunderground.getMoonsetTime());
112+
Serial.println("wundergroundWindSpeed: " + wunderground.getWindSpeed());
113+
Serial.println("wundergroundWindDir: " + wunderground.getWindDir());
114+
115+
Serial.println("wundergroundCurrentTemp: " + wunderground.getCurrentTemp());
116+
Serial.println("wundergroundTodayIcon: " + wunderground.getTodayIcon());
117+
Serial.println("wundergroundTodayIconText: " + wunderground.getTodayIconText());
118+
Serial.println("wundergroundMeteoconIcon: " + wunderground.getMeteoconIcon(wunderground.getTodayIconText()));
119+
Serial.println("wundergroundWeatherText: " + wunderground.getWeatherText());
120+
Serial.println("wundergroundHumidity: " + wunderground.getHumidity());
121+
Serial.println("wundergroundPressure: " + wunderground.getPressure());
122+
Serial.println("wundergroundDewPoint: " + wunderground.getDewPoint());
123+
Serial.println("wundergroundPrecipitationToday: " + wunderground.getPrecipitationToday());
124+
125+
Serial.println();
126+
Serial.println("---------------------------------------------------/\n");
127+
}
128+
}

0 commit comments

Comments
 (0)