Ejemplo n.º 1
0
def request_live_data():
    router_id = request.json['router_id']
    if DatabaseHandler().user_has_router(router_id, request.json['token']) is False:
        return jsonify(result=False)
    topic_name = str(uuid.uuid4())
    message = MessageCreator(MessageCreator.NEW_CHANNEL, topic_name)
    send_message(router_id, message)
    send_message_admin("API", "New Live data link by user " + DatabaseHandler().get_user_from_id(request.json['token']) + " to router " + str(router_id))
    return jsonify(topic_name=topic_name), 200
Ejemplo n.º 2
0
def set_config():
    sensors = request.json["sensors"]
    payload = []
    for sensor in sensors[:]:
        DatabaseHandler().set_sensor_config(sensor['id'], sensor['config'])
        payload.append({"id": sensor['id'], "config": sensor['config']})
    message = MessageCreator(MessageCreator.UPDATE_SENSORS, payload)
    send_message(request.json['router_id'], message)
    send_message_admin(
        "POST SENSOR", "By user " +
        DatabaseHandler().get_user_from_id(request.json['token']) +
        " to router " + str(request.json['router_id']))
    return jsonify(True), 200
Ejemplo n.º 3
0
def set_script():
    router_id = request.json['router_id']
    script = request.json['script']
    res = DatabaseHandler().add_script(router_id, script)
    if res is True:
        scripts = DatabaseHandler().get_script(router_id=router_id)
        scripts_list = []
        for x in scripts[:]:
            scripts_list.append(x.script)
        message = MessageCreator(MessageCreator.UPDATE_SCRIPT, scripts_list)
        send_message(router_id, message)
    send_message_admin(
        "POST SCRIPT", "New script added by user " +
        DatabaseHandler().get_user_from_id(request.json['token']) +
        " to router " + str(router_id))
    return jsonify(res), 200
Ejemplo n.º 4
0
def RouterSleep(id=None):
    send_message(id, "SLPPHN")
    return jsonify({'status': 'Sleeping Photons'}), 200
Ejemplo n.º 5
0
def RouterRestart(id=None):
    send_message(id, "RSTART")
    return jsonify({'status': 'Restarting'}), 200
Ejemplo n.º 6
0
def RouterStop(id=None):
    send_message(id, "SHTDWN")
    return jsonify({'status': 'Shutting Down'}), 200
Ejemplo n.º 7
0
def set_internet_button():
    router_id = request.json['router_id']
    message = MessageCreator(MessageCreator.CONFIG_BUTTON, request.json['buttons'])
    send_message(router_id, message)
    return jsonify(True), 200
Ejemplo n.º 8
0
def control_actuator():
    router_id = request.json['router_id']
    message = MessageCreator(MessageCreator.COMMAND, {'MAC': request.json['MAC'], "command": request.json['command']})
    send_message(router_id, message)
    send_message_admin("API", "Actuator control by user " + DatabaseHandler().get_user_from_id(request.json['token']) + " to router " + str(router_id))
    return jsonify(True), 200
Ejemplo n.º 9
0
def arm_system():
    router_id = request.json['router_id']
    arm = request.json['armed']
    message = MessageCreator(MessageCreator.ARM_SYSTEM, arm)
    send_message(router_id, message)
    return jsonify(True), 200
Ejemplo n.º 10
0
def phone_location():
    router_id = request.json['router_id']
    message = MessageCreator(MessageCreator.PHONE_LOCATION, request.json['sensor_id'])
    send_message(router_id, message)
    return jsonify(True), 200