Beispiel #1
0
def on_message(client, userdata, msg):
    strJson = msg.payload.decode()
    LOG.writeLn("[MQTT] " + msg.topic + " " + strJson)  #토픽과 메세지를 출력한다.
    try:
        if GLOB.saveJsonData(COM.gJsonDir + "action.json", strJson) == 0:
            remote = '0'
            grp1 = GLOB.getJsonVal(strJson, 'interval', '0')
            if (grp1 != '0'):
                GLOB.writeConfig(configFileNM, 'SETUP', 'interval', grp1)
                remote = '1'
            grp2 = GLOB.getJsonVal(strJson, 'resolution_x', '0')
            if (grp2 != '0'):
                GLOB.writeConfig(configFileNM, 'SETUP', 'resolution_x', grp2)
                remote = '1'
            grp3 = GLOB.getJsonVal(strJson, 'resolution_y', '0')
            if (grp3 != '0'):
                GLOB.writeConfig(configFileNM, 'SETUP', 'resolution_y', grp3)
                remote = '1'
            grp4 = GLOB.getJsonVal(strJson, 'rotation', '99')
            if (grp4 != '99'):
                GLOB.writeConfig(configFileNM, 'SETUP', 'rotation', grp4)
                remote = '1'
            grp5 = GLOB.getJsonVal(strJson, 'start_time', '99')
            if (grp5 != '99'):
                GLOB.writeConfig(configFileNM, 'SETUP', 'start_time', grp5)
                remote = '1'
            grp6 = GLOB.getJsonVal(strJson, 'end_time', '99')
            if (grp6 != '99'):
                GLOB.writeConfig(configFileNM, 'SETUP', 'end_time', grp6)
                remote = '1'

            print('grps = %s %s %s %s %s %s [%s]' %
                  (grp1, grp2, grp3, grp4, grp5, grp6, remote))

            if remote == '1':
                if GLOB.appendTIMELAPsControlInfo(
                        COM.gJsonDir + "device.json",
                        GLOB.readConfig(configFileNM, 'SETUP', 'interval',
                                        '0'),
                        GLOB.readConfig(configFileNM, 'SETUP', 'resolution_x',
                                        '0'),
                        GLOB.readConfig(configFileNM, 'SETUP', 'resolution_y',
                                        '0'),
                        GLOB.readConfig(configFileNM, 'SETUP', 'rotation',
                                        '0'),
                        GLOB.readConfig(configFileNM, 'SETUP', 'start_time',
                                        '0'),
                        GLOB.readConfig(configFileNM, 'SETUP', 'end_time',
                                        '0')) == 0:
                    REQUEST.updateDIYs(user_id, dev_id)
                    LOG.writeLn("[MQTT] Command recive and reboot in 3 sec")
                    time.sleep(3)
                    GLOB.run_command("sudo reboot")
    except Exception as e:
        LOG.writeLn("[MQTT] : error : %s" % e)
Beispiel #2
0
print('**  END_TIME = %s' % mEnd_time)
print('--------------------------------------------------')
print('')

# pi camera Setting
camera = PiCamera()
camera.resolution = (mResolution_x, mResolution_y)
camera.rotation = mRotation

LOG.writeLn("[timeLapse] process run")
# Main Process
while True:
    try:
        GLOB.setUpdateTime()
        GLOB.appendTIMELAPsControlInfo(COM.gJsonDir + "device.json",
                                       mInterval_sec, mResolution_x,
                                       mResolution_y, mRotation, mStart_time,
                                       mEnd_time)
        REQUEST.updateDIYs(mUser_id, mProduct_id)
        if (int(COM.gHH) >= mStart_time) and (int(COM.gHH) <= mEnd_time):
            camera.start_preview()
            imgFileNm = COM.gHomeDir + 'pictures/pic_%s.jpg' % COM.gstrYMDHMS
            # make picture
            camera.capture(imgFileNm)
            camera.stop_preview()
            LOG.writeLn('file save:%s' % imgFileNm)
            mCount = mCount + 1
        time.sleep(mInterval_sec)
    except Exception as e:
        LOG.writeLn("[timeLapse] Error : %s" % e)