I am trying to use MQTT to transfer a small (4k) log file from one RPi to another RPi.
Any idea what causes this error?
The code I am running is still a test, but here it is ...
import paho.mqtt.client as mqtt
import time
def on_message(mosq, obj, msg): # Function to retrieve file when received
with open('/var/www/html/alarmlog.txt', 'wb') as fd:
fd.write(msg.payload)
client = mqtt.Client("P2") # Start MQTT Client, NB changed to P2
client.connect("192.168.1.203", 1883, 60) # Connect to server
client.subscribe("highmount/garageb/alarm/logfile",0)
client.on_message = on_message # This is key - it calls the function
#Main loop ------------------------------------------------------------------------------------------
try:
while True: # Loop and wait for next image
client.loop(5)
print("Alarm logfile fetched")
except KeyboardInterrupt:
print (" Control C breakout ....")