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.

Can you use ShortCut to make a CR1000 w/ NL120 push to FTP?


joshdr83 May 29, 2012 08:19 PM

I am not a programmer, but I can get ShortCut to do what I want pretty well. However, I have not been able to get ShortCut to push to an FTP site, is this possible?

Thanks


Ken Conner May 29, 2012 10:14 PM

At this time you can't use ShortCut to program the data logger to send data via FTP.

If you have a copy of the CRBasic editor you can use this example to modify the program generated by ShortCut.

Public PTemp, batt_volt
Public Outstat, LastFileName As String * 30

Const ServerIP = "192.168.0.1"
Const User = "Admin"
Const Password = "Admin"
Const DestPath = "/Site1/Data/OneMin"


DataTable (Test,1,1000)
TableFile ("USR:OneMinData",8,-1,0,24,Hr,Outstat,LastFileName)
Minimum (1,batt_volt,FP2,0,False)
Sample (1,PTemp,FP2)
EndTable

BeginProg
Scan (1,Sec,0,0)
PanelTemp (PTemp,250)
Battery (batt_volt)

CallTable Test

If Outstat = -1 Then
Outstat = 0
FTPClient (ServerIP,User,Password,LastFileName,DestPath,2)
EndIf

NextScan
EndProg


joshdr83 May 30, 2012 04:04 PM

Can you get the CRBasic Editor without Loggernet, or do you have to buy the software package together?


jtrauntvein May 30, 2012 04:24 PM

While the CRBasic editor has all sorts of bells and whistles such as syntax highlighting, context sensitive help, invocation of the precompiler, & etcetera, it is by no means required in order to edit a datalogger program. All datalogger programs are simply text files and can be edited with any editor that can handle plain text. This would include notepad, wordpad, vi, and emacs (my favourite).


Ken Conner May 30, 2012 06:19 PM

CRBasic Editor comes with LoggerNet and PC400, which are both pieces of software that you purchase. There is a free 30 trial of LoggerNet available for download at:

https://www.campbellsci.com/19_1_9999_169

You could download the trial to create some programs. Just be sure to wrap everything up before the 30 days is up.


Ken Conner May 30, 2012 06:20 PM

CRBasic Editor comes with LoggerNet and PC400, which are both pieces of software that you purchase. There is a free 30 trial of LoggerNet available for download at:

https://www.campbellsci.com/19_1_9999_169

You could download the trial to create some programs. Just be sure to wrap everything up before the 30 days is up.


joshdr83 May 30, 2012 07:55 PM

I have started working with this and have managed to use LoggerNet to get the program to the CR1000.

Is there any way that the above code could be commented for me? I am trying to understand what it does and when it sends a file out, thanks.


Ken Conner May 30, 2012 08:38 PM

Hope this helps. The CRBasic editor also contains useful information and example programs.

'Define public variables - these are temporary memory locations with names that can be accessed by the program
Public PTemp 'This variable will store values for the data loggers panel temperature
Public batt_volt 'This variable will store values for the data loggers power supply
Public Outstat 'This variable will store the value for the result of the TableFile instruction
Public LastFileName As String * 30 'This is a variable, defined as a string, that will store the name of the last file created by the TableFile instruction

'Define constants - these are values with names that can be accessed by the program, but cannot be changed
Const ServerIP = "192.168.0.1" 'This is the address of the FTP server that you want to send files to
Const User = "Admin" 'This is the user name needed to login to the FTP server
Const Password = "Admin" 'This is the password needed to login to the FTP server
Const DestPath = "/Site1/Data/OneMin" 'This is the destination directory where the FTP'ed file will be saved on the FTP server

'Setup Data tables for final storage of data
DataTable (Test,1,-1) 'This is a data table called Test
DataInterval (0,60,Sec,10) 'This instruction causes the logger to create a new data record every 60 seconds
TableFile ("USR:OneMinData",8,-1,0,24,Hr,Outstat,LastFileName) 'This instruction makes the logger take all the data records created in this data table over the last 24 hours and write them to the USR drive as a single file
Minimum (1,batt_volt,FP2,0,False) 'This instruction will cause the data logger to record the minimum battery voltage value from the last 60 measurements
Sample (1,PTemp,FP2) 'This instruction will cause the data logger to record the most recent panel temperature measurement made
EndTable

BeginProg
Scan (1,Sec,0,0) 'This program will execute once a second
PanelTemp (PTemp,250) 'Measure the dataloggers internal temperature sensor
Battery (batt_volt) 'Measure the dataloggers battery voltage

CallTable Test 'Check to see if it is time to create a new record in the data table called Test

If Outstat = -1 Then 'If the variable Outstat equals -1 then do then following. If Outstat doesn't equal -1 then do nothing
Outstat = 0 'Make Outstat = 0
FTPClient (ServerIP,User,Password,LastFileName,DestPath,2) 'Connect to the FTP server and send the latest file created with the TableFile instruction in the DataTable Test.
EndIf

NextScan
EndProg


aps May 31, 2012 08:34 AM

Just a couple of further tips, whilst the above program will work, when the datalogger comes to send the file by ftp the scan holding the FTPClient instruction will be held up until the file goes (which could be a long time if the file is big or there are connection issues). This may not be critical in your application, but generally I would advise putting the FTPClient code in a Slow Sequence which runs independently of the main scan. When you do this you have to be careful as to how you detect a file is ready to send, which then gets a bit more complicated.

BTW to allow the program above to work you need to allocate some of the datalogger memory to the USR drive to hold the files before transmission.

If this is looking too complicated, if you can hold off implementing this for a few weeks, we will shortly be releasing a new operating system for the main loggers that will greatly simplify this process and avoid the need for writing files to the USR drive. That simplification may eventually allow us to add this feature to Shortcut - but don't hold me to that.


joshdr83 May 31, 2012 06:20 PM

Andrew, thank you for the help, please help me do the following:

1. Assume that I just got the CR1000 and NL120 out of the box, no USR directory (can't find in manual how to make it).

2. I want to take the following code (it will eventually be expanded to use all 8 channels), made in shortcut:

-----------------------------------------------------
'CR1000
'Created by Short Cut (2.8)

'Declare Variables and Units
Public BattV
Public PSP1
Public PSP2

Units BattV=Volts
Units PSP1=mV
Units PSP2=mV

'Define Data Tables
DataTable(Table1,True,-1)
DataInterval(0,1,Min,10)
Average(1,BattV,FP2,False)
Average(1,PSP1,FP2,False)
Average(1,PSP2,FP2,False)
EndTable

'Main Program
BeginProg
Scan(1,Sec,1,0)
'Default Datalogger Battery Voltage measurement BattV
Battery(BattV)
'Generic Differential Voltage measurements PSP1
VoltDiff(PSP1,1,mV25,1,True,0,_60Hz,109.769,0)
'Generic Differential Voltage measurements PSP2
VoltDiff(PSP2,1,mV25,2,True,0,_60Hz,107.936,0)
'Call Data Tables and Store Data
CallTable(Table1)
NextScan
EndProg

-------------------------------------------

3. Every night at 2 a.m. I want to have the CR1000+NL120 to push a data file, with a timestamped file name, of the past 48 hours of data to an FTP site.

4. I don't want to lose any data as mentioned possible in the post above.


aps Jun 1, 2012 11:42 AM

The program below will do most everything you want. However, it only outputs the last 24 hours data every 24 hours not 48 hours worth of data. (The latter could be done but would involve merging two files which gets complicated due to the headers) It also tries to send the file up to 3 times until successful.

This should work but I have not tried it live. You may get an error the first time you load it as the USR drive it defined within the program to it takes one run before this is set correctly.

I hope this is beneficial to all to see the principles - there are other examples in the CRBasic help.

As I mentioned before this will become a little simpler in the next release of logger operating system although the option to timestamp files, which is already on the wish list, may be a version later.

--
'CR1000
'Created by Short Cut (2.8)

'Declare Variables and Units
Public BattV
Public PSP1
Public PSP2

'Define public variables - these are temporary memory locations with names that can be accessed by the program
Public Outstat As Boolean, Sendit As Boolean, SentOK As Boolean, tries 'These variables control the ftp process
Public LastFileName As String * 30 'This is a variable, defined as a string, that will store the name of the last file created by the TableFile instruction
Public Newfilename As String *50 'holds the timestamped destination filename

'Define constants - these are values with names that can be accessed by the program, but cannot be changed
Const ServerIP = "192.168.0.1" 'This is the address of the FTP server that you want to send files to
Const User = "Admin" 'This is the user name needed to login to the FTP server
Const Password = "Admin" 'This is the password needed to login to the FTP server
Const DestPath = "/Site1/Data/Onemin" 'This is the destination directory where the FTP'ed file will be saved on the FTP server

Units BattV=Volts
Units PSP1=mV
Units PSP2=mV

'Define Data Tables
DataTable(Table1,True,-1)
DataInterval(0,1,Min,10)
'Every day at 2 am write a file of the last 24 hours data
TableFile ("USR:Onemin",8,-1,2,24,Hr,Outstat,LastFileName)
Average(1,BattV,FP2,False)
Average(1,PSP1,FP2,False)
Average(1,PSP2,FP2,False)
EndTable

'Main Program
BeginProg
SetStatus("UsrDriveSize","100000") 'Sets the USR drive size to 100k
Scan(1,Sec,1,0)
'Default Datalogger Battery Voltage measurement BattV
Battery(BattV)
'Generic Differential Voltage measurements PSP1
VoltDiff(PSP1,1,mV25,1,True,0,_60Hz,109.769,0)
'Generic Differential Voltage measurements PSP2
VoltDiff(PSP2,1,mV25,2,True,0,_60Hz,107.936,0)
'Call Data Tables and Store Data
CallTable(Table1)
'The following line sets a second variable the code in the slow sequence can monitor
'Checking Outstat is risky as it will get reset at the next run of the main scan
If Outstat Then
Sendit = true
tries=0
Newfilename = DestPath & " " & Public.TimeStamp(4,0) 'A quick way of generating a timestamp
Newfilename=Replace(Newfilename,":","") 'Get rid of the colons - not allowed in filenames
Newfilename=Newfilename &".dat" 'add a fixed suffix
EndIf
NextScan


SlowSequence 'Just to do the ftp without interferring with measurements.
Scan (1,min,3,0) 'Every minute check.
If Sendit Then
SentOK = FTPClient (ServerIP,User,Password,LastFileName,Newfilename,0)
tries=tries+1
If SentOK OR tries=3 Then Sendit=false
EndIf
NextScan


EndProg


joshdr83 Jun 1, 2012 03:34 PM

Thank you very much - I will see how this does over the weekend. I appreciate your patience with my lacking of experience.

If there seems to be a problem with checking Outstat, I will let you know.

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