TheThingsArchive / node-app-sdk

The Things Network Application SDK for Node.JS
https://www.thethingsnetwork.org/docs/node-js/
MIT License
41 stars 28 forks source link

The Things Network Node.js Application SDK Build Status NPM

⚠️ This SDK has been discontinued and will not be further supported.

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.

Installation NPM

npm install --save ttn

NOTE: To use this SDK with the deprecated staging environment, install version 1.3.2 instead: npm i --save ttn@1.3.2.

Documentation

Example

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.

Test Build Status

To run the tests:

yarn install
make test

Quality

The code is written in ES7 using flowtype type annotations.

To run the typechecker:

make typecheck 

To run the linter:

make quality

Build

To build the repository and transpile to ES5, run:

make build

Install git hooks

To avoid checking in code with type- and linter-errors, install commit hooks via

make git.hooks

Releasing

Tags are released through travis automatically. If you want to release manually run:

$ npm publish