Beispiel #1
0
def on_message(client, userdata, msg):
	strJson = msg.payload.decode()
	#print(msg.topic+" "+str(msg.payload)) #토픽과 메세지를 출력한다.
	LOG.writeLn("[MQTT] "+ msg.topic+" "+ strJson) #토픽과 메세지를 출력한다.
	try:
		if GLOB.saveJsonData(COM.gJsonDir+"action.json", strJson) == 0:
			remote = '0'
			grp1 = GLOB.getJsonVal(strJson, 'light', '99')
			if (grp1 != '99') :
				GLOB.writeConfig(controlFileNM, 'CONTROL', 'light', grp1)
				remote = '1'
			grp2 = GLOB.getJsonVal(strJson, 'heater', '99')
			if (grp2 != '99') :
				GLOB.writeConfig(controlFileNM, 'CONTROL', 'heater', grp2)
				remote = '1'
			grp3 = GLOB.getJsonVal(strJson, 'fan', '99')
			if (grp3 != '99') :
				GLOB.writeConfig(controlFileNM, 'CONTROL', 'fan', grp3)
				remote = '1'
			grp4 = GLOB.getJsonVal(strJson, 'pump', '99')
			if (grp4 != '99') :
				GLOB.writeConfig(controlFileNM, 'CONTROL', 'pump', grp4)
				remote = '1'
			
			active = GLOB.getJsonVal(strJson, 'active', '99')
			if (active != '99') :
				remote = active
			GLOB.writeConfig(controlFileNM, 'CONTROL', 'active', remote)
			 
			#print("grp data %s %s" % (grp1, grp2))
			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(user_id, dev_id)
	except Exception as e :
		LOG.writeLn("[MQTT] : error : %s" % e)
Beispiel #2
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)