def handle_get_last_message(json): if not "topic" in json.keys(): return {"error": "Invalid request"} msg = db_manager.get_last_message(json["topic"]) msg = {"topic": msg["topic"], "time": js_timestamp(msg["time"]), "value": msg["value"]} return msg
def _on_message(self, client, userdata, msg): #print "[Debug] %s\t%s" % (msg.topic, msg.payload) if msg.topic in MQTT_TOPICS.keys(): data = mqtt_parse_message(MQTT_TOPICS[msg.topic], msg.topic, msg.payload) if data != None: timestamp = js_timestamp(data['time']) self._socketio.emit("mqtt_message", {'topic' : msg.topic, 'time': timestamp, 'value': data['value']})
def handle_get_history(json): if not "topic" in json.keys() or not "secondsBack" in json.keys(): return {"error": "Invalid request"} history = db_manager.get_history(json["topic"], json["secondsBack"]) history = map( lambda msg: {"topic": msg["topic"], "time": js_timestamp(msg["time"]), "value": msg["value"]}, history ) return history