Skip to content

Commit

Permalink
commit
Browse files Browse the repository at this point in the history
  • Loading branch information
slacky1965 committed Sep 6, 2017
1 parent 02c47e6 commit 01bb880
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 17 deletions.
2 changes: 1 addition & 1 deletion watermeter/config.ino
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ void initDefConfig(_config *config) {
s.toCharArray(config->ntpServerName, s.length()+1);
config->timeZone = TIME_ZONE;
config->litersPerPulse = LITERS_PER_PULSE;
config->hotTime = config->coldTime = now();
config->hotTime = config->coldTime = localTimeT();
config->hotWater = config->coldWater = 0;

staConfigure = false;
Expand Down
28 changes: 20 additions & 8 deletions watermeter/time.ino
Original file line number Diff line number Diff line change
@@ -1,10 +1,23 @@
/* Get time_t without timezone */
time_t timeTwTZ() {
time_t t = now();
return t;
}

/* Get time_t with timezone */
time_t localTimeT() {
time_t t = timeTwTZ();
t += wmConfig.timeZone * SECS_PER_HOUR;
return t;
}

String localUptime() {
String s;
unsigned long milli;
if (firstNTP) {
milli = millis();
} else {
milli = (now() - timeStart)*1000;
milli = (timeTwTZ() - timeStart)*1000;
}

unsigned long secs = milli / 1000, mins = secs / 60;
Expand All @@ -27,12 +40,11 @@ String localUptime() {
}


String localTime()
{
// digital clock display of the time
String localTimeStr() {
time_t t = localTimeT();
String curTime = "";
curTime += strDigits(hour()) + ":" + strDigits(minute()) + ":" + strDigits(second());
curTime += " " + strDigits(day()) + "." + strDigits(month()) + "." + strDigits(year());
curTime += strDigits(hour(t)) + ":" + strDigits(minute(t)) + ":" + strDigits(second(t));
curTime += " " + strDigits(day(t)) + "." + strDigits(month(t)) + "." + strDigits(year(t));
return curTime;
}

Expand All @@ -58,7 +70,7 @@ void startNTP() {
setSyncInterval(SYNC_TIME);

if (DEBUG) {
Serial.printf("Local time: %s\n", localTime().c_str());
Serial.printf("Local time: %s\n", localTimeStr().c_str());
}
}

Expand Down Expand Up @@ -94,7 +106,7 @@ time_t getNtpTime()
secsSince1900 |= (unsigned long)packetBuffer[41] << 16;
secsSince1900 |= (unsigned long)packetBuffer[42] << 8;
secsSince1900 |= (unsigned long)packetBuffer[43];
return secsSince1900 - 2208988800UL + wmConfig.timeZone * SECS_PER_HOUR;
return secsSince1900 - 2208988800UL;
}
}
if (DEBUG) Serial.println("No NTP Response :-(");
Expand Down
6 changes: 3 additions & 3 deletions watermeter/watermeter.ino
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ void loop () {

/* If counter of hot water was added */
if (counterHotWater > 0) {
wmConfig.hotTime = now();
wmConfig.hotTime = localTimeT();
s = "";
s += wmConfig.hotTime;
wmConfig.hotWater += counterHotWater * wmConfig.litersPerPulse;
Expand All @@ -213,7 +213,7 @@ void loop () {

/* If counter of cold water was added */
if (counterColdWater > 0) {
wmConfig.coldTime = now();
wmConfig.coldTime = localTimeT();
s = "";
s += wmConfig.coldTime;
wmConfig.coldWater += counterColdWater * wmConfig.litersPerPulse;
Expand Down Expand Up @@ -276,7 +276,7 @@ void loop () {
}

if (firstNTP && responseNTP) {
timeStart = now();
timeStart = timeTwTZ();
firstNTP = false;
}

Expand Down
10 changes: 5 additions & 5 deletions watermeter/web.ino
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ String htmlLogo() {
s += "</p>\r\n";
s += "<p>" + returnVccStr() + ". " + returnRssiStr() + "</p>";
s += "<p>Local time: ";
s += localTime();
s += localTimeStr();
s += "</p>\r\n";
s += "</div>\r\n";
s += "</div>\r\n";
Expand Down Expand Up @@ -655,15 +655,15 @@ void parssingSettings() {
s = webServer.arg(i);
config.timeZone = s.toInt();
} else if (s == "hotw") {
config.hotTime = now();
config.hotTime = localTimeT();
s = webServer.arg(i);
config.hotWater = strtoul(s.c_str(), 0, 10);
config.hotTime = now();
config.hotTime = localTimeT();
} else if (s == "coldw") {
config.coldTime = now();
config.coldTime = localTimeT();
s = webServer.arg(i);
config.coldWater = strtoul(s.c_str(), 0, 10);
config.coldTime = now();
config.coldTime = localTimeT();
} else if (s == "countw") {
s = webServer.arg(i);
config.litersPerPulse = s.toInt();
Expand Down

0 comments on commit 01bb880

Please sign in to comment.