This commit is contained in:
Wolfgang Hottgenroth
2015-05-23 23:21:58 +02:00
commit 1d5077f7d5
3 changed files with 55 additions and 0 deletions

30
mqtt2mongo.py Normal file
View File

@ -0,0 +1,30 @@
'''
Created on 20.05.2015
@author: wn
'''
import paho.mqtt.client as mqtt
import json
import pymongo
def on_message(client, userdata, msg):
print(msg.topic+" "+str(msg.payload))
j = json.loads(msg.payload)
print(j)
mongoClient = pymongo.MongoClient('localhost')
db = mongoClient.iot
db.iot.insert(j)
if __name__ == '__main__':
print("Starting client ...")
client = mqtt.Client()
client.on_message = on_message
client.connect("mqttbroker", 1883, 60)
client.subscribe("IoT/Measurement/#")
client.loop_forever()