Hallo, ich habe das Modul "paho-mqtt" installiert, wo ich Daten verschicken kann, der Empfänger ist ein MQTT Broker, wenn ich am Server diesen Code habe:
Code
import paho.mqtt.client as mqtt
string = "hallo"
client = mqtt.Client()
client.connect("localhost", 1111, 60)
client.publish("topic", string)
client.disconnect()
und beim Client:
Code
import paho.mqtt.client as mqtt
import time
def on_message(client, userdata, msg):
print(msg.topic+" "+str(msg.payload))
client = mqtt.Client()
client.on_message = on_message
client.connect("192.168.178.22", 1111, 3) #ip, port und timeout
client.subscribe("topic") # das topic was man am server angegeben hat
#client.loop_forever()
client.loop_start()
time.sleep(33)
client.loop_stop()
#client.loop()
Alles anzeigen
habe, dann bricht die Verbindung immer ab, wenn der Server - auch kurzzeitig - vom Internet getrennt wird.
auch wenn ich client.loop() oder client.loop_forever() nehme.
Kann man das mittels mqtt regeln, oder muss man im Code etwas bauen (try, etc.)?