I currently have a program that resets the rain counter with this code snippit:
'IF IT IS THE BEGINNING OF THE DAY THEN WE RESET THE DAILY RAIN TOTAL TO 0
If IfTime(0,1440,Min) Then
SDI12Recorder (WXT(),C5,0,"XZRU!",1.0,0) 'THIS RESETS THE PRECIPITATION COUNTER
SDI12Recorder (WXT(),C5,0,"XZRI!",1.0,0) 'THIS RESETS THE PRECIPITATION INTENSITY
RainToday = 0
EndIf
Currently, my timestamp is set to Easter Standard Time (UTC-5) year-round. I want to change this to use UTC, and add a column for the local time using
UTCOffset = 5*3600-DaylightSavingUS(-1)
TmStamp_Local = Public.TimeStamp(1,1) - UTCOffset
Thanks to "notcabbage" for his answer in posting
UTC and Local Data tables simultaneously - Campbell Scientific User Forums
I'm thinking that if I do this, IfTime(0, 1440, Min) will then actually be midnight UTC?
Could I just change my code to
'5 hours early to account for UTC offset
If IfTime(-300, 1440,Min) Then
SDI12Recorder (WXT(),C5,0,"XZRU!",1.0,0) 'THIS RESETS THE PRECIPITATION COUNTER
SDI12Recorder (WXT(),C5,0,"XZRI!",1.0,0) 'THIS RESETS THE PRECIPITATION INTENSITY
RainToday = 0
EndIf
or maybe do this in Hours? (I inherited the current code)
If IfTime(-5, 24, hr) Then
SDI12Recorder (WXT(),C5,0,"XZRU!",1.0,0) 'THIS RESETS THE PRECIPITATION COUNTER
SDI12Recorder (WXT(),C5,0,"XZRI!",1.0,0) 'THIS RESETS THE PRECIPITATION INTENSITY
RainToday = 0
EndIf
Thanks in advance for any help.
I thought about this after I posted, but I still need to adjust for daylight saving time.
If IfTime(-300, 1440,Min)
should probably be
If IfTime(-UTCOffset/60, 1440,Min)
and
If IfTime(-5, 24,hr)
should be
If IfTime(-UTCOffset/3600, 24,hr)
This will get you closer. DaylightSavingUS() only returns a value when the time change happens.
PreserveVariables Public UTCOffset As Long = 5*3600 'Main Program BeginProg Scan (1,Sec,0,0) 'DaylightSavingUS only returns a value on the first scan at the new time 'Use 0 in DaylightSavingUS to not adjust the clock UTCOffset += DaylightSavingUS(0) NextScan EndProg
I am not completely certain this will work. The help for the instruction says the instruction returns 3600 when the time change happens. I am hoping it returns -3600 when time changes back. Otherwise, the offset would count up twice a year.
Thanks JDavis. It turns out that
UTCOffset = 5*3600-DaylightSavingUS(-1)
TmStamp_Local = Public.TimeStamp(1,1) - UTCOffset
Does give me a value of 14400 (4 hours) now.(We'll see what happens next week.) However doing this
UTCOffset_hrs = UTCOffset/3600 If IfTime(-UTCOffset_hrs,24,Hr) Then SDI12Recorder (WXT(),C5,0,"XZRU!",1.0,0) 'THIS RESETS THE PRECIPITATION COUNTER SDI12Recorder (WXT(),C5,0,"XZRI!",1.0,0) 'THIS RESETS THE PRECIPITATION INTENSITY RainToday = 0 EndIf
did NOT work. Maybe it was because I was trying to use a negative value for TintoInt? Anyway, I changed the If clause to be
If IfTime(24-UTCOffset_hrs,24,Hr) Then
thinking that this will be true 4 hours before midnight UTC (8PM local EDT), since my datalogger is set to UTC time. Before I left work yesterday, I noticed that my rain count did get reset, but at 20:00 UTC, 16:00 local time. So I guess the clock for IfTime() is actually local time and not UTC after all, and the correct offset is 0.
We had some light rain this morning. I haven't checked yet if the sensor picked it up yet (it was pretty light), so I suppose I'll know tomorrow morning if
If IfTime(0,24,Hr) Then
works as intended.
This post is under review.