예제 #1
0
timer = 0

LOG.writeLn("[doorDetector] process run")
while True:
    time.sleep(0.1)
    if GLOB.fileExist(metrixImg):
        timer = timer + 1
        if timer > 600:
            LOG.writeLn("[doorDetector] Alive Check (%d)" % mLstImgFileSize)
            timer = 0

        curntImgFileSize = os.path.getsize(metrixImg)
        if (curntImgFileSize > 0) and (mLstImgFileSize != curntImgFileSize):
            mLstImgFileSize = curntImgFileSize
            GLOB.setUpdateTime()
            GPIO.output(led_pin, 0)
            try:
                detectFace = 0
                rgb_small_frame = face_recognition.load_image_file(metrixImg)
                face_locations = face_recognition.face_locations(
                    rgb_small_frame)
                if face_locations:
                    face_encodings = face_recognition.face_encodings(
                        rgb_small_frame, face_locations)
                    face_names = []
                    for face_encoding in face_encodings:
                        # See if the face is a match for the known face(s)
                        matches = face_recognition.compare_faces(
                            known_face_encodings, face_encoding, 0.4)
                        name = "Unknown"
예제 #2
0
    def atOnce(self):
        self.chkSensor()
        GLOB.setUpdateTime()
        self.confUpdate()
        for [flora_name, flora] in self.flores.items():
            data = dict()
            attempts = 2
            flora['poller']._cache = None
            flora['poller']._last_read = None
            flora['stats']['count'] = flora['stats']['count'] + 1
            #print_line('Retrieving data from sensor "{}" ...'.format(flora['name_pretty']))
            while attempts != 0 and not flora['poller']._cache:
                try:
                    flora['poller'].fill_cache()
                    flora['poller'].parameter_value(MI_LIGHT)
                except (IOError, BluetoothBackendException):
                    attempts = attempts - 1
                    if attempts > 0:
                        LOG.writeLn('Retrying ...')
                    flora['poller']._cache = None
                    flora['poller']._last_read = None

            if not flora['poller']._cache:
                flora['stats']['failure'] = flora['stats']['failure'] + 1
                LOG.writeLn(
                    'Failed to retrieve data from Mi Flora sensor "{}" ({}), success rate: {:.0%}'
                    .format(
                        flora['name_pretty'], flora['mac'],
                        flora['stats']['success'] / flora['stats']['count']))
                print()
                continue
            else:
                flora['stats']['success'] = flora['stats']['success'] + 1

            for param, _ in mParameters.items():
                data[param] = flora['poller'].parameter_value(param)

            rc = -1
            try:
                data['timestamp'] = COM.gstrDATE
                data['name'] = flora_name
                data['name_pretty'] = flora['name_pretty']
                data['mac'] = flora['mac']
                data['firmware'] = flora['firmware']

                #print('Data for "{}": {}'.format(flora_name, json.dumps(data)))
                with open(COM.gJsonDir + flora_name + '.json',
                          'w',
                          encoding="utf-8") as make_file:
                    json.dump(data, make_file, ensure_ascii=False, indent="\t")

                #to make device.json file
                datas = []
                datas.append(self.device_id)
                datas.append(GLOB.readConfig(configFileNM, 'SETUP', 'mod', ''))
                datas.append(
                    GLOB.readConfig(configFileNM, 'AGENT', 'alarm', '0'))
                datas.append(str(data['temperature']))
                datas.append('0')
                datas.append(str(data['moisture']))
                datas.append(str(data['conductivity']))
                datas.append(str(data['light']))
                datas.append(str(data['battery']))
                datas.append(
                    GLOB.readConfig(controlFileNM, 'CONTROL', 'active',
                                    '0'))  # active
                datas.append(
                    GLOB.readConfig(controlFileNM, 'CONTROL', 'light',
                                    '0'))  # LED 조명
                datas.append(
                    GLOB.readConfig(controlFileNM, 'CONTROL', 'pump',
                                    '0'))  # 워터펌프
                datas.append(
                    GLOB.readConfig(controlFileNM, 'CONTROL', 'fan', '0'))  # 팬
                datas.append(
                    GLOB.readConfig(controlFileNM, 'CONTROL', 'heater',
                                    '0'))  # 히터
                datas.append(COM.gstrYMDHMS)
                datas.append(GLOB.loadTeamviewerID())

                rc = self.encodeStatJson(COM.gJsonDir + 'device.json', datas)
                if rc == 0:
                    LOG.writeLn(
                        '%s	[%s]	%s  %s  %s  %s  %s' %
                        (data['name'], data['battery'], data['temperature'],
                         data['moisture'], data['light'], data['conductivity'],
                         data['mac']))
            except Exception as e:
                LOG.writeLn("[ERROR][FLOWERCARE] : %s" % e)

            if rc == 0:
                if GLOB.appendWATERsControlInfo(
                        COM.gJsonDir + "device.json",
                        GLOB.readConfig(controlFileNM, 'CONTROL', 'active',
                                        '0'),
                        GLOB.readConfig(controlFileNM, 'CONTROL', 'light',
                                        '0'),
                        GLOB.readConfig(controlFileNM, 'CONTROL', 'pump', '0'),
                        GLOB.readConfig(controlFileNM, 'CONTROL', 'fan', '0'),
                        GLOB.readConfig(controlFileNM, 'CONTROL', 'heater',
                                        '0')) == 0:
                    REQUEST.updateDIYs(self.user_id, self.device_id)