Created
February 2, 2017 10:19
-
-
Save erijpkema/3ec59b3b8f18f5f14ba983caefe36864 to your computer and use it in GitHub Desktop.
Crude script to extract ttn data
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Crude script to extract ttn data. | |
// Run like this: | |
// docker run -it --rm --name banana2csv -v "$PWD":/usr/src/app -w /usr/src/app node:4-wheezy npm install ttn | |
// docker run -it --rm --name banana2csv -v "$PWD":/usr/src/app -w /usr/src/app node:4-wheezy node banana2csv.js | |
var ttn = require('ttn'); | |
var appEUI = ''; | |
var accessKey = ''; | |
var client = new ttn.Client('staging.thethingsnetwork.org', appEUI, accessKey); | |
var fs = require('fs'); | |
client.on('uplink', function (msg) { | |
console.log('Received message', msg); | |
console.log(msg['metadata']['server_time'], msg['fields']['temperature']); | |
console.log(msg['metadata']['server_time'], msg['fields']['light']); | |
var d = Date.parse(msg['metadata']['server_time']); | |
fs.appendFile('public/out.csv', d.toString() + ',' + msg['fields']['temperature'] + '\n' , function (err) { | |
}); | |
fs.appendFile('public/light.csv', d.toString() + ',' + msg['fields']['light'] + '\n' , function (err) { | |
}); | |
}); | |
client.on('activation', function (msg) { | |
console.log('Device activated:', msg.devEUI); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment