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.

HTML Command from CR1000


Ehsan Jul 13, 2011 10:40 PM

I am using CR1000 to read height with laser measurs and then based on the height the program sends out an HTML command to two PTZ camera. However, I have not been able to correctly send the command and it seems the camera does not respond to the HTML command I'm creating in CRBasic. Would you kindly take a look at my program and make sure it is corrct. The idea would be to send this HTML command to the camera:

http://<url>/axis-cgi/com/ptz.cgi?pan=X&tilt=Y&speed=Z

Thanks

Program:

'Declare Variables and Units
Public Flag(4), Offset(2), Height_in(2), Height(2), HouseTemp(), Clearance
Public OpenFile1 As Long, WriteHeight As String * 35, CloseStat
Public URL(2) As String * 100
Public pan(4), tilt(4),speed
Public HTTPGetReq As String * 100
Public HTTPGetResp As String * 100
Public IPSocket

Dim i, j
Units Height=mV

'******Define Data Tables******************************
DataTable(Height,1,-1)
DataEvent (600,Height(1)>3,Height(1)<3,1500)
DataInterval(0,0,mSec,0)
Sample(2,Height,IEEE4)
EndTable

' DataTable(Display,1,-1)
' DataEvent (600,Height(1)>1,Height(1)<1,600)
' DataInterval(0,0,mSec,0)
' Sample(2,Height,IEEE4)'
' Sample (1,Clearance,FP2)
' Sample (4,Flag(),FP2)
' Sample (2,Height_in(),IEEE4)
' Sample (1,HouseTemp(),FP2)
' Sample (2,Offset(),IEEE4)
'EndTable

'*Sub-routine for zeroing measurements*********************
Sub HeightZero
Offset()=0
VoltDiff(Offset(),2,mV2500,1,True,0,_60Hz,0.0625,-25)
Flag(3) = False
EndSub

'********Main Program***********************************
BeginProg
'Flag(3)=True
Scan(200,mSec,1,0)

'*Define Camera URLs and Configs****************************
'PA Camera
URL(1)="192.168.24.35"
'NJ Camera
URL(2)="192.168.24.256"
speed=20
'PA Underside View Control
pan(1)= 10
tilt(1) = 50
'NJ Underside View Control
pan(2)= 10
tilt(2) = 50
'PA Seat View Control
pan(3)= 10
tilt(3) = 50
'NJ Seat View Control
pan(4)= 10
tilt(4) = 50

'Offset(1)=1.629
'Offset(2)=1.872

PanelTemp(HouseTemp(),_60Hz)
HouseTemp=HouseTemp*(9/5)+32

'Generic 4-20 mA Input measurement Height
VoltDiff(Height,2,mV2500,1,True,0,_60Hz,0.0625,-25)

If Flag(3)=True
Call HeightZero
EndIf

For i=1 To 2
Height(i)=Height(i)-Offset(i)
Next i

'*BEGIN PTZ CAMERA CONTROL**********************************
' ***** Underside View
If Height(1) > 10 Then
Flag (1)=True
For i=1 To 2
IPSocket=TCPOpen("http://"+URL(i),80,1024)
If IPSocket<>0 Then
HTTPGetReq = "GET /axis-cgi/com/ptz.cgi?pan=" + pan(i) + "&tilt=" + tilt(i) +"&speed=" + speed + " HTTP/1.1" + CHR(13)+CHR(10)
HTTPGetReq = HTTPGetReq+ "Host: http://"+ URL(i) + CHR(13)+CHR(10)
SerialOut(IPSocket,HTTPGetReq,"",0,0)
SerialIn(HTTPGetResp,IPSocket,500,"",100)
EndIf
Next i
' ***** Seat View
ElseIf Height(1)>3 AND Height(1)<10
Flag (2)=True
For i=1 To 2
IPSocket=TCPOpen("http://"+URL(i),80,1024)
If IPSocket<>0 Then
HTTPGetReq = "GET /axis-cgi/com/ptz.cgi?pan=" + pan(i+2) + "&tilt=" + tilt(i+2) +"&speed=" + speed + " HTTP/1.1" + CHR(13)+CHR(10)
HTTPGetReq = HTTPGetReq + "Host: http://" + URL(i) + CHR(13)+CHR(10)
SerialOut(IPSocket,HTTPGetReq,"",0,0)
SerialIn(HTTPGetResp,IPSocket,500,"",100)
EndIf
Next i
Else
Flag (1)=False
Flag (2)=False
EndIf
'***END PTZ CAMERA CONTROL******************************

' Call Data Tables and Store Data
If Height(1)<2 Then
Height_in(1)=Height(1)*12
Else
Height_in(1)=0
EndIf

If Height(2)<2 Then
Height_in(2)=Height(2)*12
Else
Height_in(2)=0
EndIf

Clearance=61+(.5*(Height(1)+Height(2)))

CallTable(Height)

NextScan
EndProg

* Last updated by: Ehsan on 7/13/2011 @ 4:42 PM *


Sam Jul 14, 2011 01:57 AM

One of the first things that jumps out at me is

HTTPGetReq = HTTPGetReq+ "Host: http://"+ URL(i) + CHR(13)+CHR(10)

should be

HTTPGetReq = HTTPGetReq+ "Host: "+ URL(i) + CHR(13)+CHR(10)

so that what is posted is something like

GET /axis-cgi/com/ptz.cgi?pan=10&tilt=10&speed=10 HTTP/1.1
Host: 192.168.24.35

If that doesn't do it for you, try adding the User-Agent field, so that you get something like

GET /axis-cgi/com/ptz.cgi?pan=10&tilt=10&speed=10 HTTP/1.1
Host: 192.168.24.35
User-Agent: CR1000

HTTPGetReq = "GET /axis-cgi/com/ptz.cgi?pan=" + pan(i) + "&tilt=" + tilt(i) + "&speed=" + speed + " HTTP/1.1" + CHR(13)+CHR(10)
HTTPGetReq = HTTPGetReq + "Host: "+ URL(i) + CHR(13)+CHR(10)
HTTPGetReq = HTTPGetReq + "User-Agent: CR1000" + CHR(13)+CHR(10)
HTTPGetReq = HTTPGetReq + CHR(13)+CHR(10)
SerialOut(IPSocket,HTTPGetReq,"",0,0)
SerialIn(HTTPGetResp,IPSocket,500,"",100)

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