Thread Rating:
  • 0 Vote(s) - 0 Average
Python/Add-On newbie want to control projector.
#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
Code:
GRANT ALL PRIVILEGES ON `xbmc_%`.* TO 'xbmc'@'%';
IF you have a mysql problem, find one of the 4 dozen threads already open.
Reply
#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
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


Reply
#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
Code:
GRANT ALL PRIVILEGES ON `xbmc_%`.* TO 'xbmc'@'%';
IF you have a mysql problem, find one of the 4 dozen threads already open.
Reply
 
Thread Rating:
  • 0 Vote(s) - 0 Average



Logout Mark Read Team Forum Stats Members Help
Python/Add-On newbie want to control projector.00