Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 8093

General discussion • Re: MQTT Publishing Cron Job Stopping Randomly

$
0
0

With my MQTT I find I need to put in try/except to ensure connection/publication.

What I suggest you do is trap to see what the error is causing the problem.
That's a good idea. I currently have the block I shared above inside of a try/except block, but just for a KeyboardInterrupt (ie, Ctrl+C-ing out of the script when I run it manually).

I added this second exception to the script:

Code:

 except Exception as e:         print("An error occured: {}".format(e))         with open("error_log.txt", "a") as file:                 file.write("An error occured:\n")                 file.write(str(e) + "\n")                 traceback.print_exc(file=file)                 file.write("-" * 20 + "\n")
I wonder what will pop up.

-Joe

Statistics: Posted by joebro391 — Wed May 07, 2025 9:36 pm



Viewing all articles
Browse latest Browse all 8093

Trending Articles