Receiving RAK7249 LoRaServer MQTT feed with Arduino

I have setup a 7249 gateway and a number of nodes. Everything works wonderfully. Can see the data from the nodes on the TTN console. Now I want to get the data into my Arduino application.

I have read and read and read, and I think I’ve suddenly got it! I have set up MQTT.fx on a RPi and it appears to work, though I haven’t got it to interface to the 7249. Pretty sure I’m across that. I have an application set up on an Arduino Mega + Ethernet shield and I’m pretty sure I’ve sus’d how to get the application to talk to the MQTT.fx.

My q is:- can my Arduino application interface directly to the 7249 MQTT-bridge or do I have to go via the MQTT.fx RPi MQTT to the Arduino application?

I think it’s obvious and the answer is “Yes” but the doc talks about the need for the 7249 bridge to connect to an MQTT and then the application.

Thanks.

Hei @Oldfield,

What I would do is use the Built-in Server to create an application and add the devices.
Use the MQTT global integration to forward the decrypted data to an MQTT broker. So as long as you have a broker somewhere running that has a valid IP and port this should work.
Does this make sense ?

Regards
Vladislav

There are a variety of MQTT libraries for Arduino and as it’s a standard, I’d expect them to connect directly to the gateway.

I’m curious what you are going to do with data created in one small microcontroller that then ends up in another one!

I’m not sure I understand you’re last sentence. I Have nodes (Dragino, soon to be RAK) measuring the level of water in a 5x (soon to be 7x) 33,000 litre tanks. That data goes back to the 7249 gateway. I want to get that data off and into an Arduino Mega which essentially says:-

if tank 1 = empty, then open motorised valve 1 to deliver water to tank 1.

When tank 1 = full, close motorised valve 1

The same Mega loop checks moisture levels from other nodes (via the gateway) and operates irrigation pumps, ditto tree-watering system.

So you’re recommending I don’t use the built-in 7249 MQTT-Bridge??

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.