in functions/MqttClientPython3/MqttClientPython3.py [0:0]
def greengrass_mqtt_client_loop():
error = None
try:
mqtt_client.connect(HOST, PORT, 60)
# Blocking call that processes network traffic, dispatches callbacks and handles reconnecting.
mqtt_client.loop_forever()
except ConnectionRefusedError as e:
# Connection refused, try connecting again in 5 seconds
error = 'Connection to the MQTT server failed [' + str(e) + '], make sure it is running and the settings are correct'
except Exception as e:
# Something else went wrong
error = 'Something went wrong [' + str(e) + ']'
# If we get here we'll start log the error, if any, and loop again
if error is not None: logger.error(error)
logger.error('Reconnecting')
Timer(5, greengrass_mqtt_client_loop).start()