changes
This commit is contained in:
@ -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()
|
||||
|
||||
|
Reference in New Issue
Block a user