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)
def clearControlFile(): GLOB.writeConfig(controlFileNM, 'CONTROL', 'light' , '0') GLOB.writeConfig(controlFileNM, 'CONTROL', 'pump' , '0') GLOB.writeConfig(controlFileNM, 'CONTROL', 'fan' , '0') GLOB.writeConfig(controlFileNM, 'CONTROL', 'heater', '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)
dev_str='' if not GLOB.iniSectionRemove(configFileNM, 'DEVICE'): print('ini Section Delete Error ') if not GLOB.iniSectionAdd(configFileNM, 'DEVICE'): print('ini Section Add Error ') for dev in devices: #print("Device %s (%s), RSSI=%d dB" % (dev.addr, dev.addrType, dev.rssi)) for (adtype, desc, value) in dev.getScanData(): # Check iBeacon UUID # 255 is manufacturer data (1 is Flags, 9 is Name) #print(" (AD Type=%d) %s = %s" % (adtype, desc, value)) if adtype is 2 and TARGET_UUID in value: cnt = cnt+1 target_dev = dev print("%d) Device %s (%s), RSSI=%d dB" % (cnt, dev.addr, dev.addrType, dev.rssi)) dev_str = "sensor%02d" % (cnt) # 센서 하나만 저장 if cnt == 1: GLOB.writeConfig(configFileNM, 'DEVICE', dev_str, dev.addr) GLOB.writeConfig(configFileNM, 'FLOWERCARE', 'sensor_cnt', "%d" %cnt) if cnt > 0 : print('식물 정보 감지 센서 %d개를 찾았습니다. ' % cnt) else : print('식물 정보 센서를 감지 하지 못하였습니다.') print('제어기와 너무 멀리 떨어지거나 건전지 교체 시기인지 확인하여 주세요')