Exemplo n.º 1
0
def get_history():
    # id = authenticator.verify_token(request.json['token'])
    router_id = request.json['router_id']
    sensor_id = request.json['sensor_id']
    start = request.json['start']
    end = request.json['end']
    print(request.json)

    if start == 0 or end == 0:
        start = None
        end = None

    hh = HistoricHandler()

    if sensor_id == "ALL":
        data = {}
        db = DatabaseHandler()
        sensors = db.get_router_sensors(router_id)

        for x in sensors[:]:
            s_id = x[0]
            res = hh.get_reading(router_id, s_id, start=start, end=end)
            print("Results: " + res)
            data.update({s_id: res})

        return jsonify(data=data)

    result = hh.get_reading(router_id, sensor_id, start=start, end=end)
    ret = {}
    ret.update({sensor_id: result})

    return jsonify(data=ret)
def send_notification(router_id, data_message):
    dm = {'message': data_message}
    push_service = FCMNotification(api_key=config.FCM_SERVER_API)
    db = DatabaseHandler()
    token = db.get_phone_token(router_id)
    phones = []
    for x in token[:]:
        print(x[0])
        phones.append(x[0])
    result = push_service.notify_multiple_devices(registration_ids=phones,
                                                  data_message=dm)
    print(result)
Exemplo n.º 3
0
def SAVE_DATA(message):
    hh = DatabaseHandler()
    data = message.payload
    if len(data) == 0:
        return
    sensor_list = data['sensors']

    d = datetime.utcnow()
    unixtime = calendar.timegm(d.utctimetuple())

    print(message)

    for s in sensor_list[:]:
        hh.record_reading(unixtime, message.id, s)
Exemplo n.º 4
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
Exemplo n.º 5
0
 def emit(self, record):
     try:
         rec = {
             "level":str(record.levelno),
             "message":"%(message)s @ [%(pathname)s(%(lineno)d)]" % {"message": record.message, "pathname": record.pathname, "lineno": record.lineno},
             "time": str(calendar.timegm(time.strptime(record.asctime,"%Y-%m-%d %H:%M:%S,%f"))),
         }
         DatabaseHandler().add_warning_record(record=rec, originType="SERVER", originName="The Server")
         self.flush()
     except (KeyboardInterrupt, SystemExit):
         raise
     except:
         self.handleError(record)
Exemplo n.º 6
0
def SEND_LOG_DATA(message):
    print(message)
    DatabaseHandler().add_warning_record(message.payload, "Router",
                                         message.payload['R_id'])
Exemplo n.º 7
0
def ACTIVE_SENSORS(message):
    for sensor in message.payload[:]:
        DatabaseHandler().init_sensor(sensor, message.id)
Exemplo n.º 8
0
def PING(message):
    print("PING From " + str(message.id))
    DatabaseHandler().register_ping(message.id)