Python/Add-On newbie want to control projector.

  Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Post Reply
darkscout Offline
Posting Freak
Posts: 2,145
Joined: Jul 2008
Reputation: 12
Post: #1
I'm looking at controlling my projector with XBMC. It has a horribly old web interface that magically only works in IE6. (The SSL is fubar, etc).

I finally figured out how to get it working through curl and I'd like to make it an addon. I tried System.Exec to run my bash script but it was not happy.

This is what I have right now:
Code:
#!/bin/bash
curl -k -silent https://10.0.0.162/index.html -d "DATA1=Administrator&DATA2" -o /dev/null
if [ "$1" = "on" ] ; then
    curl -k -silent https://10.0.0.162/admin/main.html -d "DATA1=Administrator&DATA2&D1=1&V1=1" -o /dev/null
fi
if [ "$1" = "off" ] ; then
        curl -k -silent https://10.0.0.162/admin/main.html -d "DATA1=Administrator&DATA2&D2=0&V2=1" -o /dev/null
fi
if [ "$1" = "xbmc" ] ; then
        curl -k -silent https://10.0.0.162/admin/main.html -d "DATA1=Administrator&DATA2&D3=3&V3=1" -o /dev/null
fi
if [ "$1" = "wii" ] ; then
        curl -k -silent https://10.0.0.162/admin/main.html -d "DATA1=Administrator&DATA2&D3=5&V3=1" -o /dev/null
fi

I'd like to make it so that my python script will take parameters on what I want the projector to do and wire that to the remote.xml so power will turn the projector on.

Thanks.

[Image: aeKO.jpeg]
Code:
GRANT ALL PRIVILEGES ON `xbmc_%`.* TO 'xbmc'@'%';
IF you have a mysql problem, find one of the 4 dozen threads already open.
find quote
giftie Offline
Skilled Python Coder
Posts: 2,362
Joined: Mar 2010
Reputation: 54
Location: Calgary, Alberta
Post: #2
Here is your bash script changed to python:

Code:
import subprocess, sys

if ( __name__ == "__main__" ):
    subprocess.call('curl', '-k', '-silent', 'https://10.0.0.162/index.html', '-d', '"DATA1=Administrator&DATA2"', '-o', '/dev/null')
    if sys.argv[ 1 ]:
        if sys.argv[ 1 ] == "on":
            subprocess.call('curl', '-k', '-silent', 'https://10.0.0.162/admin/main.html', '-d', '"DATA1=Administrator&DATA2&D1=1&V1=1"', '-o', '/dev/null')
        elseif sys.argv[ 1 ] == "off":
            subprocess.call('curl', '-k', '-silent', 'https://10.0.0.162/admin/main.html', '-d', '"DATA1=Administrator&DATA2&D2=0&V2=1"', '-o', '/dev/null')
        elseif sys.argv[ 1 ] == "xbmc":
            subprocess.call('curl', '-k', '-silent', 'https://10.0.0.162/admin/main.html', '-d', '"DATA1=Administrator&DATA2&D3=3&V3=1"', '-o', '/dev/null')
        elseif sys.argv[ 1 ] == "wii":
            subprocess.call('curl', '-k', '-silent', 'https://10.0.0.162/admin/main.html', '-d', '"DATA1=Administrator&DATA2&D3=5&V3=1"', '-o', '/dev/null')
        else:
            print "Argument not recognized"
    else:
        print "Argument not supplied"

Save this as 'projector.py' and store it in the temp folder in xbmc home folder.

To call the script, you need to issue the following command:

Code:
RunScript(special://temp/projector.py,command)
command = on, off, xbmc, wii

[Image: e4f63e45ba34fe4695b3bb08eb2499d8e4ee484e...4c076g.jpg]
For troubleshooting and bug reporting please make sure you read this first you can also use XBMC Log Uploader Script.
Cinema Experience
Cinema Experience Wiki
cdART Manager
fanart.tv


find quote
darkscout Offline
Posting Freak
Posts: 2,145
Joined: Jul 2008
Reputation: 12
Post: #3
Thanks. This rocks. Just some changes.

1) For some reason it couldn't find it in temp, I moved it to the 'home' folder. (.xbmc)
2) Some changes to python syntax.

Code:
import subprocess, sys

if ( __name__ == "__main__" ):
    if len(sys.argv)==2:
        subprocess.call(['curl', '-k', '-silent', 'https://10.0.0.162/index.html', '-d', 'DATA1=Administrator&DATA2','-o','/dev/null'])
        if sys.argv[ 1 ] == "on":
            subprocess.call(['curl', '-k', '-silent', 'https://10.0.0.162/admin/main.html', '-d', 'DATA1=Administrator&DATA2&D1=1&V1=1', '-o', '/dev/null'])
        elif sys.argv[ 1 ] == "off":
            subprocess.call(['curl', '-k', '-silent', 'https://10.0.0.162/admin/main.html', '-d', 'DATA1=Administrator&DATA2&D2=0&V2=1', '-o', '/dev/null'])
        elif sys.argv[ 1 ] == "xbmc":
            subprocess.call(['curl', '-k', '-silent', 'https://10.0.0.162/admin/main.html', '-d', 'DATA1=Administrator&DATA2&D3=3&V3=1', '-o', '/dev/null'])
        elif sys.argv[ 1 ] == "wii":
            subprocess.call(['curl', '-k', '-silent', 'https://10.0.0.162/admin/main.html', '-d', 'DATA1=Administrator&DATA2&D3=5&V3=1', '-o', '/dev/null'])
        else:
            print "Argument not recognized"
    else:
        print "Argument not supplied"

[Image: aeKO.jpeg]
Code:
GRANT ALL PRIVILEGES ON `xbmc_%`.* TO 'xbmc'@'%';
IF you have a mysql problem, find one of the 4 dozen threads already open.
find quote