fix sunset/sunrise bug

This commit is contained in:
Geronius 2022-04-03 20:32:54 +02:00
parent a4e8b7217b
commit da3da6b505
3 changed files with 6 additions and 10 deletions

View File

@ -237,11 +237,11 @@ SensorData calcSunsetSunrise(GwApi *api, double time, double date, double latitu
int intminSS = 0;
bool sunDown = false;
// api->getLogger()->logDebug(GwLog::DEBUG,"... calcSun: Lat %f, Lon %f, at: %d, next SR: %d, next SS: %d", latitude, longitude, t, sunR, sunS);
if (!isnan(time) && !isnan(date) && !isnan(latitude) && !isnan(longitude) && !isnan(timezone)) {
// Calculate local time
t = (date * secPerYear) + (time + int(timezone * secPerHour));
// Calculate local epoch
t = (date * secPerYear) + time;
// api->getLogger()->logDebug(GwLog::DEBUG,"... calcSun: Lat %f, Lon %f, at: %d ", latitude, longitude, t);
sr.calculate(latitude, longitude, t); // LAT, LON, EPOCH
// Sunrise
if (sr.hasRise) {
@ -256,7 +256,7 @@ SensorData calcSunsetSunrise(GwApi *api, double time, double date, double latitu
intminSS = int((sunS - inthrSS * secPerHour)/60);
}
// Sun control (return value by sun on sky = false, sun down = true)
if ((t >= (sr.riseTime + int(timezone * secPerHour))) && (t <= (sr.setTime + int(timezone * secPerHour))))
if ((t >= sr.riseTime) && (t <= sr.setTime))
sunDown = false;
else sunDown = true;
}
@ -266,8 +266,6 @@ SensorData calcSunsetSunrise(GwApi *api, double time, double date, double latitu
returnset.sunriseHour = inthrSR;
returnset.sunriseMinute = intminSR;
returnset.sunDown = sunDown;
// api->getLogger()->logDebug(GwLog::DEBUG,"... calcSun: at t: %d, hasRise: %d, next SR: %d, hasSet: %d, next SS: %d\n", t, sr.hasRise, sr.riseTime, sr.hasSet, sr.setTime);
return returnset;
}

View File

@ -169,8 +169,6 @@ public:
sunset = String(commonData.data.sunsetHour) + ":" + String(commonData.data.sunsetMinute + 100).substring(1);
}
LOG_DEBUG(GwLog::LOG,"sunrise: .%s., sunset: .%s.", String(commonData.data.sunriseMinute + 100), String(commonData.data.sunsetMinute + 100));
display.setTextColor(textcolor);
display.setFont(&Ubuntu_Bold8pt7b);
display.setCursor(335, 250);

View File

@ -22,6 +22,6 @@ lib_deps =
build_flags=
-D BOARD_NODEMCU32S_OBP60
${env.build_flags}
upload_port = COM3
upload_port = COM6
upload_protocol = esptool
monitor_speed = 115200