Page 1 of 1

A simple IP camera integration

Posted: Tue Aug 19, 2008 3:10 pm
by menesi
There is an "old wish from HouseBot": how can we integrate our security (or any other) cams. Formats of streams of this cams, or its DVR-s are not implemented (yet) in Software Remote. In HB there are simple or not too simple ways to take control of DVR's, recording of streams, camera event integration with alarm system (DSC in my house), etc., but the live view of cams...

We have three AXIS 211A IP camera and here is the simple, but working solution for the live view:

These cams have "Still Image" service over the streams. These still images are normal JPG files, which are suitable with Software Remote. I've created a Script Device per cams with three properties: CamIP for IP address of that cam, CamFrameSpeed for the changing frequency of images and CamDisplayedFrame for image, which is displayed in software remote panel (the Allow Same Value Changes option has to be checked). On panel I've created a dinamic image control pointed to this script device and it's CamDisplayedFrame property. The script:

Code: Select all

' ------------------------------------------------------------------------------------------
'
'	File:	CameraHandler.vbs
'	Author:	Ménesi László
'	Desc:	
'	Usage:
'
' ------------------------------------------------------------------------------------------

Option Explicit
On Error Resume Next

Dim iFrameSpeed
Dim strCamIP, strCamLocalFile


	strCamIP = GetPropertyValue ("Camera 1.CamIP")
	strCamLocalFile = "C:\Program Files\HouseBot\Config\Themes\Touch_800x600\Cam1.jpg"

	Do
	
		iFrameSpeed = GetPropertyValue ("Camera 1.CamFrameSpeed")

		DownloadFrame "http://" & strCamIP & "/jpg/image.jpg", strCamLocalFile
		SetPropertyValue "Camera 1.CamDisplayedFrame", strCamLocalFile

		Sleep (CInt (iFrameSpeed))
	
	Loop
	


Sub DownloadFrame (strImageURL, strLocalFile)

Dim objHTTP
Dim objStream
Dim iNumber

	
	Set objHTTP = CreateObject("Microsoft.XMLHTTP")
	objHTTP.Open "GET", strImageURL, False
	objHTTP.Send
	iNumber = 0
	Do
		If objHTTP.readyState=4 Then
			Exit Do
		End If
		If iNumber=12 Then
			Exit Sub
		End If
		iNumber = iNumber + 1
		Sleep(20)
	Loop
	
	Set objStream = CreateObject("ADODB.Stream")

	objStream.Type = 1     '   1 = Binary Type
	objStream.Open
	objStream.Write objHTTP.responseBody

	objStream.SaveToFile strLocalFile, 2    '    2 = Create and overwrite a file if it already exists

	objStream.Close

	Set objStream = Nothing 
	Set objHTTP = Nothing
		
End Sub

' ------------------------------------------------------------------------------------------
State of script device is setted to "Running" by Enter List and "Stopped" by Exit List of panel. This method is not too good for more software remotes running at the same time, at this case have to find the another mode.

Thats all.

Re: A simple IP camera integration

Posted: Tue Jul 14, 2009 12:36 pm
by raptor_demon
Wow,

My virus scanner goes nuts when i try to paste this.... very odd.
it shows Generic.XPL.ADODB.DA9FC345
Raptor

Re: A simple IP camera integration

Posted: Tue Jul 21, 2009 7:36 am
by menesi
Virus alert?? It's only a simple Visual Basic script... I've no idea.