I've been trying to find answers or info about this question but without results yet. The idea is to publish the same topic into two different MQTT servers with python. I mean, something like this:
import paho.mqtt.client as paho
import datetime, time
mqttc = paho.Client()
host1 = "broker.hivemq.com" # the address of 1st mqtt broker
host2 = "192.168.1.200" # the address of 2nd mqtt broker
topic= "testingTopic"
port = 1883
def on_connect(mosq, obj, rc):
print("on_connect() "+str(rc))
mqttc.on_connect = on_connect
print("Connecting to " + host)
mqttc.connect(host1, port, 60)
mqttc.connect(host2, port, 60)
while 1:
# publish some data at a regular interval
now = datetime.datetime.now()
mqttc.publish(topic, now.strftime('%H:%M:%S')) #Publishing to MQTT1
mqttc.publish(topic, now.strftime('%H:%M:%S')) #Publishing to MQTT2
time.sleep(1)
So, the question is about the while statment... how can I do to publish the same topic into MQTT1 and MQTT2? As you can see, I want to have to posibility to publish that payload in MQTT broker that is running in internet, but if I lose internet connection, then I can pub/sub to MQTT broker in my LAN.