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