Hello there,
Looking for a piece of advice on the following issue:I need to display rainfall since 9 am, updated every minute up until 8.59 am next day, calculated using the 1-minute data.
I was trying to use DateInterval() but couldn't make it work for a specific time frame. It looks like DataInterval() can only be used from in 24 total from midnight to midnight. But maybe I wrong.
Appreciate if somebody could advise or point to the right direction. Below is a copy of the code I'm using.
Thanks!
'Declare Variables and Units
Public BattV
Public PTemp_C
'Public PTemp_C_Avg(3)
Public AirTC
Public Data_Avg(4)
Public RH
Public BP_mbar
Public Rainfall
Public Rainfall24hrs(1)
Public No_Tips
Public Output_Command As String * 255
Units BattV=Volts 'Battery voltage
Units PTemp_C=Deg C'Panel Temperature
Units AirTC=Deg C 'Air Temperature
Units RH=% 'Humidity
Units BP_mbar=mbar 'Barometer
Units Rainfall = mm'Rain
'Define Data Tables
DataTable(Data,True,-1)
DataInterval(0,1,Min,10)
CardOut(0,-1)
Average(1,AirTC,FP2,False)
Average(1,RH,FP2,False)
Average(1,BP_mbar,IEEE4,False)
' Totalize (1,Rainfall,FP2,False)
EndTable
'DataTable(Data_total,True,-1)
' DataInterval (0,1,Min,10)
' CardOut(0,-1)
' Totalize (1,Rainfall,FP2,False)
' Totalize (1,No_Tips,FP2,False)
'EndTable
DataTable(Rain_Accum,True,-1)
DataInterval (-870,1440,day,0)
Totalize (1,Rainfall,FP2,False)
EndTable
DataTable(Battery,True,-1)
DataInterval(0,1440,Min,10)
Minimum(1,BattV,FP2,False,False)
EndTable
'Main Program
BeginProg
SerialOpen (ComRS232,9600,0,100,255)
'Main Scan
Scan(5,Sec,1,0)
'Default CR6 Datalogger Battery Voltage measurement 'BattV'
Battery(BattV)
'Default CR6 Datalogger Wiring Panel Temperature measurement 'PTemp_C'
PanelTemp(PTemp_C,50)
'HMP155 (constant power) Temperature & Relative Humidity Sensor measurements 'AirTC' and 'RH'
VoltSe(AirTC,1,mV5000,U1,False,0,50,0.02,-40)
VoltSe(RH,1,mV5000,U2,False,0,50,0.02,0)
If RH>100 AND RH<108 Then RH=100
'PTB210 Barometric Pressure Sensor measurement 'BP_mbar'
VoltSe(BP_mbar,1,mV5000,U3,True,0,50,0.052,800)
PulseCount (Rainfall,1,C1,1,0,0.2,0)
No_Tips = Rainfall/0.2
If IfTime (15,24,hr)
ResetTable (Rain_Accum)
EndIf
GetRecord (Data_Avg(),Data,1)
GetRecord (Rainfall24hrs(),Rain_Accum,1)
'Call Data Tables and Store Data
CallTable Data
'CallTable Data_total
CallTable Rain_Accum
CallTable Battery
NextScan
'Send output to RS232 port
SlowSequence
Scan (1,Min,1,0)'scan buffer parameter ignored
Output_Command="$MTEMS,"+ BattV+","+Data_Avg(1)+","+Data_Avg(2)+","+Data_Avg(3)+","+Data_Avg(4)+","+Rainfall24hrs(1)+CHR(13)
SerialOut (ComRS232,Output_Command,"",0,100)
SerialFlush (ComRS232)
NextScan
EndProg
Use the DataInterval instruction for a Interval of 24 hours and 9 for TimeIntoInterval. As follows :
DataInterval (9,24,Min,10)
This is a period of 24 hours from 9am to 9am. This should get you what you want.
Hi nsw,
Thanks for the reply, I changed DataInterval() as per your example. However, I have a quiestion for you.
When I tested with new DataInterval() , I simulated rainfall using tipping bucket prior 9am and around 08:58 I saw values in Rainfalltotal24 (Which should represent rain_accumulated data for 24 hrs), then after a 9am I simulated rain again and values are chaged to new one. So, I assumed it working correct and then I simulated rain once again assuming that this new value will be added to the exisiting as its still within 24Hrs period. However, insted of updating total number its replaced with a new values.
So, my quiestion is how do I know if DataInterval() 24 hrs is actulally counting total for 24 Hrs ?
Apologies if my explanation not clear, english is not my first language.
Thanks,
SBR
Public BattV
Public PTemp_C
Public Data_Avg(4)
Public Rainfall24hrs
Public NoTips
Public NoTips24hrs As Long
Public Output_Command As String * 255
BeginProg
Scan (5,Sec,0,0)
PanelTemp (PTemp_C,15000)
Battery (BattV)
PulseCount (NoTips,1,C1,1,0,1,0) 'get no tips since last scan
NoTips24hrs = NoTips24hrs + NoTips 'accum no tips
Rainfall24hrs = NoTips24hrs * 0.2 'convert accum no tips to mm rain
If TimeIntoInterval(9,24,Hr) Then
'we have accounted for all tips in last 24 hours
'it is time to reset the accum no tips
NoTips24hrs = 0
EndIf
NextScan
'Send output to RS232 port
SlowSequence
SerialOpen (ComRS232,9600,0,100,255)
Scan (1,Min,1,0)'scan buffer parameter ignored
'Output_Command="$MTEMS," + BattV + "," + Data_Avg(1) + "," + Data_Avg(2) + "," + Data_Avg(3) + "," + Data_Avg(4) + "," + Rainfall24hrs + CHR(13)
Sprintf (Output_Command,"$MTEMS,%0.2f,%0.2f,%0.2f,%0.2,%0.2f,%0.02f",BattV,Data_Avg(1),Data_Avg(2),Data_Avg(3),Data_Avg(4),Rainfall24hrs)
SerialOut (ComRS232,Output_Command,"",0,100)
SerialFlush (ComRS232)
NextScan
EndProg
Public BattV Public PTemp_C Public Data_Avg(4) Public Rainfall24hrs Public NoTips Public NoTips24hrs As Long Public Output_Command As String * 255 BeginProg Scan (5,Sec,0,0) PanelTemp (PTemp_C,15000) Battery (BattV) PulseCount (NoTips,1,C1,1,0,1,0) 'get no tips since last scan NoTips24hrs = NoTips24hrs + NoTips 'accum no tips Rainfall24hrs = NoTips24hrs * 0.2 'convert accum no tips to mm rain If TimeIntoInterval(9,24,Hr) Then 'we have accounted for all tips in last 24 hours 'it is time to reset the accum no tips NoTips24hrs = 0 EndIf NextScan 'Send output to RS232 port SlowSequence SerialOpen (ComRS232,9600,0,100,255) Scan (1,Min,1,0)'scan buffer parameter ignored 'Output_Command="$MTEMS," + BattV + "," + Data_Avg(1) + "," + Data_Avg(2) + "," + Data_Avg(3) + "," + Data_Avg(4) + "," + Rainfall24hrs + CHR(13) Sprintf (Output_Command,"$MTEMS,%0.2f,%0.2f,%0.2f,%0.2,%0.2f,%0.02f",BattV,Data_Avg(1),Data_Avg(2),Data_Avg(3),Data_Avg(4),Rainfall24hrs) SerialOut (ComRS232,Output_Command,"",0,100) SerialFlush (ComRS232) NextScan EndProg