def flaskUpdateStatus(): if (not busyReprogramming): filename = "/Users/niels/Sites/getStatus" wuclasses = wkpf.getWuClassList(1) if 0x1005 in wuclasses: scenario=2 else: scenario=1 if scenario==1: threshold = wkpf.getProperty(thresholdWuObjectScenario1, propertyNumber=1) else: threshold = wkpf.getProperty(thresholdWuObjectScenario2, propertyNumber=1) lightSensorValue = wkpf.getProperty(lightSensorWuObject, propertyNumber=0) lightOnOff = wkpf.getProperty(lightWuObject, propertyNumber=0) if scenario == 2: occupied = wkpf.getProperty(occupancyWuObject, propertyNumber=0) f = open(filename,"w") if scenario == 1: f.write("""{{"scenario": {0}, "threshold": {1}, "lightsensor": {2}, "lamp_on": {3}}}""".format(1, threshold, lightSensorValue, 1 if lightOnOff else 0)) else: f.write("""{{"scenario": {0}, "threshold": {1}, "lightsensor": {2}, "lamp_on": {3}, "occupied": {4}}}""".format(2, threshold, lightSensorValue, 1 if lightOnOff else 0, 1 if occupied else 0)) f.close() f = open(filename,"r") print f.readlines() f.close() threading.Timer(1, flaskUpdateStatus).start()
numericInputWuObject = WuObject(nodeId=1, portNumber=1, wuclassId=3) lightSensorWuObject = WuObject(nodeId=1, portNumber=2, wuclassId=5) thresholdWuObjectScenario1 = WuObject(nodeId=1, portNumber=3, wuclassId=1) thresholdWuObjectScenario2 = WuObject(nodeId=3, portNumber=3, wuclassId=1) occupancyWuObject = WuObject(nodeId=1, portNumber=5, wuclassId=0x1005) andGateWuObject = WuObject(nodeId=3, portNumber=6, wuclassId=0x1006) lightWuObject = WuObject(nodeId=3, portNumber=4, wuclassId=4) wuobjectsNode1 = wkpf.getWuObjectList(1) wuobjectsNode3 = wkpf.getWuObjectList(3) wuclasses = wkpf.getWuClassList(3) if 0x1006 in wuclasses: # Scenario 2 light_sensor_value = wkpf.getProperty(lightSensorWuObject, propertyNumber=0) input_value = wkpf.getProperty(numericInputWuObject, propertyNumber=0) threshold_operator = wkpf.getProperty(thresholdWuObjectScenario2, propertyNumber=0) threshold_threshold = wkpf.getProperty(thresholdWuObjectScenario2, propertyNumber=1) threshold_value = wkpf.getProperty(thresholdWuObjectScenario2, propertyNumber=2) threshold_output = wkpf.getProperty(thresholdWuObjectScenario2, propertyNumber=3) occupancy_value = wkpf.getProperty(occupancyWuObject, propertyNumber=0) andgate_in1 = wkpf.getProperty(andGateWuObject, propertyNumber=0) andgate_in2 = wkpf.getProperty(andGateWuObject, propertyNumber=1) andgate_out = wkpf.getProperty(andGateWuObject, propertyNumber=2) light_value = wkpf.getProperty(lightWuObject, propertyNumber=0) print "" print "" print "=== Light sensor" print "value:", light_sensor_value