示例#1
0
def ROOM_REQUEST(message):
    print("ROOM REQ")
    print(message.id)
    sensors = DatabaseHandler().get_rooms(message.id)
    print(sensors)
    message_to_send = MessageCreator(MessageCreator.ROOM_RESPONSE, sensors)
    print("MESSAGE TO SEND" + str(message_to_send))
    return message_to_send
示例#2
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
示例#3
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
示例#4
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
示例#5
0
def test():
    message = MessageCreator(MessageCreator.PING, "dd")
    send_message_admin(message)
    return jsonify(True), 200
示例#6
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
示例#7
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
示例#8
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
示例#9
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