logging for investigating

  • I have an issue. my device froze every few days. every time(like 2 times so far) it froze in same place. Every 5 minutes it's sends data over mqtt, and it is stuck there. It has small oled which displays the current state, thats how I know.

    I thinking about creating an sdlogger class, what writes out the current state of the machine.
    Can you recommend me some "built in system variables".
    I know gc.mem_free(), and gc.mem_alloc()

  • @tttadam

    If you have trouble with fragmentation, you have to redesign your program. Running the garbage collector will not help in all situations and small changes can get you into trouble again.

    You can reduce fragmentation by using precompiled scripts and allocating huge buffers at early stages. Reinitialize your buffers instead of allocating them each time.

  • @tttadam some update: turned out that the issue is not solved. just restarting automaticly.
    I still got the same error. with a coredump. Do you ave any tips where should I search the issue? thanks.
    Guru Meditation Error: Core 0 panic'ed (IllegalInstruction)
    . Exception was unhandled.
    Register dump:
    PC : 0x40121d00 PS : 0x00060d30 A0 : 0x80126f79 A1 : 0x3ffbd780
    A2 : 0x00000003 A3 : 0x00000001 A4 : 0x3ffcb7c4 A5 : 0xffffffff
    A6 : 0x00000001 A7 : 0x00000001 A8 : 0x8008ad8a A9 : 0x3ffbd780
    A10 : 0x00000003 A11 : 0x00060d23 A12 : 0x00060d20 A13 : 0x00000001
    A14 : 0x000000fe A15 : 0x3ffc8714 SAR : 0x0000001e EXCCAUSE: 0x00000000
    EXCVADDR: 0x00000000 LBEG : 0x40099934 LEND : 0x40099962 LCOUNT : 0xffffffff

    Backtrace: 0x40121d00:0x3ffbd780 0x40126f76:0x3ffbd7b0

  • @tttadam what should solved the issue that i fired gc.collect in some places which runs every 5 minutes.

  • eventualy I hooked it on a pc, and every few second a I wrote out these values.
    This is what I got. Do you have any idea what could go wrong? (probably it is related to ujson, cause it was working fine before I used that object. )

    Free Mem: 1520256
    Alloc Mem: 1041168
    Free Mem: 1515728
    Alloc Mem: 1045696
    Guru Meditation Error: Core 0 panic'ed (Unknown reason)
    Register dump:
    Guru Meditation Error: Core 0 panic'ed (Guru Meditation Error: Core 0 panic'ed (Guru Meditation Error: Core 0 panic'ed (ets Jun 8 2016 00:22:57

    rst:0x7 (TG0WDT_SYS_RESET),boot:0x33 (SPI_FAST_FLASH_BOOT)
    configsip: 0, SPIWP:0xee
    mode:DIO, clock div:1

  • I used a few of the Openlog Serial Data Logger UART loggers in the past (basically an external Arduino with SD card programmed to log everything they receive on RX pin)
    As independent devices they log even when the entire system crashes which is very convenient for tricky problems.

    Just search on Ebay or Aliexpress for Openlog Serial Data Logger, you'll find loads for around $3.

  • @tttadam said in logging for investigating:

    Is there any more? :D

    A try block will be useful as well. so you can catch i2c erros or similar stuff. Note that sys.print_exception() has a file parameter, so you can log them as well.

    A huge problem is that there is no working flush. So you have to secure each (deep)sleep, so all of the messages are written.

    Depending on the version the micropythonimplementation accepts the parameter print(flush=True) , but it seems to do nothing :(. Really strange in my eyes, when the system is designed to shutdown quite often.

  • Is there any more? :D

  • oh good topic, I need the same, because I have a similar problem. ;-)

Log in to reply

Pycom on Twitter