Cannot publish/subscribe to my device up/down link topics

Hi there!

I am trying to make quick test for the pub/sub mechanism to my registered device on TTN so I can build my complete solution app on the data coming to the TTN broker.

At the moment I am waiting for my loRa module to arrive, that is why I want to use a simple nodeJS script to publish dummy data, and the other to subscribe and build an app using the dummy data. I use the following code for this:

var mqtt = require('mqtt')

var options = {
  port: 1883,
  host: 'mqtt://eu.thethings.network',
  username: 'xxxx',  // here I wrote my app id
  password: 'xxxx'  // here I wrote the access key
};

var client  = mqtt.connect('mqtt://eu.thethings.network',options)

client.on('connect', function () {
  client.subscribe('appID/devices/MyDeviceName/down', function (err) {
    if (!err) {
      client.publish('appID/devices/MyDeviceName/down', 'Hello mqtt')
    }
  })
})
 
client.on('message', function (topic, message) {
  // message is Buffer
  console.log(message.toString())
  // client.end()
})

This is however not doing anything, I was watching the data on TTN, nothing coming in.

I also tried using mqtt explorer but it did not work.

Both methods worked fine when I played the broker on my machine, eclipse and mosquittoo on cloud.

Your help is greatly appreciated.

Thanks!
Ahmed

You can only publish a message to the MQTT Data API to schedule a downlink. But that needs a structured JSON message with Base64 encoded binary data, not some text message like you’re showing. See its documentation. (And never use text messages in LoRaWAN, that’s just a waste of air time.)

So, you cannot use MQTT to simulate a device, if that’s what you’re after. Instead, see How can I test my application by means of seeing the data at my HTTP integration.

Aside, please see How do I format my forum post? [HowTo]