Just got a node working with a short node.js script to read the data from the mqtt queue and save it in a mongodb collection. Pics of the dead bug analog temp sensor, an arduino pro-mini (which LMiC TTN demo fills to 98% of program capacity!) with RFM95W module in the cap of a pill box:
node.js script to stuff the temp reading in a mongodb collection:
var mqtt=require(‘/usr/lib/node_modules/mqtt’)
var mongodb=require(‘/usr/lib/node_modules/mongodb’);
var mongodbClient=mongodb.MongoClient;
var mongodbURI=‘mongodb://mqtt:password@192.168.1.75:27017/data’
function insertEvent(topic,payload) {
mongodbClient.connect(mongodbURI, function(err,db) {
if(err) { console.log(err); return; }
else {
var obj = JSON.parse(payload.toString());
var buf = new Buffer(obj[‘data’], ‘base64’);
var key = topic.replace(///g,‘_’);
collection = db.collection(key);
collection.update(
{ _id:key },
{ $push: { events: { event: { value:buf.toString(), when:new Date() } } } },
{ upsert:true },
function(err,docs) {
if(err) { console.log(“Insert fail” + err); } // Improve error handling
else { console.log(“Update callback - closing db”);
db.close() }
});
}
});
}
client=mqtt.connect(‘mqtt://croft.thethings.girovito.nl’)
client.on(‘connect’,function() {
// client.subscribe(‘gateways/801F02FFFF7E56D1/status’);
client.subscribe(‘nodes/02E00202/packets’);
});
client.on(‘message’,insertEvent);