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.

CR6 HikVision Camera


GeoffreyCarlin Jun 1, 2019 04:58 AM

I have previously used a 4 M pixel FOSCAM camera to capture images with a CR6 and store them on the installed SD card. With the following code this works fine as the FOSCAM has built-in CGI scripts.

'Camera variables
Public CamURI As String * 80 = "192.168.1.110:88/cgi-bin/CGIProxy.fcgi?cmd=snapPicture2&usr=admin&pwd=password2"
Public CamPicExt As String * 40 = "CamPic.jpg"
Public Status
Public CameraOn As Boolean
Public CameraTimeOn = 0
Public PicNameString As String * 100
Public URIString As String * 100

...

 'Store the Dataloggers realtime in array rstime
RealTime(rsTime())
Sprintf (PicNameString, "CRD:%04.0f%02.0f%02.0f%02.0f%02.0f%02.0f"+CamPicExt, sYear, sMonth, sDOM, sHour, sMinute, sSecond )
URIString = "http://" + CamURI
Status = HTTPGet (URIString, PicNameString, "")
... 

I would like to do the same with an 8M HikVision again just capturing an image when required.

In the code above the URIString becomes:

"http://admin:Password1@192.168.1.110:88/Streaming/channels/1/picture"

Rather than return an image, the following HTML is returned within the .jpg file.

<!DOCTYPE html>
<html><head><title>Document Error: Unauthorized</title></head>
<body><h2>Access Error: 401 -- Unauthorized</h2>
<p>Authentication Error: Your client does not have permission to get URL /Streaming/channels/1/picture from this server.</p>
</body>
</html>

It seems the camera does not accept the username password format as presented but this does work in a browser. Camera and CR6 and both connected to the same router.

Any ideas appreciated. 


ryan42 Jun 3, 2019 12:49 AM

Try adding a header to your HTTPGet with the base64 encoded username and password

https://www.blitter.se/utils/basic-authentication-header-generator/


GeoffreyCarlin Jun 3, 2019 01:10 PM

Thanks for the reply and thanks also to Florent, CSI Townsville.

I tried adding the header but this also failed. I then went through all the camera settings and it turns out under

"System", "Security", "Authentication" both RTSP and WEB need to be set to "digest/basic".

Also found you need to go to

"Network",  "Advanced Settings", "Integration Protocol" and enable "Enable Hikvision-CGI" and set "Hikvision-CGI Authentication..." also to "digest/basic" 

Then both this 

"http://admin:Password1@192.168.1.110:88/Streaming/channels/1/picture"

and a header version work

http_header = "Authorization: Basic YWRtaW46UGFzc3dvcmQx"
http_header = http_header + CHR(13) + CHR(10)
Status = HTTPGet (URIString, PicNameString, http_header)

Complete code if interested...

'Declare Public Variables
'Example:
Public PTemp, batt_volt
Public CamPicExt As String * 40 = "SLCamPic.jpg"
Public TakePic As Boolean = True
'Period to take picture in Minutes (ie 60 take picture every hour)
Public TakeDailyPicTime As Long = 60
'Public UpdateCamDisplay 'used to update daily time and date
Public Status
Public CameraTimeOn = 0
Public PicNameString As String * 100
Public http_header As String * 100

'rsTime is used to store the data loggers current real time within the camera subroutine
Public rsTime(9) 'declare as public and dimension rTime to 9
Alias rsTime(1) = sYear 'assign the alias Year to rTime(1)
Alias rsTime(2) = sMonth 'assign the alias Month to rTime(2)
Alias rsTime(3) = sDOM 'assign the alias Day to rTime(3)
Alias rsTime(4) = sHour 'assign the alias Hour to rTime(4)
Alias rsTime(5) = sMinute 'assign the alias Minute to rTime(5)
Alias rsTime(6) = sSecond 'assign the alias Second to rTime(6)
Alias rsTime(7) = suSecond 'assign the alias uSecond to rTime(7)
Alias rsTime(8) = sWeekDay 'assign the alias WeekDay to rTime(8)
Alias rsTime(9) = sDay_of_Year 'assign the alias Day_of_Year to rTime(9)

'Declare Other Variables
'Example:
'Dim Counter

'Define Data Tables.
DataTable (Test,1,-1) 'Set table size to # of records, or -1 to autoallocate.
DataInterval (0,60,Sec,10)
Minimum (1,batt_volt,FP2,False,False)
Sample (1,PTemp,FP2)
EndTable

'Define Subroutines
'Sub
'EnterSub instructions here
'EndSub


'Main Program
BeginProg
Scan (10,Sec,0,0)
PanelTemp (PTemp,15000)
Battery (batt_volt)
CallTable Test
NextScan

'Slowsequence for taking a daily and manual picture
SlowSequence
Scan (1,Min,3,0)

'Take a image each day at the start of a TakeDailyPicTime interval or if TakePic is true
If IfTime (0,TakeDailyPicTime,min) OR (TakePic) Then
http_header = ""
Timer(1,Sec,2) 'Reset and Start Timer
SW12(2,1) 'switch camera on assumes camera is powered via switch 2

'Create a filename that include the date time
RealTime(rsTime())
Sprintf (PicNameString, "CRD:%04.0f%02.0f%02.0f%02.0f%02.0f%02.0f"+CamPicExt, sYear, sMonth, sDOM, sHour, sMinute, sSecond )

'http header info
' Header will only work if Camera user name is "admin" and password is "Password1"
' To encode a new password go to https://www.base64encode.org/ then type in admin:Password1
' or use https://www.blitter.se/utils/basic-authentication-header-generator/
http_header = "Authorization: Basic YWRtaW46UGFzc3dvcmQx"
http_header = http_header + CHR(13) + CHR(10)

Status = HTTPGet (URIString, PicNameString, http_header)
Delay (1,10,Sec) 'Allow processing to take place (could be less)
CameraTimeOn = CameraTimeOn + Timer(1,Sec,4) ' Read the timer
SW12(2,0)
'TakePic = False
EndIf
NextScan
EndSequence

EndProg

also works changing the URIString to

Const URIString = "http://admin:Password1@192.168.1.110:88/Streaming/channels/1/picture"

and commenting out or deleting the lines

http_header = "Authorization: Basic YWRtaW46UGFzc3dvcmQx"
http_header = http_header + CHR(13) + CHR(10)

Note: in the example above the camera's username is "admin" and password is set to "Password1"

Hardware: Camera is a DS-2CD2085FWD-I (8MP outdoor bullet camera), both camera and CR6 are connected to the same router being a Intercel Ultra eSAM.


Kony Nov 2, 2023 03:27 AM

This post is under review.

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