Cannot connect to hivemq server using LAN cable

I am new to Hivemq and I am using paho to connect to remote host. When I am using wifi I am able to connect and program works to me expectation. When I am using ethernet cable to connect my raspberry pi to my router, it is not working. Here is the code snippet.

def on_connect(client, userdata, flags, rc, properties=None):
print(“CONNACK received with code %s.” % rc)
def on_publish(client, userdata, mid, properties=None):
print("mid: " + str(mid))
def on_subscribe(client, userdata, mid, granted_qos, properties=None):
print("Subscribed: " + str(mid) )

print message, useful for checking if it was successful

def on_message(client, userdata, msg):
global start_PB
global stop_PB
print(msg.topic + " " + str(msg.qos) + " " + str(msg.payload))
instruction=msg.payload
print(instruction)
if instruction==‘START’:
start_PB=1
stop_PB=0
if instruction==‘STOP’:
start_PB=0
stop_PB=1
def on_disconnect(client,userdata,rc):
print(“Disconnected with code %s.” % rc)

client = paho.Client(client_id=“”, userdata=None, protocol=paho.MQTTv5)
client.on_connect = on_connect
client.on_disconnect=on_disconnect

client.tls_set(tls_version=mqtt.client.ssl.PROTOCOL_TLS)

client.username_pw_set(“xxxxx”, “yyyyyyy”)
client.connect(“mqtt-dev.myserver.com”, 1883)

client.on_subscribe = on_subscribe
client.on_message = on_message
client.on_publish = on_publish

client.subscribe(“Instructions”, qos=1)

client.loop()

For LAN connection I am getting following prints I have written in the code
CONNACK received with code
Subscribed: 1

But I am not getting this print below, which I am getting at Wifi connection
START

I know this message START is sent in the subscribed channel and it is supposed to be printed and it is indeed getting printed when I am at wifi

Hello @nilabhra
Welcome to the HiveMQ community forum! It’s great to see your interest in MQTT and HiveMQ.

It seems that your issue might stem from differences in network behavior when switching from WiFi to Ethernet. Here are a few things to check:

  1. Network Configuration Differences:
  • Verify your router’s settings for both WiFi and Ethernet. Sometimes different firewall or network isolation rules are applied to Ethernet connections.
  • Ensure your Raspberry Pi gets the correct IP address over Ethernet. Compare this to the address when connected via WiFi, and make sure the MQTT broker is accessible over Ethernet.
  1. Port Configuration:
  • You’re connecting to the MQTT broker on port 1883, which is typically used for non-TLS connections. Ensure your router allows traffic on this port when using Ethernet.
  1. Firewall and Security Settings:
  • Check if there are any firewall rules on your router that might block MQTT traffic over Ethernet.
  • Confirm that the Raspberry Pi’s firewall (if any) allows outbound connections through the Ethernet interface.
  1. TLS Configuration:

Regards,
Sheetal from HiveMQ Team