Our full technical support staff does not monitor this forum. If you need assistance from a member of our staff, please submit your question from the Ask a Question page.


Log in or register to post/reply in the forum.

Adding timestamp to HTTPGet filename


ganzlin Oct 8, 2015 08:31 PM

Hello,

I am successfully collecting .jpg images from a netcam to a CR3000 logger's USR drive and retrieving them on a schedule.

My question is: I need the .jpg files to be in the following convention: sitename_YYYY_MM_DD_hhmmss.jpg

Before I try and go down the route of renaming in an outboard program, I thought it might be possible in CRBasic/Device Config. It seems like the "Response" parameter of the HTTPGet function is not a filename per se, but specifies the drive the file is saved on the datalogger, and must match the "Files Manager File Name" in device configuration utility. As the datalogger is already putting a timestamp in the log file from the table from when the image was taken, is it possible to create a filename with a timestamp?

Currently, as the "Count" setting in device config. is set to 2 to prevent USR drive from filling up and coordinate with scheduled collection so the filename of each image currently is just the sitename and a sequential number. The program is attached here with my attempt to add the timestamp to the Response parameter.

Thanks,
Peter


'GCE-LTER Example Code for connecting a StarDot NetCam SC to a Campbell CR3000 with NL116 Ethernet module
'
'by Wade Sheldon <sheldon@uga.edu>
'
'modified from code provided by Nicholas Grant <ngrant02@fs.fed.us>
'
'last updated: 10-6-2015 by Peter Ganzlin USDA-ARS St. Paul, MN

'Notes:
' 1) The timed instructions are based on a logger synchronized to UTC/GMT and should be
' adjusted accordingly if the logger is on standard time
' 2) If the default admin password has been changed, a new base64-encoded authorization string
' will need to be generated to call the admin.cgi script; go to http://www.base64encode.org/
' and paste in username:password (e.g. admin:SiteAdmin2013 = YWRtaW46U2l0ZUFkbWluMjAxMw==)
' 3) At the recommended PHENOCAM resolution and JPEG compression only 2 images can be stored
' in the USR drive configured below, so LoggerNet should be set to retrieve (and delete)
' files every 30-60 min to avoid losing images (Main > Setup > File Retrieval tab for the logger)
' 4) Overlay text and other parameters sent to admin.cgi containing spaces, percent symbols, etc.
' need to be url-encoded (see http://www.url-encode-decode.com/ for a web-based encoding tool)
' 5) If the camera code is included in a high-frequency program, e.g. an eddy covariance flux tower,
' it should be included in a SlowSequence block after the primary scan block

'CR3000 Device Configuration Utility settings for NL115 and files:
' a) NL116 (192.168.1.2), Subnet Mask (255.255.255.0), IP Gateway (192.168.1.1), DNS Server (0.0.0.0), Camera: 192.168.1.100
' b) Advanced -> USR: Drive Size -> 1000000
' c) Advanced -> Files Manager -> (3213, USR:rosemountc6.jpg, 2) Filename = USR:rosemountc6.jpg, PakBus Address = 3213, Count = 2

'POWER IN
'12V datalogger (red)
'G datalogger (black)

PipeLineMode


'*** Variables ***

'TCPIP and date/time variables for NetCam
Public HGetHandle As Long
Public HGetResp As String * 48
Public HGetHead As String * 48

'Realtime clock array
Dim rTime(9)
Alias rTime(1) = Year 'assign the alias Year to rTime(1)
Alias rTime(2) = Month 'assign the alias Month to rTime(2)
Alias rTime(3) = Day_ 'assign the alias Day to rTime(3)
Alias rTime(4) = Hour 'assign the alias Hour to rTime(4)
Alias rTime(5) = Minute 'assign the alias Minute to rTime(5)
Alias rTime(6) = Second 'assign the alias Second to rTime(6)
'*** Final Output Data Tables ***

'Log for NetCam downloads
DataTable (HGetLog,True,100)
Sample (1,HGetHandle,Long)
Sample (1,HGetResp,String)
Sample (1,HGetHead,String)
EndTable


'*** Program ***

BeginProg

Scan (60,Sec,3,0)
RealTime (rTime) 'get various time elements

'check for the hours of 6:30am to 8pm CST for camera operations
If (Hour > 6 AND Minute > 30) OR Hour >= 7 OR Hour < 20 Then
EndIf
'turn on camera at 5 min before each cycle
If (IfTime(5,20,min) OR IfTime(15,20,min)) Then
SW12(2,1) 'turn on camera
EndIf

'Take a picture every 30min
If (IfTime(0,20,min) OR IfTime(10,20,min)) Then
'intialize rgb filename
HGetResp = "USR:rosemountc6_" & 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
HGetHandle = HTTPGet("http://192.168.1.100/netcam.jpg",HGetResp,HGetHead)
CallTable HGetLog 'log retrieval
SW12(2,0) 'turn off camera
EndIf

'turn off camera after last image capture, since camera powered on at 19:55 GMT
If (Hour = 20) Then
SW12(2,0)
EndIf

NextScan

EndProg


jtrauntvein Oct 9, 2015 11:34 PM

When you use the files manager setting, the datalogger will rename files received from the specified PakBus address, in you case, the PakBus address is a "magic" value that identifies files written by the HTTPGet instruction and will add a serial number to the file name specified. To the best of my knowledge, the files manager setting does not provide a way to mange the file name with the date. In your case, the use the of the Files Manager setting is working against your desired outcome.

The datalogger will interpret the second parameter as a file name if the string that you pass is formatted as a file name. Otherwise, the datalogger will write the response received from the server to that parameter. Since your program is already generating the file name using the date, a unique name will be generated each time anyway so the files manager setting is not doing that much for you.

If you are worried about filling up the drive and you are using LoggerNet to retrieve the files from the USR drive, LoggerNet has the option to delete the file after it has been retrieved.


ganzlin Oct 13, 2015 01:29 PM

Jtrauntvein,

Thank you for your response. That is what I was thinking, that the files manager is not the best for my case.

That said, I am still a little confused. Is there an alternative way to remotely retrieve files from the USR drive that could make use of the string in the "response parameter" as a filename?

Thanks


jtrauntvein Oct 13, 2015 04:08 PM

LoggerNet can be set up to retrieve files automatically either on its own schedule or following scheduled collection. This can be done in the Setup Screen's "File Retrieval" tab. You can specify a wildcard file pattern, such as "usr:rosemountcr*.jpg" and LoggerNet will retrieve any files that match that pattern that have been added since the last poll. This same tab also has a "Delete Files After Retrieval" check box that, if checked, will cause LoggerNet to send commands to delete the files from the datalogger after they have been retrieved.

Log in or register to post/reply in the forum.