Grabbing net cam images using vbscript only

General HouseBot discussion. Any issues that don't fit into any of the other topics belong here.
raptor_demon
Senior Member
Posts: 141
Joined: Tue Jul 07, 2009 12:55 pm
Location: NC

Re: Grabbing net cam images using vbscript only

Post by raptor_demon »

Hi Terry,

The task basically says when timer = 00:00 then run script.

However it is not working when i manually run the script and look at the file on the disk manually.

I have not yet put it into a swremote.

Raptor
Osler
HouseBot Guru
Posts: 742
Joined: Fri Feb 03, 2006 11:18 pm

Re: Grabbing net cam images using vbscript only

Post by Osler »

I am not sure that you are connecting to the server. The orignal script has no error checking, it assumes you connected and all is well.

Try using the CreateObject(msxml2.xmlhttp) in the new script I posted in place of WinHTTP and see what happens.

Osler
raptor_demon
Senior Member
Posts: 141
Joined: Tue Jul 07, 2009 12:55 pm
Location: NC

Re: Grabbing net cam images using vbscript only

Post by raptor_demon »

By server does it mean the Camera?
Osler
HouseBot Guru
Posts: 742
Joined: Fri Feb 03, 2006 11:18 pm

Re: Grabbing net cam images using vbscript only

Post by Osler »

yes

Osler
raptor_demon
Senior Member
Posts: 141
Joined: Tue Jul 07, 2009 12:55 pm
Location: NC

Re: Grabbing net cam images using vbscript only

Post by raptor_demon »

Hi,

no dice, i get the following error:
error msg
error msg
errorwednesady.jpg (10.55 KiB) Viewed 3453 times
Any ideas?


Terry, here are the tasks i have used:
task 1
task 1
task1.jpg (12.15 KiB) Viewed 3453 times
task2.jpg
task2.jpg (7.75 KiB) Viewed 3453 times
thanks for your help here guys....
raptor_demon
Senior Member
Posts: 141
Joined: Tue Jul 07, 2009 12:55 pm
Location: NC

Re: Grabbing net cam images using vbscript only

Post by raptor_demon »

ok, weird,

just messing with the code, breking it then putting it back it now works,

I think it is network traffic related....

Code: Select all

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
EDIT: Spoke too soon stopped again.
Osler
HouseBot Guru
Posts: 742
Joined: Fri Feb 03, 2006 11:18 pm

Re: Grabbing net cam images using vbscript only

Post by Osler »

Do you have a firewall on the server?

From the server, run the following script by simply double clicking it. Don't use HouseBot...just run the script:

Code: Select all

Option Explicit
On Error Resume Next

MsgBox "Script is starting."

Dim URL
Dim File
Dim xmlHTTP
Dim ADOStream
Dim Date1
Dim WshShell

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 WshShell = WScript.CreateObject("WScript.Shell")
Set xmlHTTP = CreateObject("MSXML2.XMLHTTP")

If Err.Number <> 0 Then
   MsgBox "There was a problem creating the objects. Error code: " & Err.Number
End If

MsgBox "Objects created."

Call xmlHTTP.open ("GET", URL, False)
xmlHTTP.send()

If Err.Number <> 0 Then
   MsgBox "There was a problem sending the HTTP request. Error code: " & Err.Number
End If

WScript.Sleep 500
If xmlHTTP.status = 200 Then

   MsgBox "Camera server reached successfully."

   Set ADOStream = CreateObject("ADODB.Stream")

   MsgBox "ADOStream object created."

   With ADOStream
         .Type = 1
         .Open()
         .Write(xmlHTTP.responseBody)
         .SaveToFile File, 2
         .Close()
   End With

   MsgBox "Image saved."

   Set ADOStream = Nothing
Else
   MsgBox "Camera server returned " & xmlHTTP.status & ". Unable to connect."
End If
Set xmlHTTP = Nothing
SetWshShell = Nothing
Click through the message boxes as the script runs and report back what happens.

Osler
roussell
Advanced Member
Posts: 268
Joined: Wed Dec 15, 2004 9:07 am
Location: Pelham, AL

Re: Grabbing net cam images using vbscript only

Post by roussell »

raptor_demon wrote:Hi,
Terry, here are the tasks i have used:
task1.jpg
task2.jpg
Is the 5 Second Timer Device set to Repeat? If not then that would explain why it only runs once...

Also, you may want to change the first line in the task from
If ('5 second timer.Remaining Time' is Equal '00:00')

to

If ('5 second timer.Running' is Equal 'No')

The remaining time property was a recent addition to the sleep device and while your logic is correct, perhaps HB is missing the 00 transition... Scott can answer that one. I know the "old schoolers" check for a running=no because when the timer hits zero and restarts, the running property momentarily transitions through Yes-No-Yes. It's a shot in the dark, but that's really the only difference between what you're doing and my scripts.

Terry
raptor_demon
Senior Member
Posts: 141
Joined: Tue Jul 07, 2009 12:55 pm
Location: NC

Re: Grabbing net cam images using vbscript only

Post by raptor_demon »

Hi Terry,

The sleep timer is set to repeat and I am getting images created every 5 seconds they are just identical.

Olser's new code seems to work sometimes iw ill do some more playing tonight....

Raptor
lostdreamer
Member
Posts: 54
Joined: Sat Apr 18, 2009 8:53 pm

Re: Grabbing net cam images using vbscript only

Post by lostdreamer »

Simple problem, simple solutions:

The problem with the images not refreshing is easy..... Cache settings in MSIE.
MSXML2.XMLHTTP uses MSIE to get the URL, with all of MSIE's cache settings.

2 simple options for using the VBS posted by ossler in the beginning of this topic:
1) Open MSIE, go to Extra -> Options -> Temp files and History and set it to "Every time I open a website"
2) Edit the vbs

Code: Select all

Call xmlHTTP.Open("GET", URL, False)
xmlHTTP.send()
Becomes:

Code: Select all

Call xmlHTTP.Open("POST", URL, False)
xmlHTTP.send "time="+ Now()
Sending the time with the POST data will make sure the result isn't from the cache.


Good luck,

LostDreamer
raptor_demon
Senior Member
Posts: 141
Joined: Tue Jul 07, 2009 12:55 pm
Location: NC

Re: Grabbing net cam images using vbscript only

Post by raptor_demon »

Osler wrote:Do you have a firewall on the server?

From the server, run the following script by simply double clicking it. Don't use HouseBot...just run the script:

Code: Select all

Option Explicit
On Error Resume Next

MsgBox "Script is starting."

Dim URL
Dim File
Dim xmlHTTP
Dim ADOStream
Dim Date1
Dim WshShell

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 WshShell = WScript.CreateObject("WScript.Shell")
Set xmlHTTP = CreateObject("MSXML2.XMLHTTP")

If Err.Number <> 0 Then
   MsgBox "There was a problem creating the objects. Error code: " & Err.Number
End If

MsgBox "Objects created."

Call xmlHTTP.open ("GET", URL, False)
xmlHTTP.send()

If Err.Number <> 0 Then
   MsgBox "There was a problem sending the HTTP request. Error code: " & Err.Number
End If

WScript.Sleep 500
If xmlHTTP.status = 200 Then

   MsgBox "Camera server reached successfully."

   Set ADOStream = CreateObject("ADODB.Stream")

   MsgBox "ADOStream object created."

   With ADOStream
         .Type = 1
         .Open()
         .Write(xmlHTTP.responseBody)
         .SaveToFile File, 2
         .Close()
   End With

   MsgBox "Image saved."

   Set ADOStream = Nothing
Else
   MsgBox "Camera server returned " & xmlHTTP.status & ". Unable to connect."
End If
Set xmlHTTP = Nothing
SetWshShell = Nothing
Click through the message boxes as the script runs and report back what happens.

Osler
Hi Osler,

This script ran without issue when running manually on the desktop however when running the same script in housebot i get an error 500followed by a object created. then a error 13 followed by a camera reached.

LostDreamer,

unfortualty your code produced images that were empty :(

Raptor
Osler
HouseBot Guru
Posts: 742
Joined: Fri Feb 03, 2006 11:18 pm

Re: Grabbing net cam images using vbscript only

Post by Osler »

You can't use WSHShell from within HouseBot. Delete all references to it in the script and change "WScript.Sleep" to simply "Sleep". I had to use the shell to get a sleep function outside of HouseBot....but HB has one built in.

Osler
raptor_demon
Senior Member
Posts: 141
Joined: Tue Jul 07, 2009 12:55 pm
Location: NC

Re: Grabbing net cam images using vbscript only

Post by raptor_demon »

Osler wrote:You can't use WSHShell from within HouseBot. Delete all references to it in the script and change "WScript.Sleep" to simply "Sleep". I had to use the shell to get a sleep function outside of HouseBot....but HB has one built in.

Osler
Thanks Osler,

this works great for the Netcam. For some reason tho it does not work well with my album art grab from the squeezebox server.

What did you change in the code?

Thanks
Raptor
Osler
HouseBot Guru
Posts: 742
Joined: Fri Feb 03, 2006 11:18 pm

Re: Grabbing net cam images using vbscript only

Post by Osler »

I didn't change anything...just made it so the script could run outside of HouseBot.

Post the URL for a album art grab from the squeezebox so I can take a look at it. How are you geting the albumarturi from the squeezebox?

Osler
raptor_demon
Senior Member
Posts: 141
Joined: Tue Jul 07, 2009 12:55 pm
Location: NC

Re: Grabbing net cam images using vbscript only

Post by raptor_demon »

Hi here is the url:

http://192.168.2.150:9500/music/current ... macaddress of player}

your script works perfectly if i use the url in MSIE and refresh it everytime but if i do not refreshi it the image never changes.....

I have set my MSIE settings to update the page everytime i visit as suggested by lost dreamer.

Any ideas?
Raptor
Post Reply