def run(port, queue): """invoke run when loading as a module in the simulator""" # Instance the devices that we're going to control # Add each to the control ring. For no very good reason. # lichtname = 'sim' lichtremote = False lichtapiname = 'sim' import devices.moorescloud.holiday.driver as driver app.licht = driver.Holiday(remote=False, address='sim', name='sim', queue=queue) app.licht.create_routes(app) # Adds in all the routes for device #for rt in app.routes: # print rt.method, rt.rule, rt.callback #the_srv = 'wsgiref' the_srv = 'cherrypy' # Starting with port 8080, try to grab a port! starting = True socknum = port while starting: try: app.run(host='0.0.0.0', port=socknum, server=the_srv, debug=False) # Start the server starting = False except socket.error as msg: print("Port %s not available, trying another" % socknum) socknum += 1
def new_run(): """ This is the real run method, we hope""" # Instance the devices that we're going to control # Add each to the control ring. For no very good reason. # ourname = "%s.local" % socket.gethostname() import devices.moorescloud.holiday.driver as driver app.licht = driver.Holiday( remote=False, address='localhost', name='localhost') # Connect to a real, local device app.licht.create_routes(app) # Adds in all the routes for device #the_srv = 'wsgiref' the_srv = 'cherrypy' #print app.licht #print 'Routes' #for rt in app.routes: # print rt.method, rt.rule, rt.callback print "Running..." # Try to run on port 80, if that fails, go to 8080 try: app.run(host='0.0.0.0', port=80, debug=True, server=the_srv) except socket.error as msg: print "Couldn't get port, you need to run in superuser!" sys.exit(1)
def old_run(port): """invoke run when loading as a module in the simulator""" # Instance the devices that we're going to control # Add each to the control ring. For no very good reason. # ourname = "%s.local" % socket.gethostname() discover = False # No discovery right now # Now we're using our newfangled IoTAS code to find the device if discover == True: import devices.moorescloud.holiday.discover as discover disc = discover.Discovery() print "Scanning for Holidays..." disc.discover() if len(discover.discovered) < 1: print "We got nuthin, going to use the simulator" lichtname = 'sim' lichtremote = False lichtapiname = 'sim' else: lichtname = "%s:%s" % (discover.discovered[0][0], discover.discovered[0][1]) lichtremote = True lichtapiname = discover.discovered[0][0] print "Using %s" % lichtname else: lichtname = 'sim' lichtremote = False lichtapiname = 'sim' #app.licht = devices.holiday.driver.Holiday(ourname) #app.licht = devices.moorescloud.holiday.driver.Holiday('sim') # Connect to the simulator #app.licht = devices.moorescloud.holiday.driver.Holiday(remote=True, address='yule.local') # Connect to a real device import devices.moorescloud.holiday.driver as driver #app.licht = driver.Holiday(remote=lichtremote, address=lichtname, name=lichtapiname) # Connect to a real device app.licht = driver.Holiday(remote=False, address='sim', name='sim') app.licht.create_routes(app) # Adds in all the routes for device #the_srv = 'wsgiref' the_srv = 'cherrypy' #print app.licht print 'Routes' for rt in app.routes: print rt.method, rt.rule, rt.callback print "Running..." # Try to run on port 80, if that fails, go to 8080 try: app.run(host='0.0.0.0', port=80, debug=False, server=the_srv) except socket.error as msg: # Starting with port 8080, try to grab a port! starting = True socknum = port while starting: try: app.run(host='0.0.0.0', port=socknum, server=the_srv, debug=False) # Start the server starting = False except socket.error as msg: print("Port %s not available, trying another" % socknum) socknum += 1