Notice: This forum has been recovered from an old backup, so some content, links, and dates may be outdated. The forum is currently read-only while we restore sign-in and registration functionality. Details

If you find this forum valuable and would like to help keep it online, donations to help cover hosting and domain costs are greatly appreciated, but never expected. You can support the forum through Buy Me a Coffee or Ko-fi. Thank you for helping preserve the EventGhost community.

Wireless IP Camera Pan and Tilt

If you have a question or need help, this is the place to be.
Post Reply
loveleejohn
Experienced User
Posts: 133
Joined: Thu Dec 10, 2015 12:09 am

Wireless IP Camera Pan and Tilt

Post by loveleejohn »

Hey everyone!! First post!! :D ...and sadly it's gonna be huge! :oops: Sorry about that...
First I want to say a huge thank you to the author of this software and all of you who have contributed with tips and plugins which really helps newbs like me to get up to speed pretty quickly!

Now for the question. I'm trying to control my wireless IP camera from eventghost but so far I am running into a ton of trouble trying to use the urlopen methods in a python script. For some reason when I try to execute the following code to make an HTTP reguest with the encoded url that I got from the camera's API I get errors. This is the format of the camera's encoded URL, (http://IP:PORT/decoder_control.cgi?command=33&onestep=&user=NAMEOFUSER&pwd=SECRETPASSWORD) This works fine in any browser and returns an "ok" message which I have no use for and then promptly moves the camera to the desired preset view. The trouble is that this url is not working in my Python script nor my Powershell script. :(

:::Python Script:::
import urllib
urllib.urlopen('http://IP:PORT/decoder_control.cgi?command=33&onestep=&user=NAMEOFUSER&pwd=SECRETPASSWORD')
:::END Python Script:::

This is the error I am getting back.

:::Errors that appear in Eventghost log:::
15:43:13 Traceback (most recent call last):
15:43:13 Python script "2", line 2, in <module>
15:43:13 urllib.urlopen('http://IP:PORT/decoder_control.cgi?command=33&onestep=&user=NAMEOFUSER&pwd=SECRETPASSWORD')
15:43:13 File "urllib.pyc", line 86, in urlopen
15:43:13 File "urllib.pyc", line 205, in open
15:43:13 File "urllib.pyc", line 360, in open_http
15:43:13 File "urllib.pyc", line 373, in http_error
15:43:13 File "urllib.pyc", line 688, in http_error_401
15:43:13 File "urllib.pyc", line 752, in retry_http_basic_auth
15:43:13 File "urllib.pyc", line 781, in get_user_passwd
15:43:13 File "urllib.pyc", line 792, in prompt_user_passwd
15:43:13 File "getpass.pyc", line 95, in win_getpass
15:43:13 TypeError: putch() argument 1 must be char, not unicode
:::End Error Log:::
I am on a Windows 7 64 bit computer and i am running Version 0.4.1.r1710.

Not being one to give up easily I have also tried

:::Python Script:::
import urllib2
urllib2.urlopen('http://IP:PORT/decoder_control.cgi?command=33&onestep=&user=NAMEOFUSER&pwd=SECRETPASSWORD')
:::END Python Script:::

I then decided to see if I could force this to happen with a powershell script.

:::Powershell Script:::
$IE=new-object -com internetexplorer.application
$IE.navigate2("http://IP:PORT/decoder_control.cgi?command=33&onestep=&user=NAMEOFUSER&pwd=SECRETPASSWORD")
$IE.visible=$false
Start-Sleep -s 10
Clear-Host
Get-Process iexplore | Stop-Process
:::End Powershell Script:::

Keep that script for your records by the way if you're learning powershell like I am! It's a really great way to run a program hidden. The only problem is that this method pops up an ugly Windows Security Window where I am forced to click ok to continue. I tried doing this with wshell within the script but it was messy and failed horribly...

Another issue with the powershell script is that I had to use the direct path to powershell.exe in my system directory and then put my script as a commandline parameter when I tried to run it as an application in eventghost. An extra step, but not the end of the world. Sadly when I tried to execute the powershell script in this way nothing happens. No error messages appear in the log of eventghost either so I'm not quite sure what's going on there.

Did I say this has been almost a 2 week journey? Lol. Anyways. If any of you could possibly point me in the right direction I would be forever grateful. I have a feeling that I am not writing my python code correctly but in addition to this there seems to be an additional login window that is asking for the user name in eventghost everytime I attempt to use the python method which I am confused about since the login information is already hard coded in the URL. Any ideas?
loveleejohn
Experienced User
Posts: 133
Joined: Thu Dec 10, 2015 12:09 am

Re: Wireless IP Camera Pan and Tilt

Post by loveleejohn »

Well I finally got this working. :D Perhaps I just had to post my question in order to clarify the issue in my own mind? Lol. At any rate. I was able to get this to work with curl. If any of you have any tips or pointers as to why my python script did not work, that would be very helpful for my learning! Thanks. :)
kkl
Experienced User
Posts: 317
Joined: Wed May 04, 2011 9:32 pm

Re: Wireless IP Camera Pan and Tilt

Post by kkl »

I don't know. Your syntax worked fine for me. Perhaps your password has some special character that is causing the parser to think it is unicode?
loveleejohn
Experienced User
Posts: 133
Joined: Thu Dec 10, 2015 12:09 am

Re: Wireless IP Camera Pan and Tilt

Post by loveleejohn »

kkl wrote:I don't know. Your syntax worked fine for me. Perhaps your password has some special character that is causing the parser to think it is unicode?
Hey there kkl! Thanks so much for the response! I wondered that also but I don't think the password could be the issue because I've been using a plain password with no special characters while testing this python code. :(
loveleejohn
Experienced User
Posts: 133
Joined: Thu Dec 10, 2015 12:09 am

Re: Wireless IP Camera Pan and Tilt

Post by loveleejohn »

Not sure if this means anything to you or anyone else who may be able to help kkl but the errors have changed a little when I try to run the first version of the python script I've posted above.

:::Python Error shown in Eventghost Logs:::
1:03:50 Error compiling script.
01:03:50 Traceback (most recent call last):
01:03:50 SyntaxError: invalid syntax (9, line 2)
:::End of Log:::

This is the error I've been getting back. :( I'd appreciate it if anyone can give me some insight in regards to where I am going wrong.
kkl
Experienced User
Posts: 317
Joined: Wed May 04, 2011 9:32 pm

Re: Wireless IP Camera Pan and Tilt

Post by kkl »

Have you tried starting with a blank EG configuration and adding only your Python script and nothing else?
loveleejohn
Experienced User
Posts: 133
Joined: Thu Dec 10, 2015 12:09 am

Re: Wireless IP Camera Pan and Tilt

Post by loveleejohn »

kkl wrote:Have you tried starting with a blank EG configuration and adding only your Python script and nothing else?
Hi again kkl! Thanks so much for responding. That was a great idea that I missed. I'll give it a quick try.
loveleejohn
Experienced User
Posts: 133
Joined: Thu Dec 10, 2015 12:09 am

Re: Wireless IP Camera Pan and Tilt

Post by loveleejohn »

SUCCESS AT LAST!!! kkl!! Thank you so much for encouraging me to clean the slate to test my script. I think it cleared my brain which is exactly what I needed. I was able to get the camera to rotate using the following format.

import urllib; urllib.urlopen('http://USERNAME:SECRETPASSWORD@IPADDRESS:PORT/decoder_control.cgi?command=11&onestep=?&user=USERNAME&pwd=SECRETPASSWORD&next_url=?')

The secret was to throw the username and password at the start of the cgi command aas well as near the end instead of just encoding it at the end of the URL. I surely hope this information will help someone who reads this post in the future to avoid the same pitfalls. Thanks so much kkl for being kind enough to throw a few ideas at me. Sometimes that's all it takes. :D
kkl
Experienced User
Posts: 317
Joined: Wed May 04, 2011 9:32 pm

Re: Wireless IP Camera Pan and Tilt

Post by kkl »

I'm glad you got it worked out.
Post Reply