|
|
|
Page 1 of 1
|
[ 3 posts ] |
|
can't start web server in plugin
| Author |
Message |
|
bcall
Joined: May 17, 2012 Posts: 59
|
 can't start web server in plugin
I am creating a plugin for the ISY. The easiest way to get updated on the states of its various devices is to create an event subscription which then sends HTTP/1.1 POST requests (with the update information) to a url that I specify. In order to receive these updates, I need to create an http server that simply listens for these updates and then updates the appropriate indigo devices within my plugin.
I have been able to get this working in a terminal, but when I attempt to get it working in my plugin, the http server won't start (I get an exception every time). I'm wondering if there is some restriction on http servers in plugins (or some kind of conflict I need to avoid with indigo's own server)?
Here are the relevant excerpts from my plugin:
[plugin.py] def startup(self): self.myThread = threading.Threat(target=self.deviceController.startComm) self.myThread.start() self.deviceController.isySubscribe() # this tells the isy to start sending updates to my http server
runConcurrentThread(self) while True: self.sleep(1)
[deviceController.py] def startComm(self): try: server = BaseHTTPServer.HTTPServer(('localhost', 8080), myHandler) server.serve_forever() # this should start my http server but I get an exception every time except: server.socket.close()
As I said, this works when I run the components in a terminal window.
I'm using BaseHTTPServer to create the http server. If there's something better for this, I'd be happy to modify.
Cherrypy looks like it might be good (and I see in the posts that you've used it for some of your own code), but I can't seem to import it into my plugin.py.
Thanks for your assistance.
|
| Tue Jun 12, 2012 9:10 pm |
|
 |
|
jay (support)
Site Admin
Joined: Mar 19, 2008 Posts: 6642 Location: Austin, Texas
|
 Re: can't start web server in plugin
First - there's a typo in the second line in the plugin.py (threading.Threat should be threading.Thread). There's not enough of your code to do any more troubleshooting. There's no reason why a plugin can't open an http port - it's just a separate process executing python code. I believe the twisted example plugin in the SDK shows how to open a telnet port to accept incoming connections (twisted is installed on Mac OS X by default).
You'll need to install cherrypy somewhere on your system so that Python can find it. If you intend to distribute your plugin to others then you can just put the cherrypy module in the plugin in the same directory as your plugin.py file.
_________________ Jay (Indigo Support)
|
| Wed Jun 13, 2012 8:36 am |
|
 |
|
bcall
Joined: May 17, 2012 Posts: 59
|
 Re: can't start web server in plugin
 The typo was in my post but not in the program itself (I should have used cut and paste instead of retyping). I think I found the conflict. I just wanted to make sure there weren't any potential collisions with indigo's own server. Thanks!
|
| Wed Jun 13, 2012 2:42 pm |
|
|
|
Page 1 of 1
|
[ 3 posts ] |
|
Who is online |
Users browsing this forum: No registered users and 1 guest |
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot post attachments in this forum
|
|