I have multiple python scripts running that all publish on to different MQTT Mosquitto channels / topics. All scripts start with the following code.
import paho.mqtt.client as mqtt
client = mqtt.Client("python_pub")
client.connect("localhost", 1883)
Then each script has a different publish command like
client.publish("TA/temp", temp)
or
client.publish("timer/time", time)
What happens is if I run one script it will publish successfully I can subscribe with another script.
However, if I run a second script, only the new one will publish. The other falls off.
Do I need to be using different ports or client names between the different python scripts?
Thanks!
The problem is the second line:
client = mqtt.Client("python_pub")
The "python_pub" is the client id and needs to be unique to each client that connects to the broker.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.