Hi.
I have a RAK7249 gateway installed and working using the in-build LoRa server. Backhaul from the server is ethernet to my router.
I have a very simple Arduino UNO + Dragino LoRa Shield end-node. Its payload is "Hello, Ryan". It is currently the only node in operation. It too appears to be working perfectly. I can see the packet/payload/message on the LoRa packet logger on the management software of the gateway. I can see uplinks and downlinks.
I am running MQTT.fx on windows 10 Laptop. I am connected to the node via ethernet. I am subscribed to the in-built server. The topic is "application/3/device/+/+". I have replaced specific EUI etc with wildcards. The MQTT.fx shows all the messages eg "join" and "rx".
I have to say its taken me many months to get this far. Don't laugh.
However, the intent of getting this to work is to eventually parse farm management information out of the message/payload and operate something, eg a pump. So to do that, I have built an Arduino MQTT client.
Here is the code -
<
/*
MQTT Basic v1.0
Using -
Arduin0 Mega + Arduino Ethernet2 Shield
MAC address is A8:61:0A:AE:6A:0B
Static IP address 192, 168, 1, 51
RAK7249/4240 in-built LoRa server
IP address 192, 168, 1, 227
This sketch connects to an MQTT server then -
- subscribes to the topic "application/+/device/+/+"
- prints out any messages it receives.
- it assumes the received payloads are strings not binary
- it will reconnect to the server if the connection is lost using a blocking reconnect function.
*/
#include <SPI.h>
#include <Ethernet.h>
#include <PubSubClient.h>
// Update these with values suitable for your network.
byte mac[] = { 0xA8, 0x61, 0x0A, 0xAE, 0x6A, 0x0B };
IPAddress ip(192, 168, 1, 51); // Static IP address Arduino MQTT client
IPAddress server(192, 168, 1, 227); // Static IP address RAK7249 built-in LoRa server
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*);*
- }*
- Serial.println();*
}
EthernetClient ethClient;
PubSubClient client(ethClient);
void reconnect() { - // Loop until we're reconnected*
- while (!client.connected()) {*
- Serial.print("Attempting MQTT connection...");*
- // Attempt to connect*
- if (client.connect("arduinoClient")) {*
- Serial.println("connected");*
- // Once connected, publish an announcement...*
- // client.publish("outTopic","hello world");*
- // ... and resubscribe*
- client.subscribe("application/3/device/+/+");*
- } else {*
- Serial.print("failed, rc=");*
- Serial.print(client.state());*
- Serial.println(" try again in 5 seconds");*
- // Wait 5 seconds before retrying*
- delay(5000);*
- }*
- }*
}
void setup()
{ - Serial.begin(57600);*
- client.setServer(server, 1883);*
- client.setCallback(callback);*
- Ethernet.begin(mac, ip);*
- // Allow the hardware to sort itself out*
- delay(1500);*
}
void loop()
{ - if (!client.connected()) {*
- reconnect();*
- }*
- client.loop();*
}[/color]
>
The introductory comments detail hardware used and network details. It also references where I got the code. Please note that I have commented out the "publish" facility in the sketch. I don't require this.
The Serial Monitor shows -
Attempting MQTT connection...connected
Message arrived [application/3/device/00033bbcff12a631/join] {"applicationID":"3","applicationName":"draginonode2","deviceName":"dev-00033bbcff12a631","devEUI":"00033bbcff12a631","devAddr":"021ec28b"}
However, it shows nothing after that .... forever! The MQTT.fx, on the other hand, shows heaps of messages ending in "rx" and shows the whole payload. I can even get the topic up on my iPad and the continuous messages are there. That suggests to me that the node, gateway and MQTT is working. There is something not right in the Arduino MQTT client.
Now having said all that, I have tried several hardware combinations ostensibly running the same code and I get exactly the same result on the Arduino client. And to make matters worse, I have had this Arduino MQTT client working in the past. The only thing that has changed, I upgraded the firmware in the RAK4279. However, under that firmware, the MQTT.fx laptop still works perfectly.
Any help would be gratefully appreciated. Thank you. Regards