I had impression that I can setup a mqtt-broker so that it handles str-only data something like this https://github.com/divergentti/kotiauto ... rheille.py
and I can see at the broker error messages such as:
"MQTT to InfluxDB VirheSilta
Connected with result code 0
errors/sensors/esp32/error b'23.9.2020 klo 14:25:00 uptime: 20712 device: ESP32-kanalaPIR error: [Errno 113] EHOSTUNREACH memfree: 87056'"
where the mqtt-message is generated from an ESP32 like this: https://github.com/divergentti/kotiauto ... in/main.py
.... practically first collecting errors first to the file (translated to English):
Code: Select all
def report_error(error): # IN: str virhe = error text part try: f = open('errors.txt', "r") # if exists, skip except OSError: # does not exist, create one f = open('errors.txt', 'w') errormsg = str(resolve_time()) + " uptime: " + str(utime.ticks_ms()) + " device: " \ + str(CLIENT_ID) + " error: " + str(error) + " memfree: " + str(gc.mem_free()) f.write(errormsg) f.close() def check_errorfile(): try: f = open('errors.txt', "r") except OSError: return # Read the file and send to mqtt broker rows = f.readline() while rows: try: client.publish(AIHE_VIRHEET, str(rows), retain=False) rows = f.readline() except OSError as e: # Not working, lets boot restart_and_reconnect() # File read and reported, close and delete it f.close() os.remove('errors.txt')
For better error logging I propably shall write broker which collects error messages via mqtt to mtqq-server (mosquitto) flat file. Or should I try some ready-2-go solution for this type of logging? I guess snmp traps or remote syslog is out of question?