def change_status_influxdb(self, sort, sort_status, key, status):
     try:
         data = []
         data.append(Data("status", status))
         data.append(Data(sort, key))
         sensordata = Sensordata(sort_status, self.host, data)
         self.influxdb_cloud.write_data(sensordata)
     except Exception as ex:
         logging.error(ex)
         raise Exception(ex)
def tril_vaat(a):
    print("trilling gedetecteerd")
    t = []
    t.append(Data("dishwasherstate", "Detect").__dict__)
    x = Sensordata("sensordata", "Kitchen", t)
    y = jsonpickle.encode(x.__dict__)
    mqtt.send(y)
    print(y)
def door_change(a):
    doorstate = door.pressed
    data = np.array([doorstate])
    ser = pd.Series(data)
    doorstate = ser.map({True: 'closed', False: 'open'})
    doorstate = str(doorstate.values[0])
    t = []
    t.append(Data("doorstate", doorstate).__dict__)
    x = Sensordata("sensordata", "Kitchen", t)
    y = jsonpickle.encode(x.__dict__)
    mqtt.send(y)
    print(y)
Exemple #4
0
 def start(self):
     while True:
         try:
             data = []
             data.append(Data("temperature", self.temperature_sensor()))
             sensordata = Sensordata("temperature_room", self.host,
                                     datetime.now(), data)
             self.mqtt.publish(sensordata)
             sleep(3)
         except Exception as ex:
             logging.info(ex)
             raise Exception(ex)
Exemple #5
0
 def get(self, username):
     if not username == User.get_username_by_id(session["user_id"]):
         return {'message': "You may not access another user's data."}, 400
     owner = {}
     d = Data.get_all_by_user(user_id=session["user_id"])
     if d:
         for item in d:
             owner.update(
                 {str(item.id): "/data/{}/{}".format(username, item.name)})
     shared = {}
     d = Data_Access.get(user_id=session["user_id"])
     if d:
         for item in d:
             shared.update({
                 str(item.data.id):
                 "/data/{}/{}".format(item.data.user.username,
                                      item.data.name)
             })
     return {'owner': owner, 'shared': shared}
    actLight.start()
    actTemp = threading.Thread(target=run_temp)
    actTemp.start()
    actHmdt = threading.Thread(target=run_hmdt)
    actHmdt.start()
    vibr.on_change(tril_vaat)
    door.on_change(door_change)
    door_change(0)
    #actPrs = threading.Thread(target=run_human_count)
    #actPrs.start()
    #actQueueListener = threading.Thread(target=queue_listener)
    #actQueueListener.start()

    while True:
        t = []
        t.append(Data("temperature", temp).__dict__)
        t.append(Data("light", light).__dict__)
        t.append(Data("humidity", hmdt).__dict__)
        x = Sensordata("sensordata", "Kitchen", t)
        y = jsonpickle.encode(x.__dict__)
        mqtt.send(y)
        print(y)
        time.sleep(5)

except KeyboardInterrupt as ex:
    print("Shutting down...")
except Exception as ex:
    print("something went wrong")
    print(ex)
finally:
    try:
try:
    actLight = threading.Thread(target=run_light)
    actLight.start()
    actTemp = threading.Thread(target=run_temp)
    actTemp.start()
    actHmdt = threading.Thread(target=run_hmdt)
    actHmdt.start()
    actQueueListener = threading.Thread(target=queue_listener)
    actQueueListener.start()
    door.on_change(door_change)
    door_change(0)

    while run:
        t = []
        t.append(Data("temperature", temp).__dict__)
        t.append(Data("light", light).__dict__)
        t.append(Data("humidity", hmdt).__dict__)
        if mqtt.runPrs:
            t.append(Data("persons", prs.get('person')).__dict__)
        x = Sensordata("sensordata", "GoldenEye", t)
        y = jsonpickle.encode(x.__dict__)
        mqtt.send(y)
        print(y)
        time.sleep(5)
    q.put("quit")
    GPIO.cleanup()
    print("goodbye")

except KeyboardInterrupt as ex:
    print("Shutting down...")