zanac / pyHPSU

Python Script to read and send commands to a Rotex HPSU
29 stars 21 forks source link

canpi.py - Inserire messaggio in log errore #6

Open EmilianoMaina opened 7 years ago

EmilianoMaina commented 7 years ago

I log non includono il messaggio che ha determinato l'errore per cui non si puo' fare analisi.

Aggiungere il messaggio che ha determinato l'errore nel log.

try: msg = can.Message(arbitration_id=receiver_id, data=msg_data, extended_id=False, dlc=7) self.bus.send(msg) except Exception: self.hpsu.printd('exception', 'Error sending msg')

    while notTimeout:
        i += 1
        timeout = self.timeout
        rcBUS = None
        try:
            rcBUS = self.bus.recv(timeout)
        except Exception:
            **self.hpsu.printd('exception', 'Error recv')**                    

        if rcBUS:
            if (msg_data[2] == 0xfa and msg_data[3] == rcBUS.data[3] and msg_data[4] == rcBUS.data[4]) or (msg_data[2] != 0xfa and msg_data[2] == rcBUS.data[2]):
                rc = "%02X %02X %02X %02X %02X %02X %02X" % (rcBUS.data[0], rcBUS.data[1], rcBUS.data[2], rcBUS.data[3], rcBUS.data[4], rcBUS.data[5], rcBUS.data[6])
                notTimeout = False

        if notTimeout:
            **self.hpsu.printd('warning', 'msg not sync, retry: %s' % i)**
            if i >= 15:
                **self.hpsu.printd('error', 'msg not sync, timeout')**
                notTimeout = False
                rc = "KO"
zanac commented 7 years ago

La funzione printd con parametro exception forza la libreria di logging a stampare tutto il dump dell'eccezione, il ticket è errato: un dump comprende messaggio e tutti i dati necessari per fare analisi!

EmilianoMaina commented 7 years ago

Le informazioni nei log non ci sono !!!

pi@raspberrypi:~ $ tail -20f hpsu.fast.log 2017-02-16 21:17:40,034 - ERROR - msg not sync, timeout 2017-02-16 21:17:41,035 - ERROR - command t_r1 failed 2017-02-16 21:31:14,999 - ERROR - msg not sync, timeout 2017-02-16 21:31:16,001 - ERROR - msg not sync, timeout 2017-02-16 21:31:17,003 - ERROR - msg not sync, timeout 2017-02-16 21:31:18,006 - ERROR - msg not sync, timeout 2017-02-16 21:31:19,010 - ERROR - msg not sync, timeout 2017-02-16 21:31:20,019 - ERROR - msg not sync, timeout 2017-02-16 21:31:21,022 - ERROR - msg not sync, timeout 2017-02-16 21:31:22,024 - ERROR - command t_dhw1 failed 2017-02-16 21:31:22,027 - ERROR - msg not sync, timeout 2017-02-16 21:31:23,031 - ERROR - msg not sync, timeout 2017-02-16 21:31:24,033 - ERROR - msg not sync, timeout 2017-02-16 21:31:25,039 - ERROR - msg not sync, timeout 2017-02-16 21:31:26,041 - ERROR - command t_vbh failed 2017-02-16 21:31:26,042 - ERROR - msg not sync, timeout 2017-02-16 21:31:27,045 - ERROR - msg not sync, timeout 2017-02-16 21:31:28,048 - ERROR - msg not sync, timeout 2017-02-16 21:31:29,051 - ERROR - msg not sync, timeout 2017-02-16 21:31:30,057 - ERROR - command t_r1 failed

EmilianoMaina commented 7 years ago

Lo script di lancio e':

pi@raspberrypi:~ $ more hpsu.fast.sh

! /bin/bash

python3 /home/pi/pyHPSU-master/pyHPSU.py -d PYCAN -c flow_rate -c mode -c bpv -c posmix -c t_v1 -c t_dhw1 -c t_vbh -c t_r1 -c tliq2 -c ehs -c pump -o CLOUD -u EMONCMS -g /home/pi/hpsu.fast.log -v 1

zanac commented 7 years ago

Il log evidenzia come non è mai andato in exception, il printd exception è quindi ok. Imparare leggere i log please.

EmilianoMaina commented 7 years ago

Purtroppo non si vede il grassetto nel codice (ha messo gli ****). Il problema e' che il dato oggetto di errore non viene MAI stampato per cui non puoi associare le informazioni. La segnalazione non era relativa al solo caso di exception. Va aggiunto in tutti i casi (e.g. "ERROR - msg not sync, timeout".

Impara a leggere le segnalazioni !