This commit is contained in:
Wolfgang Hottgenroth
2015-06-06 07:23:27 -07:00
parent 1d5077f7d5
commit 3a00c54e0f
2 changed files with 32 additions and 3 deletions

View File

@ -7,15 +7,15 @@ Created on 20.05.2015
import paho.mqtt.client as mqtt
import json
import pymongo
import datetime
def on_message(client, userdata, msg):
print(msg.topic+" "+str(msg.payload))
j = json.loads(msg.payload)
j['metadata']['timestamp'] = datetime.datetime.now()
print(j)
mongoClient = pymongo.MongoClient('localhost')
db = mongoClient.iot
db.iot.insert(j)
r = db.iot.insert(j)
if __name__ == '__main__':
@ -25,6 +25,7 @@ if __name__ == '__main__':
client.on_message = on_message
client.connect("mqttbroker", 1883, 60)
client.subscribe("IoT/Measurement/#")
client.subscribe("IoT/WiFiPowerMeter/Measurement")
client.loop_forever()