add retry to feeder

This commit is contained in:
Cyberes 2024-08-18 14:54:40 -06:00
parent d348bee04f
commit 85636814ed
2 changed files with 12 additions and 6 deletions

1
.gitignore vendored
View File

@ -1,4 +1,5 @@
.idea
test.sh
# ---> Python
# Byte-compiled / optimized / DLL files

View File

@ -43,12 +43,17 @@ client.loop_start()
def publish(topic: str, msg):
topic_expanded = MQTT_TOPIC_PREFIX + '/' + topic
retries = 10
for i in range(retries): # retry
result = client.publish(topic_expanded, msg)
status = result[0]
if status == 0:
logging.info(f"Sent {msg} to topic {topic_expanded}")
return
else:
logging.error(f"Failed to send message to topic {topic_expanded}: {result}")
logging.warning(f"Failed to send message to topic {topic_expanded}: {result}. Retry {i + 1}/{retries}")
time.sleep(10)
logging.error(f"Failed to send message to topic {topic_expanded}.")
def main():