0

I am currently working on a web application that can control a robot I am working on. For some reason I cannot get Pyro to work correctly. It appears everything is working (no errors) but the methods in the "server" are never called when I click a button on the web page.

Here is my "server code":

import Pyro.core
import Pyro.naming
from rrb2 import *

class Robot(Pyro.core.ObjBase):

    def _setup(self):
            rr = RRB2()
            print "SETUP"
    def ledOneOn():
            rr.set_led1(1)
            print "LED ONE ONE"
    def ledOneOff():
            rr.set_led1(0)
            print "LED ONE OFF"
    def ledTwoOn():
            rr.set_led2(1)
            print "LED TWO ON"
    def ledTwoOff():
            rr.set_led2(0)
            print "LED TWO OFF"
    def forward():
            rr.forward()
            print "FORWARD"
    def stop():
            rr.stop()
            print "STOP"
    def __init__(self):
            Pyro.core.ObjBase.__init__(self)
            self._setup()

 if __name__ == "__main__":
    # Create a Pyro server and register our module with it
    Pyro.core.initServer()
    ns = Pyro.naming.NameServerLocator().getNS()
    daemon = Pyro.core.Daemon()
    daemon.useNameServer(ns)
    uri = daemon.connect(Robot(),"robot")
    daemon.requestLoop()

I know the Robot() class is being setup because I see the output, but none of the other methods are writing an output.

Here is my "client code" that the webpage calls:

import Pyro.core
from cgi import parse_qs

def application(environ, start_response):
    robot = Pyro.core.getProxyForURI("PYRONAME://robot")
    parameters = parse_qs(environ['QUERY_STRING'])

    if 'command' in parameters:
            command = parameters['command'][0]

            if 'command' == 'ledOneOn':
                    robot.ledOneOn()
            elif 'command' == 'ledTwoOn':
                    robot.ledTwoOn()

            status = '200 OK'
    else:
            status = '400 Bad Request'

    response_headers = [('Content-type', 'text/plain'), ('Content-Length', str(len(status)))]
    start_response(status, response_headers)

    return [status]

I've already verified that robot is set to the URI and the parameters variable contains the correct information. And the code is flowing to the 'if' statements as it should. But after the setup is called in the Robot() class, none of the methods are being called. Does anyone have any ideas?

QuantumPhysGuy
  • 416
  • 5
  • 18
  • Are you logging exceptions on the server? Does the server's process have system user privileges to set the GPIO pins? – Jacob Budin Jan 16 '15 at 00:25
  • Yes I am logging them through Apache and I see none. The scripts are running as system. I have them started via rc.local. – QuantumPhysGuy Jan 16 '15 at 00:52

1 Answers1

0

It seems like you're using the no longer supported Pyro version 3. Its last release was 3 years ago. May I advise to upgrade to Pyro4 if you can?

Irmen de Jong
  • 2,739
  • 1
  • 14
  • 26