-
Notifications
You must be signed in to change notification settings - Fork 7
/
LICOR_CR1000_phenocam_ftp.CR1
436 lines (323 loc) · 14.5 KB
/
LICOR_CR1000_phenocam_ftp.CR1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
'CR1000 Series Datalogger
'To create a different opening program template, type in new
'instructions and select Template | Save as Default Template
'date:03/07/2016
'program author:Earl Keel
'contact: Earl Keel, USDA-ARS Southeast Watershed Research Lab Tifton, GA
'*****************************************************************************************
'This program will ftp the images directly the phenocam network.
'It can also ftp the images to another server if the lines are uncommented,
'SEWRL uses this function to store a local copy of the images and metadata.
'This will double your data usage on the modem, plan accordingly.
'Program also records rainfall. Using the CR1000 to capture images allows other parameters
'onsite to be recorded as well.
'!!!!!!!!This program requires that a CF card be used!!!!!!!!!!!!!!!!!!!
'a 2GB CF card should store ~3.5 months of images and metdata
'*****************************************************************************************
'Code copied from Peter 03/01/2016 EK
'Date: 1/21/2015
'Contact: Peter Ganzlin, USDA-ARS SWMRU - [email protected]
'Date:03/07/2016 EK
'Modified program to copy .jpg file to CRD: as data backup
'Date:03/14/2016 EK
'Added midnight table.
'Added instructions to clear USR: drive if full, full drive was preventing
' images from being written to CRD: drive. USR: drive is normally cleared
' after Loggernet retrieves .jpg. If communication link is lost, images will still
' be stored on compact flash card.
'Date:03/15/2016 EK
'Corrected timeisbetween function for setting takepic = true
'
'Changed instructions to control C5 for powering modem to timeisbetween.
'
'Date 03/16/2016 EK
'Increased modem on time from 5 to 10 minutes
'Added instructions to get metadata for each image both rgb and ir.
'Date 03/31/2016 EK
'Created .cgi calls on the phenocam CR1000 then calls them to collect the images and
' metadata.
'Date 05/03/2016 EK
'Implemented FTP file push to both phenocam network and Local ftp
'Date 05/09/2016 EK
'Added rainfall to program 1min and 5 min. Code used from Randy Williams ARS SEWRL.
'********************Wiring************************
'NetCam SC Power 12VDC SW12
' Ground G
'
'Crydom D1D07 relay Input +(3) C5
' Input -(4) G
' Output+(2) 12V Preferably on Power in to logger such as CH200
' Output-(1) +12VDC supply to Raven XT
'
'Raven XT +12VDC in Output -(1) of Relay
' Ground G Preferably on CH200
'TE525 raingauge signal(white) P1
' signal ref(black) singal ground AG
' shield(clear) G
'Phenocam Variables
'TCPIP and date/time variables for NetCam
Public HGetHandle As Long
Public HGetResp As String * 48
Public HGetHead As String * 48
Public HGetHandleMeta_rgb As Long
Public HGetRespMeta_rgb As String * 48
Public HGetHandleMeta_ir As Long
Public HGetRespMeta_ir As String * 48
'FTP variable
Public FTPResult
Public SendFTP As Boolean
Public Pingtest
'File list variable
Public NumFile
Public USRFiles(4) As String * 40
Public FTPDest(4) As String * 60
Public PhenoDest(4) As String *65
Dim i
Dim j
Dim p
'Realtime clock array
Dim rTime(9)
Alias rTime(1) = Year,Month,DOM,Hour,Minute,Secd,uSecd,WkDay,DayofYr
'DateTime date/time string format
Public DateTime As String * 28
Dim UTC_Offset As Long
'Phenocam
Public TakePic As Boolean
Public Copy_rgb As Boolean
Public Copy_meta_rgb As Boolean
Public Copy_ir As Boolean
Public Copy_meta_ir As Boolean
'Variable to store USR drive space
Public Drivefree As Long
'Modem control flag
Public Flag(5) As Boolean
' - reads every minute
' - store rain data every minute if raining
' - store 5 minute rainfall totals if raining
'\\\\\\\\\\\\\\\\\\\\\\\\\\\\DECLARATIONS\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
Public pcpinch, fvminpcp, oneminpcp
Public OutputFlag111 As Boolean
Public OutputFlag444 as BOOLEAN
Units oneminpcp=inch
Units pcpinch=inch
Units fvminpcp=inch
'Declare Public Variables
'Example:
Public PTemp, batt_volt
'Declare Other Variables
'Example:
'Dim Counter
'Declare Constants
'Example:
'CONST PI = 3.141592654
'Phenocam Data Table
'Log for NetCam downloads
DataTable (HGetLog,True,100)
Sample (1,HGetHandle,Long)
Sample (1,HGetResp,String)
Sample (1,HGetHead,String)
Sample (1,Copy_rgb,Boolean)
Sample (1,Copy_ir,Boolean)
EndTable
'Define Rain Data Tables
DataTable (Precp,True,120 )
DataInterval (0,1,Min,10)
Totalize (1,pcpinch,FP2,False)
EndTable
DataTable(Precp_1min,OutputFlag111,-1)
DataInterval(0,1,Min,10)
Sample(1,oneminpcp,FP2)
EndTable
DataTable (Precp_5min_inch, true,24)
DataInterval (0,5,Min,10)
Totalize(1,pcpinch,FP2,0)
EndTable
DataTable(Precp_5min_in_RFOnly,OutputFlag444,-1)
DataInterval(0,5,Min,10)
Sample(1,fvminpcp, FP2)
EndTable
'Define Data Tables.
DataTable (Hourly,1,9999) 'Set table size to # of records, or -1 to autoallocate.
DataInterval (0,60,Min,10)
Minimum (1,batt_volt,FP2,False,False)
Sample (1,PTemp,FP2)
EndTable
'Added midnight table 03/14/2016
DataTable (Midnight,True,30 )
DataInterval (0,1440,Min,10)
Minimum (1,batt_volt,FP2,False,False)
Sample (1,PTemp,FP2)
EndTable
'Define Subroutines
'Sub
'EnterSub instructions here
'EndSub
'Main Program
BeginProg
NetworkTimeProtocol ("",-18000,1000)
Scan (1,Sec,0,0)
PanelTemp (PTemp,250)
Battery (batt_volt)
'Enter other measurement instructions
'Call Output Tables
'Example:
'TE525/TE525WS Rain Gauge measurement
'measure the number of bucket tips, calc. precip volume (inches)
'each tip is 0.01 inch
PulseCount(pcpinch,1,1,2,0,0.01,0)
CallTable Precp
CallTable Precp_5min_inch
' begin final storage calculations
' store precip every minute during rain events
If (Precp.output(1,1)=true) Then GetRecord(oneminpcp,Precp,1)
If (oneminpcp <> 0) Then
OutputFlag111=true
EndIf
CallTable Precp_1min
OutputFlag111 = false
' calculate 5 minute total
If (Precp_5min_inch.output(1,1)=true) Then GetRecord(fvminpcp,Precp_5min_inch,1)
If (fvminpcp <> 0) Then
OutputFlag444=true
EndIf
CallTable Precp_5min_in_RFonly
OutputFlag444 = false
CallTable Hourly
CallTable Midnight
'between 5:30 and 21:00 trigger an image every 30 minutes
' If TimeIsBetween (0530,21,24,Hr) Then
If TimeIsBetween (330,1260,1440,Min) Then
If IfTime(0,30,min) Then TakePic = TRUE
EndIf
' Power modem using C5 and Crydom solid state relay D1D07
' Turn on cell modem 9 minutes into a 30 minute interval
' If IfTime(9,30,min) Then
' Flag(5) = True
' EndIf
' Turn off cell modem 14 minutes into a 30 minute interval
'If IfTime(14,30,min) Then
'Flag(5) = False
' EndIf
'Added timeisbetween function to control C5
'Increased time the cell modem is powered up from 5 to 10 min.
If TimeIsBetween (9,25,30,min) Then
Flag(5) = True
Else
Flag(5) = False
EndIf
If Flag(5) = True Then PortSet(5,1) 'C5 set high
If Flag(5) = False Then PortSet(5,0)' C5 set low
NextScan
SlowSequence
Do
Delay (1,1,Sec)
RealTime (rTime) 'get various time elements
If TakePic = TRUE Then
Drivefree = settings.USRDriveFree 'Retrieve free space on USR: drive
If Drivefree <= 500000 Then 'If no room left on USR
FileManage ("USR:*.jpg",16) 'delete .jpg files from USR
FileManage ("USR:*.meta",16) 'delete .txt files from USR
EndIf
SW12(1) 'turn on camera
Delay(1,70,Sec) 'delay, let camera boot up
'intialize rgb filename
'Stores image with filename from phenocam i.e. "arsgacp1"
HGetResp = "USR:arsgacp1_" &rTime(1)&"_"&FormatLong(rTime(2),"%02u")&"_"&FormatLong(rTime(3),"%02u")&"_"&FormatLong(rTime(4),"%02u")&FormatLong(rTime(5),"%02u")&FormatLong(rTime(6),"%02u") &".jpg"
HGetHead = "" 'important to initialize
'get image and store to USR drive OLD WAY w/o metadata
' HGetHandle = HTTPGet("http://192.168.1.100/netcam.jpg",HGetResp,HGetHead)
'get rgb image metadata
HGetRespMeta_rgb = "USR:arsgacp1_" &rTime(1)&"_"&FormatLong(rTime(2),"%02u")&"_"&FormatLong(rTime(3),"%02u")&"_"&FormatLong(rTime(4),"%02u")&FormatLong(rTime(5),"%02u")&FormatLong(rTime(6),"%02u") &".meta"
HGetHandleMeta_rgb = HTTPGet("http://192.168.1.100/metadata.cgi",HGetRespMeta_rgb,"")
HGetHandle = HTTPGet("http://192.168.1.100/rgb.cgi",HGetResp,HGetHead)
'copy file from USR: to CRD:
Copy_rgb = FileCopy ("USR:arsgacp1_" &rTime(1)&"_"&FormatLong(rTime(2),"%02u")&"_"&FormatLong(rTime(3),"%02u")&"_"&FormatLong(rTime(4),"%02u")&FormatLong(rTime(5),"%02u")&FormatLong(rTime(6),"%02u") &".jpg","CRD:arsgacp1_" &rTime(1)&"_"&FormatLong(rTime(2),"%02u")&"_"&FormatLong(rTime(3),"%02u")&"_"&FormatLong(rTime(4),"%02u")&FormatLong(rTime(5),"%02u")&FormatLong(rTime(6),"%02u") &".jpg")
'copy metadata file from USR: to CRD:
Copy_meta_rgb = FileCopy ("USR:arsgacp1_" &rTime(1)&"_"&FormatLong(rTime(2),"%02u")&"_"&FormatLong(rTime(3),"%02u")&"_"&FormatLong(rTime(4),"%02u")&FormatLong(rTime(5),"%02u")&FormatLong(rTime(6),"%02u") &".meta","CRD:arsgacp1_" &rTime(1)&"_"&FormatLong(rTime(2),"%02u")&"_"&FormatLong(rTime(3),"%02u")&"_"&FormatLong(rTime(4),"%02u")&FormatLong(rTime(5),"%02u")&FormatLong(rTime(6),"%02u") &".meta")
Delay(1,30,Sec)
'switches camera to ir mode
HGetResp = ""
' HGetHead = "Authorization: Basic YWRtaW46YWRtaW4NCg==" +CHR(13)+CHR(10)
HGetHead = ""
HGetHandle = HTTPGet("http://admin:[email protected]/admin.cgi?image&ir_enable=1",HGetResp,HGetHead)
Delay(1,30,Sec)
'intialize ir filename
HGetResp = "USR:arsgacp1_IR_" &rTime(1)&"_"&FormatLong(rTime(2),"%02u")&"_"&FormatLong(rTime(3),"%02u")&"_"&FormatLong(rTime(4),"%02u")&FormatLong(rTime(5),"%02u")&FormatLong(rTime(6),"%02u") &".jpg"
HGetHead = "" 'important to initialize
'get image and store to USR drive OLD WAY w/o metadata
' HGetHandle = HTTPGet("http://192.168.1.100/netcam.jpg",HGetResp,HGetHead)
'get ir image metadata
HGetRespMeta_ir = "USR:arsgacp1_IR_" &rTime(1)&"_"&FormatLong(rTime(2),"%02u")&"_"&FormatLong(rTime(3),"%02u")&"_"&FormatLong(rTime(4),"%02u")&FormatLong(rTime(5),"%02u")&FormatLong(rTime(6),"%02u") &".meta"
HGetHandleMeta_ir = HTTPGet("http://192.168.1.100/metadata.cgi",HGetRespMeta_ir,"")
HGetHandle = HTTPGet("http://192.168.1.100/rgb.cgi",HGetResp,HGetHead)
'copy file from USR: to CRD
Copy_ir = FileCopy ("USR:arsgacp1_IR_" &rTime(1)&"_"&FormatLong(rTime(2),"%02u")&"_"&FormatLong(rTime(3),"%02u")&"_"&FormatLong(rTime(4),"%02u")&FormatLong(rTime(5),"%02u")&FormatLong(rTime(6),"%02u") &".jpg","CRD:arsgacp1_IR_" &rTime(1)&"_"&FormatLong(rTime(2),"%02u")&"_"&FormatLong(rTime(3),"%02u")&"_"&FormatLong(rTime(4),"%02u")&FormatLong(rTime(5),"%02u")&FormatLong(rTime(6),"%02u") &".jpg")
'copy file from USR: to CRD
Copy_meta_ir = FileCopy ("USR:arsgacp1_IR_" &rTime(1)&"_"&FormatLong(rTime(2),"%02u")&"_"&FormatLong(rTime(3),"%02u")&"_"&FormatLong(rTime(4),"%02u")&FormatLong(rTime(5),"%02u")&FormatLong(rTime(6),"%02u") &".meta","CRD:arsgacp1_IR_" &rTime(1)&"_"&FormatLong(rTime(2),"%02u")&"_"&FormatLong(rTime(3),"%02u")&"_"&FormatLong(rTime(4),"%02u")&FormatLong(rTime(5),"%02u")&FormatLong(rTime(6),"%02u") &".meta")
If Copy_meta_ir Then SendFTP = True
Delay(1,15,Sec)
'swicthes camera back to rgb mode
HGetResp = ""
'HGetHead = "Authorization: Basic YWRtaW46YWRtaW4=" +CHR(13)+CHR(10)
HGetHead = ""
HGetHandle = HTTPGet("http://admin:[email protected]/admin.cgi?image&ir_enable=0",HGetResp,HGetHead)
CallTable HGetLog 'log retrieval
SW12(0) 'turn off camera
TakePic=FALSE
Copy_rgb = False
Copy_ir = False
Copy_meta_ir = False
Copy_meta_rgb = False
'SendFTP = True
EndIf
Loop
EndSequence
'Slow sequence to send files to FTP server
SlowSequence
Scan (120,Sec,0,0)
If SendFTP = True
'Set port for outgoing to PPP for ping test
IPRoute("8.8.8.8",1)
'Test connection prior to sending files ftp destination
Pingtest = PingIP ("8.8.8.8",3000)
'IF connection is good proceed with ftp transfer
If Pingtest <> 0 Then
'Clear out USRFiles array before next call on filelist
Erase (USRFiles())
'Get a list of file names from the USR drive
NumFile = FileList ("USR",USRFiles())
'Replace USR: for the destination on the ftp drive
' For i = 1 To 4
' FTPDest(i)= Replace (USRFiles(i),"USR:","/arsgacp1test/")
' Next i
'Replace USR: for the destination on the phenocam network
For p = 1 To 4
PhenoDest(p)= Replace (USRFiles(p),"USR:","/data/arsgacp1/")' replace arsgacp1 with site name
Next p
'--------This section of code sends the images to a local FTP server--------------------
' uncomment and fill in a proper IP address if you want to store a local copy of images
'Set port connection for outgoing to PPP for (local ftp server)
' IPRoute ("xxx.xxx.xxx.xxx",1)
'FTP file to a local ftp server
' For j = 1 To 4
' FTPResult = FTPClient ("xxx.xxx.xxx.xxx","user_name","password",USRFiles(j),FTPDest(j),2)
' Next j
'-----------------------------------------------------------------------------------------
'Set port connection for outgoing to PPP for Phenocam network
IPRoute ("klima.nau.edu",1)
'FTP file to Phenocam network
For j = 1 To 4
FTPResult = FTPClient ("phenocam.nau.edu","anonymous","anonymous",USRFiles(j),PhenoDest(j),2)
Next j
'Remove files from USR drive if sucessful
If FTPResult = -1 Then
FileManage ("USR:*.jpg",16) 'delete .jpg files from USR
FileManage ("USR:*.meta",16) 'delete .txt files from USR
SendFTP = False
EndIf
EndIf
EndIf
NextScan
EndSequence
EndProg