mirror of https://github.com/sqfmi/Watchy.git
update weather interval
parent
1ae5fa2654
commit
55cb672cee
|
@ -95,6 +95,7 @@ void Watchy7SEG::drawBattery(){
|
|||
void Watchy7SEG::drawWeather(){
|
||||
|
||||
weatherData currentWeather = getWeatherData();
|
||||
|
||||
int8_t temperature = currentWeather.temperature;
|
||||
int16_t weatherConditionCode = currentWeather.weatherConditionCode;
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "Watchy",
|
||||
"version": "1.2.3",
|
||||
"version": "1.2.5",
|
||||
"description": "Watchy - An Open Source E-Paper Watch by SQFMI",
|
||||
"authors": [
|
||||
{
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
name=Watchy
|
||||
version=1.2.3
|
||||
version=1.2.5
|
||||
author=SQFMI
|
||||
maintainer=SQFMI
|
||||
sentence=Watchy - An Open Source E-Paper Watch by SQFMI
|
||||
|
|
|
@ -8,6 +8,8 @@ RTC_DATA_ATTR int menuIndex;
|
|||
RTC_DATA_ATTR BMA423 sensor;
|
||||
RTC_DATA_ATTR bool WIFI_CONFIGURED;
|
||||
RTC_DATA_ATTR bool BLE_CONFIGURED;
|
||||
RTC_DATA_ATTR weatherData currentWeather;
|
||||
RTC_DATA_ATTR int weatherIntervalCounter = WEATHER_UPDATE_INTERVAL;
|
||||
|
||||
String getValue(String data, char separator, int index)
|
||||
{
|
||||
|
@ -484,35 +486,37 @@ void Watchy::drawWatchFace(){
|
|||
}
|
||||
|
||||
weatherData Watchy::getWeatherData(){
|
||||
|
||||
weatherData currentWeather;
|
||||
|
||||
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);
|
||||
http.begin(weatherQueryURL.c_str());
|
||||
int httpResponseCode = http.GET();
|
||||
if(httpResponseCode == 200) {
|
||||
String payload = http.getString();
|
||||
JSONVar responseObject = JSON.parse(payload);
|
||||
currentWeather.temperature = int(responseObject["main"]["temp"]);
|
||||
currentWeather.weatherConditionCode = int(responseObject["weather"][0]["id"]);
|
||||
}else{
|
||||
//http error
|
||||
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);
|
||||
http.begin(weatherQueryURL.c_str());
|
||||
int httpResponseCode = http.GET();
|
||||
if(httpResponseCode == 200) {
|
||||
String payload = http.getString();
|
||||
JSONVar responseObject = JSON.parse(payload);
|
||||
currentWeather.temperature = int(responseObject["main"]["temp"]);
|
||||
currentWeather.weatherConditionCode = int(responseObject["weather"][0]["id"]);
|
||||
}else{
|
||||
//http error
|
||||
}
|
||||
http.end();
|
||||
//turn off radios
|
||||
WiFi.mode(WIFI_OFF);
|
||||
btStop();
|
||||
}else{//No WiFi, use RTC Temperature
|
||||
uint8_t temperature = RTC.temperature() / 4; //celsius
|
||||
if(strcmp(TEMP_UNIT, "imperial") == 0){
|
||||
temperature = temperature * 9. / 5. + 32.; //fahrenheit
|
||||
}
|
||||
currentWeather.temperature = temperature;
|
||||
currentWeather.weatherConditionCode = 800;
|
||||
}
|
||||
http.end();
|
||||
//turn off radios
|
||||
WiFi.mode(WIFI_OFF);
|
||||
btStop();
|
||||
}else{//No WiFi, use RTC Temperature
|
||||
uint8_t temperature = RTC.temperature() / 4; //celsius
|
||||
if(strcmp(TEMP_UNIT, "imperial") == 0){
|
||||
temperature = temperature * 9. / 5. + 32.; //fahrenheit
|
||||
}
|
||||
currentWeather.temperature = temperature;
|
||||
currentWeather.weatherConditionCode = 800;
|
||||
}
|
||||
weatherIntervalCounter = 0;
|
||||
}else{
|
||||
weatherIntervalCounter++;
|
||||
}
|
||||
return currentWeather;
|
||||
}
|
||||
|
||||
|
|
|
@ -33,6 +33,7 @@ class Watchy {
|
|||
|
||||
void handleButtonPress();
|
||||
void showMenu(byte menuIndex, bool partialRefresh);
|
||||
void showFastMenu(byte menuIndex);
|
||||
void showBattery();
|
||||
void showBuzz();
|
||||
void showAccelerometer();
|
||||
|
|
|
@ -30,6 +30,7 @@
|
|||
#define OPENWEATHERMAP_APIKEY "f058fe1cad2afe8e2ddc5d063a64cecb" //use your own API key :)
|
||||
#define OPENWEATHERMAP_URL "http://api.openweathermap.org/data/2.5/weather?q="
|
||||
#define TEMP_UNIT "metric" //use "imperial" for Fahrenheit"
|
||||
#define WEATHER_UPDATE_INTERVAL 30 //minutes
|
||||
//wifi
|
||||
#define WIFI_AP_TIMEOUT 60
|
||||
#define WIFI_AP_SSID "Watchy AP"
|
||||
|
|
Loading…
Reference in New Issue