How to set up non-lorawan application & sensors with MQTT

Hello everyone,

I have some questions regarding setting up a non-lorawan gateway (ESP23) with non-lorawan sensors in TTN using MQTT. Firstly, I have created the ESP32 as an “Application” with an ID, is this correct? Secondly, I believe I don’t need to create the sensors in “End devices” since they are not lorawan-compatible, is that correct?

Moreover, I’m wondering what the publish and subscribe commands should be for my setup. Is this format only for lorawan sensors or should I use theem:

#Publish sensor data
client.publish(“v3/esp32-mqtt@ttn/devices/+/up”)
#Subscribe to sensor data
client.subscribe(“v3/esp32-mqtt@ttn/devices/+/down”)

Here are some excerpts from my code:

#include <PubSubClient.h>                 
#include <WiFi.h>
const char* ssid = "Vodafone";                              
const char* password = "password";                        
const char* ttn_server = "eu1.cloud.thethings.network";
const char* ttn_user = "esp32-mqtt@ttn";
const char* ttn_password = "password";
const int ttn_port = 1883;
WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
  }
  client.setServer(ttn_server, 1883);  
  client.setCallback(callback_led);                                
   while (!client.connected()) {                                     
    if (client.connect("ESP-32a", ttn_user, ttn_password)) {                                   
      Serial.println("Connected to MQTT-Broker.");
      client.setBufferSize(2048);
      client.subscribe("Room1/Temperature");
    }  else {
      Serial.println("Connection failed.");
      delay(2000);
    }
  }
}
oid callback_led(char* topic, byte* payload, unsigned int length){            
  String payloadString = "";
  actTopic = topic;
  if (actTopic == "Temperature") {            
    for (int i = 0; i < length; i++) {
      payloadString += (char)payload[i];
    }
    temperature = payloadString.toFloat();        
    if (temperature>25){                        
      digitalWrite (redLed,HIGH);
      }
    else {
      digitalWrite (redLed,LOW);
      }
  }

Most of the time, I can only find information on Lorawan-compatible gateways and sensors on Google or in forums. Therefore, I would appreciate it if you could give me a hint on similar topics. Any insights or suggestions would be greatly appreciated. Thank you in advance!

This TTI funded forum only discusses LoRaWAN on TTN / TTI.

And TTN do not run an MQTT server for the general convenience of anyone, not even the users - it ONLY sends OUT messages like uplinks and ONLY receives messages for downlinks.

Can you not imagine the load if people started using the server as a general purpose MQTT server? A server no one pays for?

If you need an MQTT server, I’d recommend something like a Linode Nanode to run your own MQTT server .

Closing

PS, for anyone arriving here via Google, the OP has this the wrong way round.

The up topic is for hearing uplinks the are sent from a device.

The down topic is for the very very occasional, if ever at all, downlinks to the device. But we don’t do no stinking downlinks on TTN as it’s anti-social - forum search for details.

But just to be clear, you can’t publish your own uplinks.

1 Like