예제 #1
0
파일: boot.py 프로젝트: 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()
예제 #2
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()
예제 #3
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"]}) 
예제 #4
0
def run(root_path='/test', port=80, backlog=10):
    print("Starting test server ...")
    import uhttpd
    import http_file_handler
    file_handler = http_file_handler.Handler(root_path=root_path)
    import http_api_handler
    api_handler = http_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()
예제 #5
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()
예제 #6
0
async def main(modules):
    sound = SoundIntensity()

    while True:
        intensity = sound.next()

        modules['gills'].update_intensities(intensity)

        if not modules['cannon'].is_calibrating:
            compass_angle = modules['compass'].get_angle()
            modules['cannon'].rotate_to(compass_angle)

        ticks = ticks_ms()

        for module in modules.values():
            module.step(ticks)

        np.write()

        await asyncio.sleep_ms(1)


if __name__ == "__main__":
    modules = init_modules()
    api_handler = http_api_handler.Handler([([''], ApiHandler(modules))])
    loop = asyncio.get_event_loop()
    loop.create_task(main(modules))
    server = uhttpd.Server([('/api', api_handler)])
    server.run()
예제 #7
0
            value = tuple(int(html_color[i:i + 2], 16) for i in (0, 2, 4))
            print("Set white color to ", value)
            self.chess.set_color(player=0, color=value)
        elif 'set_color_black' == operation:
            html_color = api_request['query_params']['value']
            value = tuple(int(html_color[i:i + 2], 16) for i in (0, 2, 4))
            print("Set black color to ", value)
            self.chess.set_color(player=1, color=value)
        elif operation == 'index':
            print("Der Nutzer wollte die Website sehen")
            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__":
    chess = Chess()
    api_handler = http_api_handler.Handler([([''], ApiHandler(chess))])
    loop = asyncio.get_event_loop()
    loop.create_task(main(chess))
    server = uhttpd.Server([('/api', api_handler)])
    server.run()
import http_api_handler
import uhttpd
import uasyncio as asyncio

class Handler:
    def __init__(self):
        pass
    
    def get(self, api_request):
        print(api_request)
        return {'foo': 'bar'}


def simple_loop():
    while True:
        print("Yeehaw!")
        await asyncio.sleep(1)

api_handler = http_api_handler.Handler([(['test'], Handler())])

loop = asyncio.get_event_loop()
loop.create_task(simple_loop())
server = uhttpd.Server([('/api', api_handler)])
server.run()
예제 #9
0
import my_api
import http_api_handler
api_handler = http_api_handler.Handler([
    (['temp_hum'], my_api.DHTHandler()),
    (['water_temp'], my_api.WaterTempHandler()),
    (['water_level'], my_api.WaterLevelHandler()),
    (['switch'], my_api.SwitchHandler())
])
import uhttpd
server = uhttpd.Server([('/api', api_handler)])
server.run()