def on_message(client, userdata, msg): topic = msg.topic payload = msg.payload.decode() # print(topic, payload) # save new states from this message save_states(topic, payload) # get all values from database temperature = database.get("sensor", "iot/sensors/section0/temperature") humidity = database.get("sensor", "iot/sensors/section0/humidity") HI = 0.0 # heatindex makes only sense if temperature is over 25 if temperature > 25: HI = heat_index.calculate(float(temperature), float(humidity)) pers_s0 = float(database.get("sensor", person_counter_0)) pers_s1 = float(database.get("sensor", person_counter_1)) pers_s2 = float(database.get("sensor", person_counter_2)) shelf_s1 = float(database.get("sensor", "iot/sensors/section1/shelf")) shelf_s2 = float(database.get("sensor", "iot/sensors/section2/shelf")) print(HI) # save all value to file export.to_problem_file(HI, pers_s0, pers_s1, pers_s2, shelf_s1, shelf_s2, shelf_s1 + shelf_s2) # run ff plan = subprocess.run([ "./ff", "-o", "domain_supermarket.pddl", "-f", "problem_supermarket_generated.pddl" ], stdout=subprocess.PIPE).stdout.decode('utf-8') # parse resulting file new_states = parser.get_states(plan) print(new_states) for (topic, new) in new_states.items(): # get value for matrix leds if topic.startswith("iot/actuators/section") and topic.endswith( "/gate"): section_id = topic.replace("iot/actuators/section", "").replace("/gate", "") value = database.get( "sensor", "iot/sensors/section" + section_id + "/counter") if new: value = "-" new = value # check what should get updated with database old = database.get("actuator", topic) # make sure both datatypes are the same old = str(old) new = str(new) if new != old: database.upsert("actuator", topic, new) mqtt_publish.sendValue(new, topic)
def getShelf2(self, val): mqtt.sendValue(val, "section2/shelf")
def getHumidity(self, val): mqtt.sendValue(val, "section0/humidity")
def getShelf1(self, val): mqtt.sendValue(val, "section1/shelf")
def getTemperature(self, val): mqtt.sendValue(val, "section0/temperature")