Hi, I'm trying to send data to a server via sftp in files called "Table_YYYY-MM-DD.dat". Every file containing records between midnight and 23:59:59.
To achieve this, I used Table.Timestamp(5, m), with m the number of records between two transmissions.
The result is records between midnight and 23:59:59 only with Slow Table, the first. The other two table, Stat and Sonic files have record between 00:00:07.35 and 23:59:40.5 or something similar.
I also tried faster scan times, such as 30 seconds, but nothing changed.
How can I send data as frequently as possible, change the name at midnight, and correctly separate the stored records? Thanks
'CR6 Series 'Double sonic via RS232, double etm-30, sftp send and mail average notification 'ETM every 1 sec 'Sonic every 50 msec 'Average every 30 min sent by email every 6 hr 'All raw data sent via SFTP 'Mail Const _EMAIL_SUBJECT = "Six hour average" Const _EMAIL_TO_ADDRESS = "" Public email_message As String * 100 Public email_relay_server_response As String * 100 Public email_relay_results_human_readable As String * 40 Public email_tx_success Public avgName As String, previousAvgName As String Public mailFlag As Boolean 'FTP parameter strings (as constants), Message String & Result Variable Public FTPResult, FTPResult2, FTPResult3 Const IPAddress="" Const UserName="" Const Password="" Public sftpFlag As Boolean Public date_slow As String * 15 Public date_stat As String * 15 Public date_sonic As String * 15 'Serial COM RS232 Const STX=CHR(2) 'ASCII start-of-text Const ETX=CHR(3) 'ASCII end-of-text Public row2 As String * 50 Public n2 As Long 'Declare Public Variables Public u_1 Public v_1 Public w_1 Public Ts_1 Public u_2 Public v_2 Public w_2 Public Ts_2 Public AirTC1 Public RH1 Public AirTC2 Public RH2 Public BattV Public PTemp_C 'Public BP_mbar Units u_1=m/s Units v_1=m/s Units w_1=m/s Units Ts_1=C Units u_2=m/s Units v_2=m/s Units w_2=m/s Units Ts_2=C Units AirTC1=Deg C Units RH1=% Units AirTC2=Deg C Units RH2=% Units BattV=Volts 'Units BP_mbar=hPa 'Define slow Data Tables DataTable(Slow,True,-1) DataInterval(0,1,Sec,0) TableFile ("CRD:"&Status.SerialNumber(1,1)&"_slow_data_",64,-1,0,1,Day,0,0) Sample(1,AirTC1,FP2) Sample(1,RH1,FP2) Sample(1,AirTC2,FP2) Sample(1,RH2,FP2) EndTable DataTable(Stat,True,-1) DataInterval(0,1,Sec,0) TableFile ("CRD:"&Status.SerialNumber(1,1)&"_status_",64,-1,0,1,Day,0,0) Minimum(1,BattV,FP2,False,False) Average(1,PTemp_C,FP2,False) EndTable 'Define Data Tables DataTable (Sonic,True,-1) DataInterval(0,50,mSec,0) TableFile ("CRD:"&Status.SerialNumber(1,1)&"_sonic_data_",64,-1,0,1,Day,0,0) Sample(1, u_1,FP2) Sample(1, v_1,FP2) Sample(1, w_1,FP2) Sample(1, Ts_1,FP2) Sample(1, u_2,FP2) Sample(1, v_2,FP2) Sample(1, w_2,FP2) Sample(1, Ts_2,FP2) EndTable DataTable (Avg,True,-1) DataInterval (0,30,Min,0) 'aggiungo riga alla tabella ogni 30 min 'crea file nuovo ogni 6 ore = intervallo invio mail), tiene solo gli ultimi 4 file di medie, e invio per mail quello appena salvato TableFile("CRD:avg",64,5,0,6,Hr,0,avgName) Average (1,AirTC1,FP2,False) Average (1,RH1,FP2,False) Average (1,AirTC2,FP2,False) Average (1,RH2,FP2,False) Average(1, u_1,FP2,False) Average(1, v_1,FP2,False) Average(1, w_1,FP2,False) Average(1, Ts_1,FP2,False) Average(1, u_2,FP2,False) Average(1, v_2,FP2,False) Average(1, w_2,FP2,False) Average(1, Ts_2,FP2,False) Minimum(1,BattV,FP2,False,False) EndTable 'Main Program BeginProg mailFlag = True 'true invia mail sftpFlag = True SerialOpen(ComC3,9600,3,0,512,0) Scan (50,mSec,1200,0) VoltSe(u_1,1,mV5000,U1,False,200,15000,0.008,-20) '-20) VoltSe(v_1,1,mV5000,U2,False,200,15000,0.008,-20) '-20) VoltSe(w_1,1,mV5000,U3,False,200,15000,0.008,-20) '-20) VoltSe(Ts_1,1,mV5000,U4,False,200,15000,0.022,-40) SerialInRecord (ComC3,row2,2,0,3,n2,01) '2 and 3 ascii char or &H02 and &H0D0A If n2 = 39 Then u_2 = Mid(row2,3,7) v_2 = Mid(row2,11,7) w_2 = Mid(row2,19,7) Ts_2 = Mid(row2,29,7) EndIf CallTable Sonic NextScan SlowSequence Scan(1,Sec,1,0) 'Default CR6 Datalogger Battery Voltage measurement 'BattV' Battery(BattV) VoltSe(AirTC1,1,mV1000,U10,False,0,15000,0.1,-40) VoltSe(RH1,1,mV1000,U9,False,0,15000,0.1,0) If RH1>100 AND RH1<103 Then RH1=100 VoltSe(AirTC2,1,mV1000,U12,False,0,15000,0.1,-40) VoltSe(RH2,1,mV1000,U11,False,0,15000,0.1,0) If RH2>100 AND RH2<103 Then RH2=100 CallTable Slow CallTable Stat CallTable Avg NextScan SlowSequence Scan(30,Min,3,0) 'Send to server If sftpFlag Then date_slow = Left(Slow.Timestamp(5,1800),10) '1 * 60 * 30 measure ago date_stat = Left(Stat.Timestamp(5,1800),10) '1 * 60 * 30 measure ago date_sonic = Left(Sonic.Timestamp(5,36000),10) '20 * 60 * 30 measure ago FTPResult=FTPClient(IPAddress,UserName,Password,"Slow","Slow_" & date_slow & ".dat",28,0,0,Min,-1008) FTPResult2=FTPClient(IPAddress,UserName,Password,"Stat","Stat_" & date_stat & ".dat",28,0,0,Min,-1008) FTPResult3=FTPClient(IPAddress,UserName,Password,"Sonic","Sonic_" & date_sonic & ".dat",28,0,0,Min,-1008) EndIf 'Send email If avgName <> previousAvgName AND mailFlag Then 'if new file avg saved previousAvgName = avgName email_message = email_message & "Datalogger station " & Status.StationName & ". " email_message = email_message & "Datalogger time is " & Public.Timestamp(4,1) '1st attempt email_tx_success = EmailRelay (_EMAIL_TO_ADDRESS,_EMAIL_SUBJECT,email_message,email_relay_server_response,avgName) 'If EmailRelay was not successful, lets try one more time. If email_tx_success <> -1 Then '2nd attempt email_tx_success = EmailRelay (_EMAIL_TO_ADDRESS,_EMAIL_SUBJECT,email_message,email_relay_server_response,avgName) EndIf 'Human readable error messages Select Case email_tx_success Case -1 email_relay_results_human_readable = "EmailRelay received msg OK!" Case 0 email_relay_results_human_readable = "Conn to EmailRelay failed" Case -2 email_relay_results_human_readable = "lack of records or not enough time" Case -3 email_relay_results_human_readable = "EmailRelay OK, error in communication." EndSelect EndIf NextScan EndProg
The easiest way is usually the optional parameters in the FTPClient() instruction. There is a technical paper on the topic:
https://s.campbellsci.com/documents/us/technical-papers/ftp-streaming.pdf
Sorry, but I don't understand how can I send data frequently (every 10-30 minutes) and change the date in the file name to match the data inside.
With the optional parameters of FTPClient(), it seems to me that I can only send one file per day at midnight, with an incremental number appended.
Thanks