Arduino MQTT subscriber unable to connect to Broker over Ubiquiti PtP Link

First of all, this is my first time posting here, so i do apologise if this topic has already been solved,

I have a Mosquito MQTT broker, publishers and subscribers, the Publishers and Subscribers are Arduinos with Ethernet Shield for IP Communication and the Broker is running on an Ubuntu box.

I have everything running well except for the subscribers.

I will leave the sketches for both the Publishers and subscribers at the end of the email.

DESCRIPTION OF PROBLEM

When the subscribers are connected to the same physical Ethernet switch as the Broker, then they are able to connect to it (able to subscribe to the various Topics). From the IDE serial monitor I’m able to confirm this. However, they are unable to connect to the broker from a Point-To-Point wireless link (Ubiquiti NanoStation).
Please note: There is no issue with the Publishers – They work fine with same Ethernet Library and also over the Point-To-Point link.

REQUEST:

Could anyone please have a look at the sketch and see what I have done wrong. I have been battling this for the past few weeks with no success.

I will really appreciate you help.

Kind regards,
.

SKETCH FOR THE SUBSCRIBERS – THIS IS THE ONE WITH THE IP COMMUNICATION ISSUES OVER THE PtP LINK.

#include <PubSubClient.h>
#include <Ethernet.h>
const byte LIGHT_PIN = 3; // When activated goes high 5V output when remote key for Alarm panel is pressed
const byte POLICE_PANIC_PIN = 5; // When activated goes high 5V output when remote key for Alarm panel is pressed
const char ID = "Arduino9"; // Unique Name of our client device
const char TOPIC_B = "Outdoor/SecurityLight_Siren_Topic_B"; // Topic to Subscribe to
// Callback Function Header
void callback(char
topic, byte
payload, unsigned int length);

// Ethernet Shield Networking details (CHANGE THE DETAILS BELOW TO SUIT NETWORK ROUTER HUB CONFIGURATION)
byte mac[] = { 0xED, 0xED, 0xBE, 0xAD, 0xCE, 0xED }; // Unique Device Ethernet shield (W5100) MAC address
IPAddress ip(192, 168, 0, 224); // For Arduino #9 - Topic B Subscriber NEW Ethernet shield (W5100) IP address
IPAddress broker(192, 168, 0, 200); // NEW MTTQ server IP address

// PubSubClient client(wclient); // Setup MQTT client for WiFi Option

EthernetClient ethClient;
PubSubClient client(ethClient);

// Handle incomming messages from the broker
void callback(char* topic, byte* payload, unsigned int length) {
String response;

for (int i = 0; i < length; i++) {
response += (char)payload*;*

  • }*

  • Serial.print("Message has arrived for ");*

  • Serial.print(TOPIC_B);*

  • Serial.print(" ");*

  • Serial.println(response);*

  • Serial.println("Remote Control Security Light/Alarm response change of state");*

  • /// For Topic_B // Police State Panic Activation*

  • if(response == "help") // Turn the light on*

  • {*

  • digitalWrite(POLICE_PANIC_PIN, HIGH); // When the Remote Control through Alarm Panel is activated via message "help" Output 5V to SSR terminals*

  • digitalWrite(LIGHT_PIN, LOW); // onboard indicator LED turn on*

  • }*

  • else if(response == "block") // Turn the Police Strobe and Floodlights off*

  • {*

  • digitalWrite(POLICE_PANIC_PIN, LOW);// OV output - Turn output to the SSR terminals off.*

  • digitalWrite(LIGHT_PIN, HIGH); // onboard indicator LED turn off*

  • } *
    }
    // Reconnect to client
    void reconnect() {

  • // Loop until we're reconnected*

  • while (!client.connected()) {*

  • Serial.print("Attempting MQTT connection...");*

  • // Attempt to connect*

  • if(client.connect(ID)) {*

  • client.subscribe(TOPIC_B);*

  • Serial.println("connected");*

  • Serial.print("Subscribed to: ");*

  • Serial.println(TOPIC_B);*

  • Serial.println('\n');*

  • } else {*

  • Serial.println(" try again in 5 seconds");*

  • // Wait 5 seconds before retrying*

  • delay(5000);*

  • }*

  • }*
    }
    void setup() {

  • Serial.begin(115200); // Start serial communication at 115200 baud*

  • pinMode(POLICE_PANIC_PIN, OUTPUT); // Configure POLICE_PANIC_PIN as an output*

  • pinMode(LIGHT_PIN, OUTPUT); // Configure LIGHT_PIN as an output*

  • delay(100);*

  • client.setServer(broker, 1883);*

  • client.setCallback(callback);// Initialize the callback routine*

  • // Ethernet shield configuration*

  • Ethernet.begin(mac, ip);*

  • delay(1500); // Allow hardware to stabilize*

}
void loop() {

  • if (!client.connected()) // Reconnect if connection is lost*
  • {*
  • reconnect();*
  • }*
  • client.loop();*
    }

Does it work if one subscriber only is connected?

Do the subscribers have unique mac addresses?

CONTINUED:

SKETCH FOR THE PUBLISHERS:

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

// Declare global variables

const int Alarm_buttonPin = 2; // the number of the pushbutton pin // External INT0 /Pin to control the Alarm with // Constant value variable which we don't want changed
const int Flood_buttonPin = 3; // // the number of the pushbutton pin // External INT1 /Pin to control the flood light with // Constant value variable which we don't want changed
const int LedPin = 5; // the number of the MAIN ALARM LED pin
const int FloodledPin = 4; // temporary onboard LED // Turn on FLOOD Lights!
const char *ID = "Arduino222"; // Unique Name of our client device
const char *TOPIC_A = "Outdoor/SecurityLight_Siren_Topic_A"; // Topic to Subscribe to
const char *TOPIC_B = "Outdoor/SecurityLight_Siren_Topic_B"; // Topic to Subscribe to
const char *STATE_TOPIC = "Room/SecurityLight_Siren/State"; // Topic to Publish the light state to
const char *STATE_POLICE = "Room/SecurityLight_Siren/PoliceState"; // Topic to Publish the light state to

// variables will change:
volatile int buttonStateAlarm = 1; // variable for reading the pushbutton status
volatile int buttonStateFlood = 1; // variable for reading the pushbutton status

// Ethernet Shield Networking details (CHANGE THE DETAILS BELOW TO SUIT NETWORK ROUTER HUB CONFIGURATION)
byte mac[] = { 0xBE, 0xAA, 0xBB, 0xCC, 0xED, 0xAC }; // Ethernet shield Arduino Client#1 (W5100) MAC address
IPAddress ip(192, 168, 0, 222); // FIELD NEW Ethernet shield (W5100) Arduino#Pub1A IP address for #7
IPAddress broker(192, 168, 0, 200); // Canberra MTTQ server IP address
EthernetClient ethClient;
PubSubClient client(ethClient);

//PubSubClient client(wclient);
bool state=0;

// Reconnect to client
void reconnect() {
// Loop until we're reconnected
while (!client.connected()) {
Serial.print("Attempting MQTT connection...");
// Attempt to connect
if (client.connect(ID)) {
Serial.println("connected");
Serial.print("Publishing to: ");
Serial.println(TOPIC_A);
Serial.print(" And Publishing to: ");
Serial.println(TOPIC_B);
Serial.println('\n');

} else {
Serial.println(" try again in 5 seconds");
// Wait 5 seconds before retrying
delay(5000);
}
}
}

void setup() {
Serial.begin(115200); // Start serial communication at 115200 baud
// initialize the LED pins as outputs:
pinMode(LedPin, OUTPUT);
pinMode(FloodledPin, OUTPUT);
digitalWrite(LedPin,1);// Start off with off state
digitalWrite(FloodledPin,1); // Start off with off state
// initialize the pushbutton pin as an input:
pinMode(Alarm_buttonPin, INPUT);
pinMode(Flood_buttonPin, INPUT);
// Attach an interrupt to the ISR vector
attachInterrupt(0, pin_ISR_ALARM, CHANGE); // monitor an interrupt on Pin 2 but only trigger when Switch is held LOW
attachInterrupt(1, pin_ISR_FLOOD, CHANGE); // monitor an interrupt on Pin 3 but only trigger when Switch is held LOW
// attachInterrupt(0, pin_ISR_ALARM_OFF, FALLING); // monitor an interrupt on Pin 2 but only trigger when Switch is held LOW
// attachInterrupt(1, pin_ISR_FLOOD_OFF, FALLING); // monitor an interrupt on Pin 3 but only trigger when Switch is held LOW
delay(100); // allow UNO to settle with initialisation
// MTTQ parameters
client.setServer(broker, 1883);
// Ethernet shield configuration
Ethernet.begin(mac, ip);

delay(1500); // Allow hardware to stabilize

}

void loop() {
if (!client.connected()) // Reconnect if connection is lost
{
reconnect();
}
client.loop();
delay(100); // allow Broker to catch up with change of states (50 mSec)
// nothing else to do!
} // Closing main loop bracket

// 2 x Interrupt Service Routines Below:-
void pin_ISR_ALARM()
{
buttonStateAlarm = digitalRead(Alarm_buttonPin);
digitalWrite(LedPin,buttonStateAlarm );
if (buttonStateAlarm == 0)
{
client.publish(TOPIC_A, "on");
Serial.println((String)TOPIC_A + " => Alarm Siren on");
}
else
{
if (buttonStateAlarm == 1)
client.publish(TOPIC_A, "off");
Serial.println((String)TOPIC_A + " => Alarm Siren off");
}
}

void pin_ISR_FLOOD()
{
buttonStateFlood = digitalRead(Flood_buttonPin);
digitalWrite(FloodledPin,buttonStateFlood );
if (buttonStateFlood == 0)
{
client.publish(TOPIC_B, "help");
Serial.println((String)TOPIC_B + " => Flood Lights are now on");
}
else
{
if (buttonStateFlood == 1)
client.publish(TOPIC_B, "block");
Serial.println((String)TOPIC_B + " => Block it; Flood Lights are now turned off");
}
}