For The Things Stack V3 based networks, use MQTT, HTTP or Pub/Sub integrations for streaming data, and gRPC and HTTP for application and device management. See The Things Stack documentation for more information.
This is the Node.js Application SDK for The Things Network to receive activations and messages from IoT devices via The Things Network and send messages as well.
npm install --save ttn
NOTE: To use this SDK with the deprecated staging environment, install version 1.3.2 instead:
npm i --save [email protected]
.
import { data, application } from "ttn"
const appID = "foo"
const accessKey = "ttn-account.eiPq8mEeYRL_PNBZsOpPy-O3ABJXYWulODmQGR5PZzg"
// discover handler and open mqtt connection
data(appID, accessKey)
.then(function (client) {
client.on("uplink", function (devID, payload) {
console.log("Received uplink from ", devID)
console.log(payload)
})
})
.catch(function (err) {
console.error(err)
process.exit(1)
})
// discover handler and open application manager client
application(appID, accessKey)
.then(function (client) {
return client.get()
})
.then(function (app) {
console.log("Got app", app)
})
.catch(function (err) {
console.error(err)
process.exit(1)
})
There are more examples in the examples/
directory. For examples
written in ES5 (instead of ES2015), check the examples/es5/
directory.
To run the tests:
yarn install
make test
The code is written in ES7 using flowtype
type annotations.
To run the typechecker:
make typecheck
To run the linter:
make quality
To build the repository and transpile to ES5, run:
make build
To avoid checking in code with type- and linter-errors, install commit hooks via
make git.hooks
Tags are released through travis automatically. If you want to release manually run:
$ npm publish