[ANSWERED]Control Indigo from outside the system

Posted on
Thu Jul 17, 2014 7:56 am
robertgerman offline
Posts: 42
Joined: Dec 14, 2013
Location: Vaxjo, Sweden

[ANSWERED]Control Indigo from outside the system

Hi Guys,
I would like to send a command to my indigo server from a website to trigger an action group. Since I can't have mutiple users on the control pages I need a way to gain access for some users via a login page on my web server that send commands to Indigo. How do I do it?

Rob

Posted on
Thu Jul 17, 2014 9:50 am
jay (support) offline
Site Admin
User avatar
Posts: 18221
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Control Indigo from outside the system

The best solution for you is to use the RESTful API to communicate with Indigo. You'll need to authenticate of course - the Indigo Server uses HTTP digest authentication so you should be able to do that via whatever you're using on your web server.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Thu Jul 17, 2014 10:45 am
robertgerman offline
Posts: 42
Joined: Dec 14, 2013
Location: Vaxjo, Sweden

Re: [ANSWERED]Control Indigo from outside the system

Thanks Jay!

Now the tricky part, how will I actually implement it, though? I read about HTTP digest auth, but didn't understand much of how to make it work. Do you have a step by step guide?

Thanks!
Rob

Posted on
Thu Jul 17, 2014 1:40 pm
FlyingDiver offline
User avatar
Posts: 7222
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: [ANSWERED]Control Indigo from outside the system

You're going to need to create a web page on the website that authenticates your users and then has buttons or whatever for the commands you want to send to Indigo. Then a web app on that server will need to make a call to Indigo. Here's some Python code that does that. This is for an XBMC plugin I'm working on, but it should get you started:

Code: Select all
# -*- coding: utf-8 -*-
import sys
import os
import traceback
import xbmc
import xbmcaddon
import urllib
import urllib2

__addon__     = xbmcaddon.Addon(id='script.indigo')
__addonid__   = __addon__.getAddonInfo('id')
__addonname__ = __addon__.getAddonInfo('name')
__cwd__       = __addon__.getAddonInfo('path').decode("utf-8")
__version__   = __addon__.getAddonInfo('version')
__icon__      = __addon__.getAddonInfo('icon')
__resource__  = xbmc.translatePath( os.path.join( __cwd__, 'resources' ).encode("utf-8") ).decode("utf-8")
__lib__  = xbmc.translatePath( os.path.join( __resource__, 'lib' ).encode("utf-8") ).decode("utf-8")

sys.path.append(__resource__)
sys.path.append(__lib__)

# Import the common settings
from settings import Settings

xbmc.log(msg='%s: version %s started with %d arguments: %s' % (sys.argv[0], __version__, len(sys.argv), str(sys.argv)), level=xbmc.LOGNOTICE)

if __name__ == '__main__':

    deviceName = xbmc.getInfoLabel('System.FriendlyName')
    ipAddress = Settings.getIPAddress()
    userName = Settings.getUserName()
    passWord = Settings.getPassWord()
    url = "http://%s:8176/xbmc/xbmc" % ipAddress
    params = {'xbmc_command' : 'Select',
              'xbmc_dest' : deviceName,
              'xbmc_source' : sys.argv[1],
              'xbmc_dest_input' : sys.argv[2] }
    data = urllib.urlencode(params)
    req = urllib2.Request(url, data)
    authhandler = urllib2.HTTPDigestAuthHandler()
    authhandler.add_password('Indigo Control Server', url, userName, passWord)
    opener = urllib2.build_opener(authhandler)
    urllib2.install_opener(opener)
    page_content = urllib2.urlopen(req)


Then on Indigo you need an IndigoWebServer plugin that accepts that URL and does something with it. Here's the other end of the call from the Python routine above. There's probably a lot of stuff in there that's not needed because I started with a sample script of some kind.

Code: Select all
####################
## IMPORTS
import time
import cherrypy
from cherrypy import _cperror

from indigopy import indigoconn as ic
from indigopy import indigodb as idb
from indigopy.basereqhandler import BaseRequestHandler, kTrueStr, kFalseStr, kEmptyStr, kTextPageStr, kHtmlPageStr, kXmlPageStr

####################
def PluginName():
   return u"XBMC-Indigo Plugin"

def PluginDescription():
   return u"This is the XBMC-Indigo Plugin."

def ShowOnControlPageList():
   return False      # if True, then above name/description is shown on the Control Page list index

# Optional hook called when the IndigoWebServer first connects to IndigoServer
def IndigoConnected():
   pass

# Optional hook called when the IndigoWebServer disconnect from IndigoServer
def IndigoDisconnected():
   pass
   
####################
# here to suppress the log message
def NullLog(logMessage):
   pass
   
####################
class XBMCRequestHandler(BaseRequestHandler):

   """ Handles HTTP page requests. """

   def __init__(self, logFunc, debugLogFunc):
      BaseRequestHandler.__init__(self, logFunc, debugLogFunc)


   def xbmc(self, **params):
      saveLogFunc = cherrypy.server.indigoDb._Log
      cherrypy.server.indigoDb._Log = NullLog
   
      for param, value in cherrypy.request.params.items():
         cherrypy.server.indigoDb.VariableSetValue(cherrypy.server.indigoConn, param, value)
      cherrypy.server.indigoDb.VariableSetValue(cherrypy.server.indigoConn, "xbmc_last", str(time.time()))
      
      cherrypy.server.indigoDb._Log = saveLogFunc
      return
   xbmc.exposed = True        # exposed = True must be set for handler func to be called

joe (aka FlyingDiver)
my plugins: http://forums.indigodomo.com/viewforum.php?f=177

Posted on
Thu Jul 17, 2014 6:58 pm
jay (support) offline
Site Admin
User avatar
Posts: 18221
Joined: Mar 19, 2008
Location: Austin, Texas

Re: [ANSWERED]Control Indigo from outside the system

robertgerman wrote:
Now the tricky part, how will I actually implement it, though? I read about HTTP digest auth, but didn't understand much of how to make it work. Do you have a step by step guide?


I'm afraid that it's beyond the scope of our forums unless - others care to chime - in for several reasons, but primarily because there are a lot of different web technologies that you could use (php, rails, django, Java, etc.) and because we're using standard HTTP authentication you should be able to find examples for the technology that you're using. We don't necessarily have experience with all the possible web application technologies out there.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 11 guests