def main():
    # Start Broadcast service
    service_broadcast.start()
    
    # Resource tree creation
    root = resource.Site()

    root.add_resource(('.well-known', 'core'), resource.WKCResource(root.get_resources_as_linkheader))
    root.add_resource(('motor',), MotorResource())
    asyncio.async(aiocoap.Context.create_server_context(root))

    asyncio.get_event_loop().run_forever()
Exemplo n.º 2
0
@app.route('/decreasePower/<motor>', methods = ['POST'])
def decreasePowerEndpoint(motor):
    decreasePower(motor)
    return "Success"

@app.route('/check')
def check():
    return "online"

@app.route("/setPowerAll", methods=['POST'])
def setPowerAllEndpoint():
    print(request.data)
    pieces = {}
    for piece in request.data.split("&"):
        values = piece.split("=")
        pieces[values[0]] = int(values[1])

    setPowerAll(pieces)
    return "Done"

@app.route("/setPower/<motor>::<power>", methods=['POST'])
def setPowerEndpoint(motor, power):
    powerInt = int(power)
    print("Power doidao" + str(powerInt))
    setW(motor, powerInt)
    return "Done"

if __name__ == "__main__":
    service_broadcast.start()
    app.run(host='0.0.0.0', port=8080, debug=True)