mirror of https://github.com/sqfmi/Watchy.git
Moved class members to RTC_DATA_ATTR to persist through deep sleep
parent
5f129ecb84
commit
95322d05e5
|
@ -11,6 +11,18 @@ RTC_DATA_ATTR bool BLE_CONFIGURED;
|
||||||
RTC_DATA_ATTR weatherData currentWeather;
|
RTC_DATA_ATTR weatherData currentWeather;
|
||||||
RTC_DATA_ATTR bool displayFullInit = true;
|
RTC_DATA_ATTR bool displayFullInit = true;
|
||||||
|
|
||||||
|
// Weather related variables. Explained in comment at setupWeather() below.
|
||||||
|
RTC_DATA_ATTR bool weatherCelsius = true;
|
||||||
|
RTC_DATA_ATTR uint32_t weatherCity = 5128581; // New York City, USA
|
||||||
|
RTC_DATA_ATTR String weatherLang = "en";
|
||||||
|
// Change this to use your own API key!
|
||||||
|
RTC_DATA_ATTR String weatherAPIKey = "f058fe1cad2afe8e2ddc5d063a64cecb";
|
||||||
|
|
||||||
|
// Initialise these both to the SAME value, so the weather will
|
||||||
|
// be fetched the first time getWeatherData() is called.
|
||||||
|
RTC_DATA_ATTR uint16_t weatherIntervalCounter = 30;
|
||||||
|
RTC_DATA_ATTR uint16_t weatherInterval = 30;
|
||||||
|
|
||||||
Watchy::Watchy(){} //constructor
|
Watchy::Watchy(){} //constructor
|
||||||
|
|
||||||
void Watchy::init(String datetime){
|
void Watchy::init(String datetime){
|
||||||
|
@ -76,7 +88,7 @@ void Watchy::setupWeather( uint32_t city,
|
||||||
weatherCelsius = celsius;
|
weatherCelsius = celsius;
|
||||||
weatherAPIKey = apikey;
|
weatherAPIKey = apikey;
|
||||||
weatherLang = lang;
|
weatherLang = lang;
|
||||||
weatherInit = true; // record the fact that we initialised
|
|
||||||
// indicates that weather needs to be fetched
|
// indicates that weather needs to be fetched
|
||||||
weatherIntervalCounter = weatherInterval;
|
weatherIntervalCounter = weatherInterval;
|
||||||
}
|
}
|
||||||
|
@ -595,15 +607,12 @@ void Watchy::drawWatchFace(){
|
||||||
//! return a weatherData structure with current weather, if available.
|
//! return a weatherData structure with current weather, if available.
|
||||||
/*!
|
/*!
|
||||||
uses weatherInterval, weatherAPIKey, weatherCity, and weatherCelsius
|
uses weatherInterval, weatherAPIKey, weatherCity, and weatherCelsius
|
||||||
|
|
||||||
|
If weather is not available by WiFi/internet, it reads the sensor's temperature
|
||||||
|
and sets the description to "Ambient".
|
||||||
*/
|
*/
|
||||||
weatherData Watchy::getWeatherData(){
|
weatherData Watchy::getWeatherData(){
|
||||||
String units = String("metric");
|
String units;
|
||||||
if( weatherInit == false ) {
|
|
||||||
// Change this to use your own API key!
|
|
||||||
String APIkey = String("f058fe1cad2afe8e2ddc5d063a64cecb");
|
|
||||||
// Initialise to defaults (NYC, metric, 30 minutes, SQFMI's API key)
|
|
||||||
setupWeather( 5128581, true, 30, String("en"), APIkey );
|
|
||||||
}
|
|
||||||
|
|
||||||
if(weatherIntervalCounter >= weatherInterval){ //only update if weatherInterval has elapsed i.e. 30 minutes
|
if(weatherIntervalCounter >= weatherInterval){ //only update if weatherInterval has elapsed i.e. 30 minutes
|
||||||
if(connectWiFi()){
|
if(connectWiFi()){
|
||||||
|
@ -613,6 +622,8 @@ weatherData Watchy::getWeatherData(){
|
||||||
|
|
||||||
if( weatherCelsius == false ) {
|
if( weatherCelsius == false ) {
|
||||||
units = String("imperial");
|
units = String("imperial");
|
||||||
|
} else {
|
||||||
|
units = String("metric");
|
||||||
}
|
}
|
||||||
String weatherQueryURL =
|
String weatherQueryURL =
|
||||||
String(OPENWEATHERMAP_URL) + String(weatherCity) +
|
String(OPENWEATHERMAP_URL) + String(weatherCity) +
|
||||||
|
|
Loading…
Reference in New Issue