src/main.cpp
// Update the internet based information and update screen
Update the internet based information and update screen
Update the internet based information and update screen
void updateData()
{
  time_t now = time(nullptr);
  gfx.fillBuffer(MINI_BLACK);
  gfx.setFont(ArialRoundedMTBold_14);
  drawProgress(50, "Updating conditions...");
  OpenWeatherMapCurrent *currentWeatherClient = new OpenWeatherMapCurrent();
  currentWeatherClient->setMetric(IS_METRIC);
  currentWeatherClient->setLanguage(OPEN_WEATHER_MAP_LANGUAGE);
  currentWeatherClient->updateCurrentById(&currentWeather, OPEN_WEATHER_MAP_API_KEY, OPEN_WEATHER_MAP_LOCATION_ID);
  delete currentWeatherClient;
  currentWeatherClient = nullptr;
  drawProgress(70, "Updating forecasts...");
  OpenWeatherMapForecast *forecastClient = new OpenWeatherMapForecast();
  forecastClient->setMetric(IS_METRIC);
  forecastClient->setLanguage(OPEN_WEATHER_MAP_LANGUAGE);
  uint8_t allowedHours[] = {12, 0};
  forecastClient->setAllowedHours(allowedHours, sizeof(allowedHours));
  forecastClient->updateForecastsById(forecasts, OPEN_WEATHER_MAP_API_KEY, OPEN_WEATHER_MAP_LOCATION_ID, MAX_FORECASTS);
  delete forecastClient;
  forecastClient = nullptr;
  drawProgress(80, "Updating astronomy...");
  Astronomy *astronomy = new Astronomy();
  moonData = astronomy->calculateMoonData(now);
  moonData.phase = astronomy->calculateMoonPhase(now);
  delete astronomy;
  astronomy = nullptr;
  Serial.printf("Free mem: %d\n", ESP.getFreeHeap());
  delay(1000);
}
void updateData ( ) { time_t now = time ( nullptr ) ; gfx . fillBuffer ( MINI_BLACK ) ; gfx . setFont ( ArialRoundedMTBold_14 ) ; drawProgress ( 50 , " " ) ; OpenWeatherMapCurrent * currentWeatherClient = new OpenWeatherMapCurrent ( ) ; currentWeatherClient -> setMetric ( IS_METRIC ) ; currentWeatherClient -> setLanguage ( OPEN_WEATHER_MAP_LANGUAGE ) ; currentWeatherClient -> updateCurrentById ( & currentWeather , OPEN_WEATHER_MAP_API_KEY , OPEN_WEATHER_MAP_LOCATION_ID ) ; delete currentWeatherClient ; currentWeatherClient = nullptr ; drawProgress ( 70 , " " ) ; OpenWeatherMapForecast * forecastClient = new OpenWeatherMapForecast ( ) ; forecastClient -> setMetric ( IS_METRIC ) ; forecastClient -> setLanguage ( OPEN_WEATHER_MAP_LANGUAGE ) ; uint8_t allowedHours [ ] = { 12 , 0 } ; forecastClient -> setAllowedHours ( allowedHours , sizeof ( allowedHours ) ) ; forecastClient -> updateForecastsById ( forecasts , OPEN_WEATHER_MAP_API_KEY , OPEN_WEATHER_MAP_LOCATION_ID , MAX_FORECASTS ) ; delete forecastClient ; forecastClient = nullptr ; drawProgress ( 80 , " " ) ; Astronomy * astronomy = new Astronomy ( ) ; moonData = astronomy -> calculateMoonData ( now ) ; moonData . phase = astronomy -> calculateMoonPhase ( now ) ; delete astronomy ; astronomy = nullptr ; Serial . printf ( " \n " , ESP . getFreeHeap ( ) ) ; delay ( 1000 ) ; }
Update the internet based information and update screen
Update the internet based information and update screen
// https://github.com/ThingPulse/esp8266-weather-station/issues/144 prevents using this //   // 'now' has to be UTC, lat/lng in degrees not raadians //   SunMoonCalc *smCalc = new SunMoonCalc(now - dstOffset, currentWeather.lat, currentWeather.lon); //   moonData = smCalc->calculateSunAndMoonData().moon; //   delete smCalc; //   smCalc = nullptr;