Annual Hour meter

I have a data logger that tracks when my oil burner starts (based on amp draw).
I data log the time it starts and the time it stops.

what I am after is an odometer of sorts.
in my mind I never heat after April and never before September.

what has me baffled is how to create a non-destructible run-time hour meter.

I was thinking of using eprom to save the daily hour run time, and then re-set the daily run time clock.
I have an SD card and RTC for the rest of the data logging, but I am hoping to have an hour meter that cannot be removed .

I was also thinking about power failure. maybe use a battery backup and when there is a power failure, log all the system parameters at that time, ditto the power restore time. After Hurricane Sandy, we lost power for a couple weeks.

looking for suggestions on this part of the project.

So your question is "How do I keep my Arduino running for a few weeks in the event of a power outage?" For that it would be helpful to know how much power the Arduino is consuming. Do you have a milliamp meter?

johnwasser:
So your question is "How do I keep my Arduino running for a few weeks in the event of a power outage?" For that it would be helpful to know how much power the Arduino is consuming. Do you have a milliamp meter?

actually, my question is how is the best way to keep a running log that will pick up were it left off after a power failure, a re-boot, an SD card failure or swap...
I am thinking along the lines of :
create a log file in eeprom
each night at midnight, write the days events.
in the event of a power failure or data loss or whatever, read the eeprom and add to the total yearly count of run-time hours.
currently I read the the RTC, read the inputs, write to the SD card.

changing the SD card means a re-set and all the data is re-set to zero.
that is what I am trying to avoid.

johnwasser:
So your question is "How do I keep my Arduino running for a few weeks in the event of a power outage?" For that it would be helpful to know how much power the Arduino is consuming. Do you have a milliamp meter?

currently using a couple temperature sensors. LM34 and a CT for amps.
I am trying to monitor how the OA temp affects the run time and such.
my house of a dinosaur and is cold too often.
in the spring and fall, we keep the temp at about 67
in the dead of winter, he furnace runs so often that the house gets really hot so we have to turn the thermostat down 5 degrees or more just to keep the house normal.

The EEPROM has a limited number of write cycles. Writing the running log once per second could wear it out in less than a year. But an SD card has a wear leveling algorithm so you can write your running log as a separate file on the SD instead.

MorganS:
The EEPROM has a limited number of write cycles. Writing the running log once per second could wear it out in less than a year. But an SD card has a wear leveling algorithm so you can write your running log as a separate file on the SD instead.

that is why I want to write to it once per day, preferably at noon or midnight.
100,000 days... well within MTBF.

Then I don't understand the original question. How often do you write to the SD card? Why can't you put the data there?

MorganS:
Then I don't understand the original question. How often do you write to the SD card? Why can't you put the data there?

I watch the amps on the heater/oil burner
when the oil burner starts, it draws about 2.5 amps.
since there was a change, I log this time on the SD card
once the firebox is hot, the fan turns on, the amps jump to about 6
I log this time
when the oil burner shuts off and the fan is running, the amps do to about 3.5
I log this time.
when the fan shuts off, the amps drop to 0
I log this time.
so, I get about 4-8 writes to the SD card on each heating cycle.
the oil burner can come on and off and the fan can come on and off.
when the oil burner is running, I time the run time.
at midnight, I want to log the total oil burner run time for the day.
this is the new part and hence the reason I am looking for guidance.

the next phase of the project is to add an 8 led indicator
assuming I re-set when I get an oil delivery, the odometer is noted for that time.
then as the oil burner runs, it uses oil. after 10 hours, the LED will drop after, 20 drop again.
at some point, I will know the tank is getting low and needs to be filled.

this is totally non-invasive and can be used on underground oil tanks. that is the reason I was not going for the actual level measurement.

I am looking at the car backup sensors as a 1 horn/receiver that may be oil resistant. but that is not this project.

dave-in-nj:
changing the SD card means a re-set and all the data is re-set to zero. that is what I am trying to avoid.

How about using two SD card readers. Use one and when you need to change a card, send an instruction to the board to start using the other one. You can then swap the disconnected card without resetting.

You know you can open more than one file on an SD card? Just you can't have two open at the same time. So at midnight,tally up the data for the main file, close it and save an entry to the daily file.

You should be closing the file every time you finish writing anyway. Pulling the SD card out while the Arduino is holding a file open is going to cause errors on the card. Since you are logging discrete events, the total time that the file is held open should only be a few milliseconds per day. Just put in a little test to ensure that there is a card present before you write to it.

Do you want to record things like "the oil burner turned on at 10:30 and off at 10:50"?
Or is it enough to record "the oil burner was on for 20 minutes"?
Depending on which way you want it, the approach you use will be different.

Also, what kind of SD card is it? How much data can it hold?

MorganS:
You know you can open more than one file on an SD card? Just you can't have two open at the same time. So at midnight,tally up the data for the main file, close it and save an entry to the daily file.

You should be closing the file every time you finish writing anyway. Pulling the SD card out while the Arduino is holding a file open is going to cause errors on the card. Since you are logging discrete events, the total time that the file is held open should only be a few milliseconds per day. Just put in a little test to ensure that there is a card present before you write to it.

I have pulled the card, copied the data, then put the card back in and found that it was not working. I press re-set each time I re-insert the card, so anything that was in memory is lost.
although you are correct, I plan on testing the approach on the SD to make sure I get valid readings.
I will also have a button to activate to write th contents of eeprom to the SD card once I get the bugs worked out.

odometer:
Do you want to record things like "the oil burner turned on at 10:30 and off at 10:50"?
Or is it enough to record "the oil burner was on for 20 minutes"?
Depending on which way you want it, the approach you use will be different.

Also, what kind of SD card is it? How much data can it hold?

I currently save
03:21:12 10/27/15 2.65 amps 1
I have 4 levels. 0/1/2/3
0 = less than 2amps // nothing running
1=>2 & < 3.4 // oil bruner draws around 2.6 amps
2 = >3.5 & < 5 // fan only draws about 3.8 amps
3 > 5.5 // oil and fan draw about 6.4 amps

the plan is that if 1 or 3,
then = millis()

I have a flag that sees any step change and upon a step change, writes the SD card.

what I was planning was

if step-change
if 1 or 3
then = millis()

if step-change
if 0 or 2
duration = millis() - then
odometer = odometer + duration

if midnight
log time and date with
date (of yesterday)
duration
odometer = odometer + duration

duration = 0


I will only need to set the odometer once a year.

MorganS:
The EEPROM has a limited number of write cycles. Writing the running log once per second could wear it out in less than a year. But an SD card has a wear leveling algorithm so you can write your running log as a separate file on the SD instead.

dave-in-nj:
that is why I want to write to it once per day, preferably at noon or midnight.
100,000 days... well within MTBF.

Rather than write to to the EEPROM once per second or once per day do so every 10 minutes. Just keep track of the number of 10 minute intervals in an unsigned long. That way you are not at risk of losing much data if there is a power failure. You could do some wear-levelling by writing to (say) 4 different EEPROM locations in succession. If you did lose power all you need to do is find the largest number among the saved values and continue from there.

...R

Robin2:
Rather than write to to the EEPROM once per second or once per day do so every 10 minutes. Just keep track of the number of 10 minute intervals in an unsigned long. That way you are not at risk of losing much data if there is a power failure. You could do some wear-levelling by writing to (say) 4 different EEPROM locations in succession. If you did lose power all you need to do is find the largest number among the saved values and continue from there.

...R

the plan is to tally the day's use and write only one time to the eeprom per day.

dave-in-nj:
the plan is to tally the day's use and write only one time to the eeprom per day.

But that means you lose a whole day's data if there is a power outage just before your WRITE.

...R

Robin2:
But that means you lose a whole day's data if there is a power outage just before your WRITE.

...R

trying to each my college daughter to find solutions and not barriers.
if I have a failed SD card, there is nothing.
if I lose power, and loose a day, I lose a day.
I could save each hour, 8,760 hours (saves) a year ?
eeprom would last over 100 years. ?

dave-in-nj:
I currently save
03:21:12 10/27/15 2.65 amps 1
I have 4 levels. 0/1/2/3
0 = less than 2amps // nothing running
1=>2 & < 3.4 // oil bruner draws around 2.6 amps
2 = >3.5 & < 5 // fan only draws about 3.8 amps
3 > 5.5 // oil and fan draw about 6.4 amps

the plan is that if 1 or 3,
then = millis()

I have a flag that sees any step change and upon a step change, writes the SD card.

what I was planning was

if step-change
if 1 or 3
then = millis()

if step-change
if 0 or 2
duration = millis() - then
odometer = odometer + duration

if midnight
log time and date with
date (of yesterday)
duration
odometer = odometer + duration

duration = 0


I will only need to set the odometer once a year.

Take care that your odometer does not "roll over".

Also, is it possible for "step-change" to go directly from 1 to 3, or from 3 to 1?
Besides, if you have a real-time clock, why are you using millis() to measure durations?

odometer:
Take care that your odometer does not "roll over".

Also, is it possible for "step-change" to go directly from 1 to 3, or from 3 to 1?
Besides, if you have a real-time clock, why are you using millis() to measure durations?

the weather this year has not offered a trial of the furnace.
currently
the oil burner starts and runs for about 4 minutes 2.5 amps
the fan comes on runs with the burner 6.5 amps
the burner shuts off and the fan continues 3.5 amps
I expect in cold, the fan could be running and the burner comes on again.
but I just look at the amps,
if it is less than 2, then I have a variable that shows condition 0
between 2 and 3, condition 1
between 3 and 4, condition 2
over 5 amps, condition 3
if the current condition is not the same as the last condition,
data log the time, the amps and the condition.
this works well and does not care what state it was in, only that it changed state.
what is new, is the odometer.
if condition 1 or 3, that means the oil burner is running.
new flag, burnerRunning = 1

now, if that changes state, I log the time.
if it enters that state, I note the time.

==============================

why millis() ?
easier to use millis() that to call the RTC
always have short runs of less than 10 minutes so cumulative errors will not be horrible.

also, I ran this in free mode, continuous scans, continuous logging. the RTC lost time.
it appears that the RTC can loose time if you call it too frequently, or if the call is not completed within an allotted time.
losing 45 seconds a day was very disconcerting ! in that search, some people posted that they call the RTC once a day, then use millis() and make an adjustment once a day.

thoughts on EEPROM.
say it has a total failure at 100,001 writes

that allows on to write to it once a day for 100k days
or 100k times in a day.

or once a day for 273 years
or 273 times a day for a year

or 27 times a day for 10 years
or once an hour for 11 years and 3 months.

=================================

Robin2 offered that a power failure would result in the loss of a days data.
that offers that either a battery backup or a super cap and a power test, write to eeprom upon a power loss
could be implemented. although the hope that the data would be on the SD card, it would mean going back through all the data to find the power loss.

Writing two files to the SD card also helps.
all testing will be to the SD card until I am confident that the EEPROM read/write is working.

Very welcome suggestions. botht needs to be addressed.