Receiving RAK7249 LoRaServer MQTT feed with Arduino

Hei @Oldfield

I am in-fact recommending to use it.

Gateway->Built-in Server->Application/device->Built-in MQTT Bridge->Broker on the Arduion.

Regards
Vladislav

I think my q is can the 7249 MQTT-Bridge be used as simply a bridge. The doc seems to say that the Bridge has to connect to an external standalone MQTT.

Oh, okay. Then we’re on the same page. That is exactly what I think I’m doing. Thanks

I meant to say:-

I think my q is can the 7249 MQTT-Bridge be used as simply an MQTT. The doc seems to say that the MQTT-Bridge has to connect to an external standalone MQTT.

… and then → my application which cld be hosted on the same Arduino?

Yeah, assuming that by application you mean something taking the already decrypted and decoded data, for example actual sensor values and doing something with it, for example triggering a switch when the value drops below a certain level.

Yes, thats exactly what I mean. So, just to confirm, the MQTT-Bridge has to connect to a separate and external MQTT-Broker eg MQTT.fx running on a RPi, and the “application” (as I described It Triggering a switch) running on an Arduino talks to the RPi

Or you can run a broker on the arduino I guess

1 Like

Which circles us back to my answer. John, there’s no obvious reason for your Arduino to not talk directly to the MQTT on the gateway.

1 Like

Im trying to use the MQTT broker built into the RAK7249. How do I determine its IP address, please

It will be the same as the gateway itself …

Hi Again. Thank your help todate.

I’m using a RAK 7249 in this configuration:- Gateway->Built-in Server->Application/device->Built-in MQTT Bridge->software on an Arduino Mega+Ethernet sheld.

Maybe my approach and software is too simple?

I wondered if you cld have a look at the code and suggest where I may have gone wrong.

Many Thanks.

#include <SPI.h>
#include <Ethernet.h>
#include <PubSubClient.h>

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; // Arduino MAC address
IPAddress ip(192, 168, 1, 177); // Arduino IP address
IPAddress server(192, 168, 1, 245); // RAK7249 IP address

EthernetClient ethClient;
PubSubClient mqttClient(ethClient);

void setup()
{
Serial.begin(9600);
mqttClient.setServer(server, 1883); // MQTT
mqttClient.setCallback(callback);
Ethernet.begin(mac, ip); // Allow the hardware to sort itself out
delay(1500);
}

void loop()
{
if (!mqttClient.connected())
{
reconnect();
}
mqttClient.loop();
}

void callback(char* topic, byte* payload, unsigned int length)
{
Serial.print(“Message arrived [”);
Serial.print(topic);
Serial.print("] ");
for (int i = 0; i < length; i++)
{
Serial.print((char)payload[i]);
}
Serial.println();
}

void reconnect()
{
while (!mqttClient.connected()) // Loop until we’re reconnected
{
Serial.print(“Attempting MQTT connection…”);
if (mqttClient.connect(“Oldfield”)) // Attempt to connect
{
Serial.println(“connected
mqttClient.subscribe(“application/sensor-node-dht22/device/01f3b8f85a1c1050/”); // subscribe
}
else
{
Serial.print(“failed, rc=”);
Serial.print(mqttClient.state());
Serial.println(” try again in 5 seconds");
delay(5000); // Wait 5 seconds before retrying
}
}
}

Due to eyesight issues, I can only see formatted code - can you edit and use the block quote " button.

I’d get me a desktop MQTT client and check that you can connect & subscribe using that.

Hello.

Can you please point me to documentation that describes how to connect the RAK7249 to an external MQTT. Thanks.

Quickest way is to go to the product page and follow the link from there.

Or the downloads site.

This is mistaken, and may be the source of your confusion

The MQTT bridge is a component that sits between the packet forwarder and the MQTT broker which the built in server uses to communicate with the packet forwarder aspect of the gateway itself.

It has no role for the decoded application data.

The actual flow is more like this:

concentrator chip
packet forwarder
legacy UDP protocol
MQTT bridge
MQTT broker for gateway traffic
Built in Server
MQTT broker for application traffic

It’s that second MQTT broker (external or internal) that you need to point both the server and the Arduino at so that the decoded application traffic (rather than raw encoded gateway traffic) can flow between them.

1 Like

Well, progress. Thank you for your help.

I decided to try to get the RAK7249 going using the built-in server and the MQTT bridge working to an MQTT on my laptop rather then a RPi MQTT.

I have managed to get the MQTT on the laptop to connect to the 7249. So pretty excited about that.

I have also subscribed to a series of topics associated with nodes that the gateway can see.

So the issue now is, I dont get to see any traffic/data that I have subscribed to.

One of the nodes is the rak7204 which hasn’t been “seen” for 3 months, so I may be a bit overly hopeful. However one is DHT22 temp/humidity, and I can see that on the TNN when configured.

I’m thinking I’ll start again with a new node and get that to go afresh.

Any ideas, anyone?

That’s a mistake. You’re still confusing the MQTT bridge’s task of feeding encrypted raw traffic into the network server with what you want to have happen to the decrypted application level traffic coming out of the network server.

So the issue now is, I dont get to see any traffic/data that I have subscribed to.

Indeed, you won’t, because you broke the MQTT bridge connection between the gateway component and the the network server component of the box.

Reset to factory configuration and configure the network server’s output MQTT; don’t mess with the configuration of the MQTT bridge as it has nothing to do with your goal. These are entirely distinct uses of MQTT.

And remember of course that if you are using the internal server, then you are not using TTN. And if you are using TTN, then you are not using the internal server. OTAA nodes will have to be forced to re-join if you change network servers between internal and TTN.

Thank you for your help/advice. Much appreciated.

I set up the RAK7249 LoRaPacket Server = built-in LoRa server. Left the MQTT bridge alone. Set up Au915 and Concentrator 1. All good. Can see traffic on the LoRaWAN Packet Logger. Pretty cool.

LoRa Network Server Gateway overview = setup Gateway and Applications.

Installed MQTT.fx on a windows 10 laptop

In MQTT.fx topic = application/{{application_ID}}/device/{{device_EUI}}/rx

Pretty soon discovered that “application_ID” is the ID from the :“LoRa Network Server Application Overview” screen and not the ID from the “TTN application/device screen”. Big learning.

Worked perfectly. Got packets on the laptop screen. Doubly pleased and grateful for all the help.

Next issue was to set an MQTT Broker up on an Arduion Uno. I used the following sketch -

#include <SPI.h>
#include <Ethernet.h>
#include <PubSubClient.h>

byte mac = {0xDE, 0xED, 0xBA, 0xFE, 0xFE, 0xED}; // Update these with values suitable for your network.
IPAddress ip(192, 168, 1, 50); // IP address to use if DHCP failed
IPAddress server(192, 168, 1, 146); // IP address of RAK7294 built-in server
EthernetClient ethClient;
PubSubClient client(ethClient);

void setup()
{
Serial.begin(57600);
client.setServer(server, 1883);
client.setCallback(callback);
Ethernet.begin(mac, ip); // try to conigfure using IP address instead of DHCP:
delay(5000); // Allow the hardware to sort itself out
}

void loop()
{
if (!client.connected())
{
reconnect();
}
}

void reconnect()
{
while (!client.connected()) // Loop until we’re reconnected
{
Serial.print(“Attempting MQTT connection… \n”);
if (client.connect(“arduinoClient”)) // Attempt to connect
{
Serial.println(“connected”);
client.subscribe(“application/3/device/00033bbcff12a631/rx”); // Once connected,resubscribe
if (client.subscribe(“application/3/device/00033bbcff12a631/rx”)) Serial.print(“sending the subscribe succeeded”);
}
else
{
if (client.state() == -4) Serial.print(“The server didn’t respond within the keep=alive time.”);
if (client.state() == -3) Serial.print(“The network connection was broken.”);
if (client.state() == -2) Serial.print(“The network connection failed.”);
if (client.state() == -1) Serial.print(“The client is disconnected cleanly.”);
if (client.state() == 1) Serial.print(“The server doesn’t support the requested version of MQTT.”);
if (client.state() == 2) Serial.print(“The server rejected the client identifier.”);
if (client.state() == 3) Serial.print(“The server was unable to accept the connection.”);
if (client.state() == 4) Serial.print(“The username/password was rejected.”);
if (client.state() == 5) Serial.print(“The client was not authorised to connect.”);
Serial.println(“\n try again in 5 seconds”);
delay(5000); // Wait 5 seconds before retrying
}
}
}

void callback(char* topic, byte* payload, unsigned int length)
{
Serial.print(“Message arrived [”);
Serial.print(topic);
Serial.print("] ");
for (int i = 0; i < length; i++)
{
Serial.print((char)payload[i]);
}
Serial.println();
}

I have put in some serial.prints to debug.

The monitor reads -

Attempting MQTT connection
connected
sending the subscribe succeeded

After that, nothing happens. The topic = “application/3/device/00033bbcff12a631/rx” on the MQTT.fx gets a great response of messages: temperature, etc, but on the Arduino, nothing.

Can you please give some ideas as to where Im going wrong.

Again, thank you for your earlier assistance. The outcome has been pretty fantastic. Regards

No, that’s an MQTT client.

As far as I can tell, you are using the MQTT broker built into the gateway.

You then installed MQTT client software on the windows machine, and were able to subscribe to the application feed, which indicates everything is working correctly.

You then failed to get any messages when attempting to subscribe from an Arduino sketch, while the windows setup confirms they are continuing to be published. That would indicate either a problem with the Arduino sketch, or a problem with whatever it is using for networking. If I had to guess, there’s probably an MQTT method you should be calling periodically in your loop() which you are forgetting to call. Events will happen as callbacks, but you need to let the MQTT code run regularly to maintain the connection and find out if there are any messages to deliver to your callback. But that’s really about the Arduino library, not the gateway…