How to send a downlink to your mote via ttn network using ttn.js


#1

Does any one know how to publish a message to the TTN using the code below:

var ttn = require(‘ttn’);
var appEUI = ‘xxxxxxxxxx’;
var accessKey = ‘********************************************’;
var client = new ttn.Client(‘staging.thethingsnetwork.org’, appEUI, accessKey);

client.on(‘uplink’, function (msg) {
console.log(‘Received message’, msg);
});

client.on(‘activation’, function (msg) {
console.log(‘Device activated:’, msg.devEUI);
});


(Gonzalo Casas) #2

Looks like the ttn.js SDK doesn't support that at the moment.


(Mike Aski) #3

Any info about ETA of downlink?


(Gonzalo Casas) #4

@MikeAski: ok, now I see why you said you didn't find a definitive answer to whether downlink is supported or not. So, to clarify a bit more: downlink is supported as of today, support is limited to Class A devices.

This forum topic refers to downlink support in the node.js SDK, not in the network itself. And between the last answer and now, downlink support has been added also to the SDK: https://github.com/TheThingsNetwork/sdk/commit/3786646c9921ee9af25e1843fb78f39f5ca64811

:smile:


(Mike Aski) #5

Ok, thanks a lot for this clarification :+1:


(Niek Beijloos) #6

Downlink with node.js :

client.send(devID, "01",1)

devID = speaks for itself.
“01” = string with the data you want to send.
1 = port you are communicating with ( see your data in the console).

Compleet example:

var ttn = require("ttn")

var appID = "****"
var accessKey = "****"

ttn.data(appID, accessKey)
  .then(function (client) {
    client.on("uplink", function (devID, payload) {
      console.log("Received uplink from ", devID)
      console.log(payload)
      client.send(devID, "01",1)
    })
  })
  .catch(function (error) {
    console.error("Error", error)
    process.exit(1)
  })

(Arjan) #7

Just for future readers, as per the documentation:

  • payload (PayloadArray | PayloadRaw | String | PayloadFields) The raw payload as a Buffer, an Array of numbers, a hex string or an object of payload fields.