-
Notifications
You must be signed in to change notification settings - Fork 2
Forward data from TTN to any Web app
The TTN backend provides a MQTT broker. All examples here can be run from your desktop. Once it works, you could host the same glue code in the cloud, e.g. at Google App Engine.
Download and install Nodejs from https://nodejs.org/en/ then type
$ node -v
(The basic idea of the code below works in any other language, of course.)
$ npm install ttn --save
With a MQTT client you can subscribe to packets.
This client just logs incoming packets to your console.
https://github.com/TheThingsNetwork/node-app-sdk/blob/master/src/example.js or https://bitbucket.org/tamberg/iotworkshop/src/tip/NodeJS/ttn-mqtt-logger.js
var ttn = require('ttn');
var appId = 'TTN_APP_ID';
var accessKey = 'TTN_ACCESS_KEY';
var client = new ttn.Client('eu', appId, accessKey);
client.on('message', function(deviceId, message) {
console.log(message.payload_raw);
});
For app ID and keys, see https://console.thethingsnetwork.org/applications
Instead of logging to the console, your MQTT client (aka glue code) can forward packets.
In the case of ThingSpeak you send a GET (!) request to post data to a ThingSpeak channel.
https://bitbucket.org/tamberg/iotworkshop/src/tip/NodeJS/ttn-thingspeak-forwarder.js
In the case of IFTTT the code looks very similar.
Here, the value is transferred in the body of a POST request.
https://bitbucket.org/tamberg/iotworkshop/src/tip/NodeJS/ttn-ifttt-forwarder.js
If you prefer hosting the node code in the cloud, check https://zeit.co/now/
Error: Connection refused: Not authorized => Check your keys.
- HC SR501 Passive Infrared Sensor (PIR)
- HRLV MaxSonar EZ MB1013 Ultrasonic Range Finder
- TCRT5000 Infrared Reflective Barrier
- SHT31
- ublox PAM-7Q (GPS)
- SDP610 (Differential pressure sensor)