Hi Folks,
I am kind of lost, so I need some help. The following code is part of my Home Thermostat using the Particle Photon, of course, this is not the whole
code, this part just tells me how long the heater has been ON or OFF.
The problem that I am having is with time.
This line is supposed to tell me how long the heater has been ON, the problem is that sometimes it tells me the correct time, like
4:23, this means 4 minutes and 23 seconds, most of the time, it says like 4:546785, 4 minutes and how many seconds?
Blynk.virtualWrite(V12, "Heater was ON for ", + String(heater_total_timeM), + String(":"), + String(heater_total_timeS), + String("\n"));
I am using Blynk, that’s why you see: Blynk.virtualWrite…
I am trying to avoid configuring an external RTC like the DS3231, so using the Particle built in RTC will simplify the hardware design.
The first screenshot last line shows my issues, the second screenshot last line is what I expect to see, in this case: 2 minutes and 7 seconds.
Thank you.
bool heater_now, heater_previous = 1;
unsigned long heater_OFFm, heater_OFFs, heater_ONm, heater_ONs, heater_total_timeM, heater_total_timeS, heater_counter;
void heater_ON_OFF()
{
heater_now = digitalRead(HEATING);
if (heater_now != heater_previous)
{
heater_previous = heater_now;
if (heater_now == HIGH)
{
heater_counter++; // Increment counter everytime the heating system is turned ON
Blynk.virtualWrite(V12, "clr");
Blynk.virtualWrite(V12,"=============== Heating ON =================\n");
Blynk.virtualWrite(V12, "On ", Time.format(Time.now(), "%m/%d/%y at %I:%M:%S %p \n")); // Cooling System turned ON\n")));
Blynk.virtualWrite(V12, "Heating System Turned ON, \n");
Blynk.virtualWrite(V12, ("Temperature was: ") + String(fTemp,2), "\n");
Blynk.virtualWrite(V12, "Today numbers of ON so far: ", heater_counter, "\n");
heater_ONm = Time.minute(); // Track how long the heater has been ON.
heater_ONs = Time.second();
Blynk.virtualWrite(V12, "\n"); // Insert a blank line.
//Blynk.virtualWrite(V3, (Time.format(Time.now(), "%m/%d/%y %I:%M:%S %p Heating System turned ON\n")));
}
if (heater_now == LOW)
{
heater_OFFm = Time.minute(); // Track how long the heater has been OFF
heater_OFFs = Time.second();
Blynk.virtualWrite(V12,"=============== Heater OFF ================\n");
Blynk.virtualWrite(V12, "On ", Time.format(Time.now(), "%m/%d/%y at %I:%M:%S %p \n"));
Blynk.virtualWrite(V12, "Heating System Turned OFF, \n");
Blynk.virtualWrite(V12, "Temperature was: " + String(fTemp,2), + "\n");
heater_total_timeM = heater_OFFm - heater_ONm;
heater_total_timeS = heater_OFFs - heater_ONs;
Blynk.virtualWrite(V12, "Heater was ON for ", + String(heater_total_timeM), + String(":"), + String(heater_total_timeS), + String("\n"));
heater_total_timeM = 0;
heater_total_timeS = 0;
}
}
}
! !