I have been using wget and a combination of batch files and vbscript to pull images from a few Axis 2100 network cameras. Everything is working fine, but I would like to get rid of wget and use a pure vbscript solution to grab and store images. I found a starter-script on the web and modified it to suit my needs:
URL="http://10.10.220.100/axis-cgi/jpg/image.cgi"
TEMPPATH = "C:\temp\"
outputfile= "C:\Program Files\HouseBot\Config\images\garage.jpg"
const ForReading = 1 , ForWriting = 2 , ForAppending = 8
Set fsoMain = CreateObject("Scripting.FileSystemObject")
Set objHTTP = CreateObject("WinHttp.WinHttpRequest.5.1")
Set fsResults = fsoMain.OpenTextFile(OUTPUTFILE,ForWriting, True)
Call objHTTP.Open("GET", url, FALSE)
objHTTP.Send
for i = 1 to lenb(objHTTP.ResponseBody)
fsResults.write Chr(Ascb(midb(objHTTP.ResponseBody,i,1)))
Next
fsResults.Close()
This works, but is painfully slow. On average it will take 5-10 seconds to grab an image and write it to the disk. By comparison, wget will perform the same operation in less than 1 second. Processor utilization will also spike up pretty high while the script is running. I know I'm trying to fix something that isn't broken...but... does anyone have any suggestions for speeding up this process using only vbscript?
Dim URL
Dim File
Dim xmlHTTP
Dim ADOStream
URL = "http://www.goes.noaa.gov/GIFS/ECI8.JPG"
File = "C:\Test.JPG"
Set xmlHTTP = CreateObject("MSXML2.XMLHTTP")
Call xmlHTTP.Open("GET", URL, False)
xmlHTTP.Send()
Set ADOStream = CreateObject("ADODB.Stream")
With ADOStream
.Type = 1
.Open()
.Write(xmlHTTP.responseBody)
.SaveToFile File, 2
.Close()
End With
Set ADOStream = Nothing
Set xmlHTTP = Nothing
I am having a small issue that this script does not seem to get the latest image, i had it running every 5 seconds for 2 days and it did not update the image every 5 seconds, it looked more like every 4 hours.
On the property that's storing the path to your image - make sure you have checked "Allow same value changes". That's usually the problem when you expect something to be updating in housebot and it isn't.
For some reason it just will not update... i told it to create a new file every 30 mins and it just doesn't want to update every time. After a few hours it finally changes images but that's it.
If i visit the cameras address say 192.168.1.1/img.jpg it works every time.
I have tried leaving hte video web page up and that did not help.
Any ideas?
UPDATE:
Restarting housebot allows it to capture the correct image once. after that it never get the image a second time.
Raptor
What type of machine is the software remote running on that you are using to view the images? I have issues with dynamic images on some of my devices that rdp into the server to access the software remote. Do the images show when you run the software remote on an actual PC (i.e., no rdp involved)?
Also, change the interval to 1 minute and ensure that the image in the theme folder is actually changing like you expect it to.
Paste the script you're using here along with any relevant screenshots of the HB device/task that's executing the script. Perhaps that will help to shed some light on the problem.
Dim URL
Dim File
Dim xmlHTTP
Dim ADOStream
Dim Date1
Date1 = Day(Date)&"-"&Month(Date)&"-"&Year(Date)&"-"&hour(now)&"h"&minute(now)&"m"&second(now)
URL = "http://192.168.2.160/image.jpg"
File = "D:\shares\Photos\Security Cam\Security-"&Date1&".jpg"
Set xmlHTTP = CreateObject("MSXML2.XMLHTTP")
Call xmlHTTP.Open("GET", URL, False)
xmlHTTP.Send()
Set ADOStream = CreateObject("ADODB.Stream")
With ADOStream
.Type = 1
.Open()
.Write(xmlHTTP.responseBody)
.SaveToFile File, 2
.Close()
End With
Set ADOStream = Nothing
Set xmlHTTP = Nothing
Ok, try this instead. I have not debugged it but it should alleviate two possible problems. The first is with Microsoft.xmlhttp. I have experienced some goofiness with this particular object in the past. I have used WinHTTP to do the heavy lifting in this script and then transfer the data to ADOStream to save the binary file. The second is that you have network congestion and the camera is unresponsive. The script will catch this (i.e., camera server does not return 200 after the request) and pop an error message. If this solves the problem, great. If you start getting pop-ups...we can fix that as well with a bit more work. [NOTE: my code has not been debugged....but it should be close]
Option Explicit
Dim URL
Dim File
Dim xmlHTTP
Dim ADOStream
Dim Date1
Date1 = Day(Date)&"-"&Month(Date)&"-"&Year(Date)&"-"&hour(now)&"h"&minute(now)&"m"&second(now)
URL = "http://192.168.2.160/image.jpg"
File = "D:\shares\Photos\Security Cam\Security-"&Date1&".jpg"
Set xmlHTTP = CreateObject("WinHttp.WinHttpRequest.5.1")
Call xmlHTTP.open ("GET", FullURL, False)
xmlHTTP.send()
Sleep(500)
If xmlHTTP.status = 200 Then
Set ADOStream = CreateObject("ADODB.Stream")
With ADOStream
Type = 1
Open()
Write(xmlHTTP.responseBody)
SaveToFile File, 2
Close()
End With
Set ADOStream = Nothing
Else
MsgBox "There was an error."
End If
Set xmlHTTP = Nothing
Option Explicit
Dim URL
Dim File
Dim xmlHTTP
Dim ADOStream
Dim Date1
Date1 = Day(Date)&"-"&Month(Date)&"-"&Year(Date)&"-"&hour(now)&"h"&minute(now)&"m"&second(now)
URL = "http://192.168.2.160/image.jpg"
File = "D:\shares\Photos\Security Cam\Security-"&Date1&".jpg"
Set xmlHTTP = CreateObject("WinHttp.WinHttpRequest.5.1")
Call xmlHTTP.open ("GET", URL, False)
xmlHTTP.send()
Sleep(500)
If xmlHTTP.status = 200 Then
Set ADOStream = CreateObject("ADODB.Stream")
With ADOStream
.Type = 1
.Open()
.Write(xmlHTTP.responseBody)
.SaveToFile File, 2
.Close()
End With
Set ADOStream = Nothing
Else
MsgBox "There was an error."
End If
Set xmlHTTP = Nothing
error:
Error 0 a connection withthe server could not be estabilished...
If you still are having touble getting your VB script to work may want to try AUTOHOTKEY. You can make scripts with it and also convert your scripts into .exe files (optional:which is what I do) and call them from HB. I use this to update wx images I pull off the web for example.
The UrlDownloadToFile command is what you need to pull your jpg off your IP camera at specified intervals.
Just a thought I would throw this out there as a possible solution.
BTW I have found that AUTOHOTKEY works very well along side HB. I also use it to control a SWRemtoe with a 2.4ghz $10 'presentation' remote designed to work with Powerpoint.
What is the task that fires the device? where is the mechanism to make it repeatedly fire? You should have a property in you device that is the path to the image. That property is the one that you will use to display the image in a swremote. That property should have the "Allow same value changes" checkbox checked is the image is being updated but always has the same filename. You should then have a task that executes that script at whatever interval you decide. An alternative to the task is to have the script loop forever, however if you do that remember to insert a "sleep x" (where x is the interval in milliseconds) in teh script loop to prevent the script fro consuming all of your resources.
Terry