Ejemplo n.º 1
0
def main_loop():
    '''Main run loop'''
    loop = asyncio.get_event_loop()
    # setup webserver
    handler = uhttpd.api_handler.Handler([([], Handler())])
    server = uhttpd.Server([('/', handler)])
    loop.create_task(check_inputs())
    server.run()
Ejemplo n.º 2
0
Archivo: boot.py Proyecto: GabeKnuth/mc
def setup_httpd():
    api_handler = http_api_handler.Handler([(['submit.something'],
                                             default_api.Handler())])

    admin_server = uhttpd.Server([('/api', api_handler),
                                  ('/', http_file_handler.Handler('/www'))],
                                 config={'bind_addr': '192.168.4.1'})
    admin_server.start()
Ejemplo n.º 3
0
def main():
    try:
        relay = Relay()
        exception_timeout = configuration.get('exception_reset_timeout')
        api_handler = http_api_handler.Handler([(['relay'],
            RelayHandler(relay, configuration.get('http_authorization_token')))]
        )
        server = uhttpd.Server([('/api', api_handler)])
        server.run()
    except Exception as e:
        print(('Caught exception, {}'
               'resetting in {} seconds...').format(e, exception_timeout))
        time.sleep(exception_timeout)
        machine.reset()
def run(root_path='/test', port=80, backlog=10):
    print("Starting test server ...")
    import uhttpd
    import uhttpd.file_handler
    file_handler = uhttpd.file_handler.Handler(root_path=root_path)
    import uhttpd.api_handler
    api_handler = uhttpd.api_handler.Handler([(['test'], TestAPIHandler())])
    global server
    server = uhttpd.Server([('/api', api_handler), ('/test', file_handler)], {
        'port': port,
        'require_auth': True,
        'backlog': backlog
    })
    server.run()
Ejemplo n.º 5
0
    def __init__(self):
        super(WebServer, self).__init__()

        if not http_file_handler.exists( self.webroot):
            os.mkdir( self.webroot)
        
        self.initApp()
        self.initMqtt()

        self.confbox = axconfbox.Confbox(self.app, axapp.CONFIG )
        self.gpio = axgpio.Gpio()

        #www
        webhandler = http_file_handler.Handler( self.webroot )
        #api
        api_handler = http_api_handler.Handler([ (['gpio'], self.gpio) , 
                                                 (['conf'], self.confbox)
                                              ])
        self.server = uhttpd.Server([('/web', webhandler),('/api', api_handler)] , config={'port': self.config["webport"]}) 
def wc():
    import uhttpd
    import uhttpd.file_handler
    import uhttpd.api_handler
    import api

    api_handler = uhttpd.api_handler.Handler([
        #([], api.APIHandler())
        (['system'], api.SystemAPIHandler()),
        (['memory'], api.MemoryAPIHandler()),
        (['flash'], api.FlashAPIHandler()),
        (['network'], api.NetworkAPIHandler())
    ])
    file_handler = uhttpd.file_handler.Handler(block_size=256)
    server = uhttpd.Server([
        ('/api', api_handler),
        ('/', file_handler)
    ], {'max_headers': 50, 'backlog': 10})
    server.run()
Ejemplo n.º 7
0
def run():
    ##
    ## Start the controller and signal we are starting
    ##
    global controller_
    controller_ = neolamp.controller.Controller()
    controller_.pixel_dance()
    controller_.clear()
    ##
    ## Set up and start the web server
    ##
    #import system.api
    api_handler = uhttpd.api_handler.Handler([
        (['neolamp'], neolamp.api.Handler(controller_))
        #, (['system'], system.api.Handler())
    ])
   # file_handler = uhttpd.file_handler.Handler('/www/neolamp')
    server = uhttpd.Server([
        ('/api', api_handler)
        #,('/', file_handler)
    ], {'max_headers': 50, 'backlog': 10})
    server.run()
Ejemplo n.º 8
0
        elif 'leer' == operation:
            value = str(api_request['query_params']['value'])
            print("leer", value)
            self.barschild.leer(value)
            #self.chess.set_turn("white", time=value)
        elif 'restart' == operation:
            print("restart game")
            self.barschild.restart()
        elif operation == 'index':
            print("send webpage")
            return self.INDEX
        elif operation == 'hello':
            print("Hello World")
            return ('''
            <!DOCTYPE html>
             <html>
              <header>
              <title> EasterEgg: </title>
              </header>
              <body> Hello  world </body>
              </html>''')


if __name__ == "__main__":
    barschild = Barschild()
    api_handler = http_api_handler.Handler([([''], ApiHandler(barschild))])
    loop = asyncio.get_event_loop()
    loop.create_task(main(barschild))
    server = uhttpd.Server([('/api', api_handler)])
    server.run()
Ejemplo n.º 9
0
import uhttpd
import uhttpd.file_handler
server = uhttpd.Server([('/', uhttpd.file_handler.Handler('/www'))])
server.run()