diff --git a/examples/WatchFaces/7_SEG/7_SEG.ino b/examples/WatchFaces/7_SEG/7_SEG.ino index 37c2e1d..1f1180b 100644 --- a/examples/WatchFaces/7_SEG/7_SEG.ino +++ b/examples/WatchFaces/7_SEG/7_SEG.ino @@ -2,7 +2,11 @@ Watchy7SEG watchy; -void setup(){ +void setup() { + // City names with spaces require a + + // temp units must be either metric or imperial + watchy.setWeatherLocation("New+York", "US", "metric"); + watchy.init(); } diff --git a/src/Watchy.cpp b/src/Watchy.cpp index 40bdfa0..d7ec8aa 100644 --- a/src/Watchy.cpp +++ b/src/Watchy.cpp @@ -612,12 +612,19 @@ void Watchy::drawWatchFace(){ display.println(currentTime.Minute); } +void Watchy::setWeatherLocation(String city, String countryCode, String tempUnit){ + currentWeather.city = city; + currentWeather.countryCode = countryCode; + currentWeather.tempUnit = tempUnit; +} + weatherData Watchy::getWeatherData(){ if(weatherIntervalCounter >= WEATHER_UPDATE_INTERVAL){ //only update if WEATHER_UPDATE_INTERVAL has elapsed i.e. 30 minutes if(connectWiFi()){//Use Weather API for live data if WiFi is connected HTTPClient http; http.setConnectTimeout(3000);//3 second max timeout - String weatherQueryURL = String(OPENWEATHERMAP_URL) + String(CITY_NAME) + String(",") + String(COUNTRY_CODE) + String("&units=") + String(TEMP_UNIT) + String("&appid=") + String(OPENWEATHERMAP_APIKEY); + String weatherQueryURL = String(OPENWEATHERMAP_URL) + String(currentWeather.city) + String(",") + String(currentWeather.countryCode) + + String("&units=") + String(currentWeather.tempUnit) + String("&appid=") + String(OPENWEATHERMAP_APIKEY); http.begin(weatherQueryURL.c_str()); int httpResponseCode = http.GET(); if(httpResponseCode == 200) { @@ -634,7 +641,7 @@ weatherData Watchy::getWeatherData(){ btStop(); }else{//No WiFi, use RTC Temperature uint8_t temperature = RTC.temperature() / 4; //celsius - if(strcmp(TEMP_UNIT, "imperial") == 0){ + if(currentWeather.tempUnit.equals("imperial")){ temperature = temperature * 9. / 5. + 32.; //fahrenheit } currentWeather.temperature = temperature; @@ -963,4 +970,4 @@ void Watchy::updateFWBegin(){ // time_t t = makeTime(tm); // return t + FUDGE; //add fudge factor to allow for compile time -// } \ No newline at end of file +// } diff --git a/src/Watchy.h b/src/Watchy.h index 887d58e..ca1565a 100644 --- a/src/Watchy.h +++ b/src/Watchy.h @@ -17,6 +17,9 @@ typedef struct weatherData{ int8_t temperature; int16_t weatherConditionCode; + String city = CITY_NAME; + String countryCode = COUNTRY_CODE; + String tempUnit = TEMP_UNIT; }weatherData; class Watchy { @@ -41,6 +44,7 @@ class Watchy { void setTime(); void setupWifi(); bool connectWiFi(); + void setWeatherLocation(String city, String country, String units); weatherData getWeatherData(); void updateFWBegin(); @@ -61,4 +65,4 @@ extern RTC_DATA_ATTR BMA423 sensor; extern RTC_DATA_ATTR bool WIFI_CONFIGURED; extern RTC_DATA_ATTR bool BLE_CONFIGURED; -#endif \ No newline at end of file +#endif