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.

possiblity to send data via HTTP Post


Arno Feb 16, 2012 09:20 AM

Hi,
I know, that sending data via http get works fine:
http://www.campbellsci.com/forum/messages.cfm?threadid=93BAB4F0-E0D2-5603-427B4E1477BE4CF1
But for a bigger number of data it’s not comfortable.
Have anyone an idea to realize sending data via http post.
At the Institute , how I work, its strongly recommended to send
data to a databank in this way. At the moment we send the data via ftp on a ftp-server .
And then the IT-Administration had to take over the data in the databank.
Sorry for my English.
Can anyone help me?
Thanks a lot


Sam Feb 16, 2012 03:53 PM

Arno,

When armed with TCPOpen(), TCPClose(), SerialOut/OutBlock(), SerialIn/InBlock(), FileOpen(), FileRead(), FileWrite(), and FileClose(), you have all the tools you need to POST via HTTP.

OS 24 for the CR800, CR1000, and CR3000 contained a few new instructions and many improvements related to IP communications.

https://www.campbellsci.com/70_103

Of particular note HTTP GET has been canned up.

Result = HTTPGet(URI,Response,Header)

where RESULT will be 100 or greater if successful, the URI parameter is a string that contains the address of the HTTP server, RESPONSE is either a variable for file name that will be written with the GET request results, and HEADER is a variable or constant for holding additional header information to send and header information returned.

The HTTPGet() instruction can be used to post or get data via HTTP. For example, the following could be used to retrieve an image from an IP camera and store it on the USR drive of the logger.

HTTPResult = HTTPGet("http://url.com/netcam.jpg", "USR:netcam.jpg", "")

We are also looking to release HTTPPost() in the next OS. To be honest, it is already in OS 24. Please remember that it is a beta. It has not been put through the ringer. Use at your own risk. With that said, I encourage you to try it in a non-production environment and provide us feedback. We can always use a guinea pig or two.

Syntax
Result = HTTPPost(URI,Content,Response,Header)

URI: Address of HTTP server.
Content: Variable or file name specifying content to send.
Response: Variable or file name where results will be written.
Header: Variable containing additional HTTP header that will get transmitted and HTTP header information returned in response


And to close ... Please remember that HTTPPost() is not officially released (as of OS 24). It is beta. It has not been put through the ringer. Use at your own risk.

* Last updated by: Sam on 2/16/2012 @ 8:57 AM *


Arno Feb 22, 2012 02:45 PM

Hello Sam,

thanks for answering so fast.
Now we have tried with HTTPPost.
We‘ve established a connection, but no datafile is send.

'Declare Public Variables
'Example:
Public PTemp, batt_volt
Public HTTPSuccess As Boolean, HTTPInit As Boolean, ModemOn As Boolean
Public LastFname As String * 32
Public OutStat
Public FileOut As String * 50
Public rTime(9) 'declare as public and dimension rTime to 9
Public Response As String

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) = DOM '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)
Alias rTime(7) = uSecond 'assign the alias uSecond to rTime(7)
Alias rTime(8) = WeekDay 'assign the alias WeekDay to rTime(8)
Alias rTime(9) = DOY 'assign the alias DOY to rTime(9)


'Define Data Tables
DataTable (Daten,1,-1)
DataInterval (0,5,Sec,10)
'Fill table always to full 5 minutes
TableFile("USR:Daten_",8,-1,0,5,Min,OutStat,LastFname)
Minimum(1,batt_volt,FP2,0,False)
Sample(1,PTemp,FP2)
EndTable

'Main Program
BeginProg

'Turn off modem
SW12 (0)
ModemOn=False
HTTPInit=False

'Measurement scan is 5 seconds
Scan (5,Sec,0,0)
PanelTemp (PTemp,250)
Battery (batt_volt)
CallTable Daten
If OutStat<>0 Then
RealTime(rTime)
Second=0
HTTPInit=True
EndIf
NextScan

SlowSequence
'Slow scan is 1 minute
'switch modem on as soon as file is available
'transmit file one minute later
'turn modem off after transmission
Scan (1,min,0,0)
If HTTPInit Then
If ModemOn Then
FileOut=Trim("Daten" & Trim(FormatFloat(Year,"%04.00f")) & Trim(FormatFloat(DOY,"%03.00f")) & Trim(FormatFloat(Hour,"%02.00f")) & Trim(FormatFloat(Minute,"%02.00f")) & Trim(FormatFloat(Second,"%02.00f")) & ".dat")
HTTPSuccess = HTTPPost("http://hostname/vpn/index.php?logger_type=campbell&ID=HOHOLZ0001&dateiname=" & LastFname,LastFname,Response,"")
EndIf
If NOT ModemOn Then
'Turn on modem
SW12 (1)
Delay (0,10,Sec)
ModemOn=True
EndIf
If HTTPSuccess Then
'Turn off modem
SW12 (0)
ModemOn=False
HTTPSuccess=False
HTTPInit=False
EndIf
EndIf
NextScan

EndProg

The original hostname is replaced by “hostname”.
We tryed to send a file with data, which is defined in "LastFname". This File exists on the local storage.
But there is no file/content in the variable $_FILES at the PHP Script.

Following information where delived to the server script:

$_REQUEST-Variable:

Array
(
[logger_type] = campbell
[ID] = HOHOLZ0001
[dateiname] = USR:Daten_91.dat
)

$_FILES-Variable:

Array
(
)


Can you have a look on it? What do we wrong?
Thanks and greetings,
Arno


GaryTRoberts Feb 25, 2012 12:03 AM

I assume that you are using enctype="multipart/form-data" in the form in index.php. If you are the following code shows you what you need to modify in HTTPPost's header string and the data in LastFname to get it to work.

file_handle = FileOpen ( LastFname, "r", 0 )
FileRead (file_handle, file_content, 1400) ' 1400 being the size of the file in bytes
FileClose (file_handle)

http_post_header = "Content-Type: multipart/form-data; boundary=CSI---------Boundary---------CSI" + CHR(13) + CHR(10)

file_content_2 = file_content_2 + "--" + "CSI---------Boundary---------CSI" + CHR(13) + CHR(10)
file_content_2 = file_content_2 + "Content-Disposition: form-data; name=" + CHR(34) + "file" + CHR(34) + "; filename=" + CHR(34) + LastFname + CHR(34) + CHR(13) + CHR(10)
file_content_2 = file_content_2 + "Content-Type: application/octet-stream" + CHR(13) + CHR(10)
file_content_2 = file_content_2 + CHR(13) + CHR(10)
file_content_2 = file_content_2 + file_content + CHR(13) + CHR(10)
file_content_2 = file_content_2 + "--" + "CSI---------Boundary---------CSI" + CHR(13) + CHR(10)
file_content_2 = file_content_2 + "Content-Disposition: form-data; name=" + CHR(34) + "submit" + CHR(34) + CHR(13) + CHR(10)
file_content_2 = file_content_2 + CHR(13) + CHR(10)
file_content_2 = file_content_2 + "Submit"+ CHR(13) + CHR(10)
file_content_2 = file_content_2 + "--" + "CSI---------Boundary---------CSI" + "--" + CHR(13) + CHR(10)

HTTPPost ("http://hostname/vpn/index.php?logger_type=campbell&ID=HOHOLZ0001&dateiname=" & LastFname", file_content_2, Response, http_post_header)

That is just a good guess at what you might be doing. You will have to modify it to fit your form..I hope that will give you an idea of what you need to do.

Some of what is done can be explained by http://www.faqs.org/rfcs/rfc1867.html and http://www.htmlcodetutorial.com/forms/form_enctype.html.

-Gary

* Last updated by: GaryTRoberts on 2/25/2012 @ 1:49 PM *

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