mirror of https://github.com/sqfmi/Watchy.git
Allow the weather location to be set by the user
Update the 7_SEG example to show how it's donepull/62/head
parent
80c4444576
commit
841ef40467
|
@ -2,7 +2,11 @@
|
||||||
|
|
||||||
Watchy7SEG watchy;
|
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();
|
watchy.init();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -612,12 +612,19 @@ void Watchy::drawWatchFace(){
|
||||||
display.println(currentTime.Minute);
|
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(){
|
weatherData Watchy::getWeatherData(){
|
||||||
if(weatherIntervalCounter >= WEATHER_UPDATE_INTERVAL){ //only update if WEATHER_UPDATE_INTERVAL has elapsed i.e. 30 minutes
|
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
|
if(connectWiFi()){//Use Weather API for live data if WiFi is connected
|
||||||
HTTPClient http;
|
HTTPClient http;
|
||||||
http.setConnectTimeout(3000);//3 second max timeout
|
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());
|
http.begin(weatherQueryURL.c_str());
|
||||||
int httpResponseCode = http.GET();
|
int httpResponseCode = http.GET();
|
||||||
if(httpResponseCode == 200) {
|
if(httpResponseCode == 200) {
|
||||||
|
@ -634,7 +641,7 @@ weatherData Watchy::getWeatherData(){
|
||||||
btStop();
|
btStop();
|
||||||
}else{//No WiFi, use RTC Temperature
|
}else{//No WiFi, use RTC Temperature
|
||||||
uint8_t temperature = RTC.temperature() / 4; //celsius
|
uint8_t temperature = RTC.temperature() / 4; //celsius
|
||||||
if(strcmp(TEMP_UNIT, "imperial") == 0){
|
if(currentWeather.tempUnit.equals("imperial")){
|
||||||
temperature = temperature * 9. / 5. + 32.; //fahrenheit
|
temperature = temperature * 9. / 5. + 32.; //fahrenheit
|
||||||
}
|
}
|
||||||
currentWeather.temperature = temperature;
|
currentWeather.temperature = temperature;
|
||||||
|
@ -963,4 +970,4 @@ void Watchy::updateFWBegin(){
|
||||||
|
|
||||||
// time_t t = makeTime(tm);
|
// time_t t = makeTime(tm);
|
||||||
// return t + FUDGE; //add fudge factor to allow for compile time
|
// return t + FUDGE; //add fudge factor to allow for compile time
|
||||||
// }
|
// }
|
||||||
|
|
|
@ -17,6 +17,9 @@
|
||||||
typedef struct weatherData{
|
typedef struct weatherData{
|
||||||
int8_t temperature;
|
int8_t temperature;
|
||||||
int16_t weatherConditionCode;
|
int16_t weatherConditionCode;
|
||||||
|
String city = CITY_NAME;
|
||||||
|
String countryCode = COUNTRY_CODE;
|
||||||
|
String tempUnit = TEMP_UNIT;
|
||||||
}weatherData;
|
}weatherData;
|
||||||
|
|
||||||
class Watchy {
|
class Watchy {
|
||||||
|
@ -41,6 +44,7 @@ class Watchy {
|
||||||
void setTime();
|
void setTime();
|
||||||
void setupWifi();
|
void setupWifi();
|
||||||
bool connectWiFi();
|
bool connectWiFi();
|
||||||
|
void setWeatherLocation(String city, String country, String units);
|
||||||
weatherData getWeatherData();
|
weatherData getWeatherData();
|
||||||
void updateFWBegin();
|
void updateFWBegin();
|
||||||
|
|
||||||
|
@ -61,4 +65,4 @@ extern RTC_DATA_ATTR BMA423 sensor;
|
||||||
extern RTC_DATA_ATTR bool WIFI_CONFIGURED;
|
extern RTC_DATA_ATTR bool WIFI_CONFIGURED;
|
||||||
extern RTC_DATA_ATTR bool BLE_CONFIGURED;
|
extern RTC_DATA_ATTR bool BLE_CONFIGURED;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue