''' 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()