Publish for ISO8601 to MQTT Core Dump

  1. My goal is: to publish an ISO8601 Compliant TimeStamp to MQTT

  2. My actions are:

  • Note that I have recently updated mos, 2.18.0 -> 74~brew.

  • I have added a sys.tz_spec in my mos.yml and written code using the strftime() function to output a string for the ISO 8601 time specification. The code is running, and I am getting time publications, however I am now getting a core dump after some time has elapsed that seems to be related to the SNTP query to time.google.com.

  • I have also reviewed the forum questions and responses in this area and I see similar issues associated with sys.tz_spec and strftime().

I have similar code to what Ingrid describes here.
https://community.mongoose-os.com/t/cron-bug-just-started/1392
https://community.mongoose-os.com/t/cant-get-current-local-time-in-my-timezone/1832
https://community.mongoose-os.com/t/core-dump-after-setting-wifi/1704

from mos.yml

        config_schema:
        #I2C
         - ["i2c.enable", true]
         - ["i2c.sda_gpio", 21]
         - ["i2c.scl_gpio", 22]

        # Set timezone to Mountain Standard Time
         - ["sys.tz_spec", "MST7"]

    includes:
      - include  

    libs:
    # Defaults
      - origin: https://github.com/mongoose-os-libs/boards
      - origin: https://github.com/mongoose-os-libs/ca-bundle
      - origin: https://github.com/mongoose-os-libs/aws
      - origin: https://github.com/mongoose-os-libs/dash
      - origin: https://github.com/mongoose-os-libs/http-server
      - origin: https://github.com/mongoose-os-libs/ota-shadow
      - origin: https://github.com/mongoose-os-libs/ota-http-client
      - origin: https://github.com/mongoose-os-libs/ota-http-server
      - origin: https://github.com/mongoose-os-libs/rpc-service-config
      - origin: https://github.com/mongoose-os-libs/rpc-service-fs
      - origin: https://github.com/mongoose-os-libs/rpc-uart
      - origin: https://github.com/mongoose-os-libs/shadow
      - origin: https://github.com/mongoose-os-libs/sntp
    # Additions
      - origin: https://github.com/mongoose-os-libs/spi
      - origin: https://github.com/mongoose-os-libs/i2c

from main.c

        time_t now = time(0);
        struct tm timeinfo;
        localtime_r(&now, &timeinfo);
        char timestamp[25];
        strftime(timestamp, sizeof(timestamp), "%FT%T%z", &timeinfo);

        snprintf(topic, sizeof(topic), "event/esp32_xxxxxx"); 
        json_printf(&out, "{total_ram: %lu, free_ram: %lu, device: \"%s\", timestamp: \"%s\"}",
                         (unsigned long)mgos_get_heap_size(),
                         (unsigned long)mgos_get_free_heap_size(),
                         (char *)mgos_sys_config_get_device_id(),
                         timestamp);

         /*  Note: Desired Time Format is %Y-%m-%d %H:%M:%S%z, for example, 2021-01-28T13:15:24+00:00.   */
  1. The result I see is:
  • In the mos serial console I see listed 74~brew when I am expecting to see 2.19.0

  • The code is running, and I am getting time publications, however I am now getting a core dump after some time has elapsed that seems to be related to the SNTP query to time.google.com. The display in the mos tool serial console at the time of crash is as follows:

RAM: 286236, 224220 free 
[Feb 2 12:18:19.610] main.c:16 Tock uptime: 6993.03, RAM: 286236, 224208 free 
[Feb 2 12:18:20.610] main.c:16 Tick uptime: 6994.03, RAM: 286236, 224220 free 
[Feb 2 12:18:21.610] main.c:16 Tock uptime: 6995.03, RAM: 286236, 224220 free 
[Feb 2 12:18:22.321] mgos_sntp.c:95 SNTP query to time.google.com 
[Feb 2 12:18:22.371] mgos_sntp.c:59 SNTP reply from 216.239.35.12: time 1612293502.891547, local 1612293503.418388, delta -0.526841

I have tried to run mos debug-core-dump:

mos debug-code-dump

however, I get the error:

Error: /private/tmp/mos-20210111-26155-15sp7e/mos-b8341b5dca25fe86d6e22ce3e574a9413bab9f74/cli/debug_core_dump/debug_core_dump.go:209: --fw-elf-file is not set and could not be guessed
/private/tmp/mos-20210111-26155-15sp7e/mos-b8341b5dca25fe86d6e22ce3e574a9413bab9f74/cli/main.go:198: debug-core-dump failed
  1. My expectation & question is:
    It looks like I have gone down the same path as Ingrid above and have similar issues.
  • Can you give me any guidance on why I am seeing this crash and how to trouble shoot or fix this?
  • Why is the mos debug-code-dump not running?
  • Is there a better way to publish an ISO 8601 TimeStamp then using the sys.tz_spec or strftime()?

For mos debug-core-dump to work without any other flags (assuming there is only 1 core dump file), you have to run it in the root directory of your application and have the build directory present.
Or

mos debug-core-dump path_to_the_core_file --fw-elf-file path_to_the_elf_file

The elf file is located in the build/objs/ directory.

Thank you @nliviu,
I noticed a typo in my original post, it should be mos debug-core-dump not mos debug-code-dump. Somehow it feels like the later. Freudian slip?

I found this format worked from the build directory mos debug-core-dump ./path/coreDumpFile.xxx.yyy ./build/objs/file.elf

Remote debugging using 127.0.0.1:1234
Found core at 23 - 460928
Mapping DRAM: 335872 @ 0x3ffae000
Mapping /opt/Espressif/rom/rom.bin at 0x40000000
Mapping /fw.elf .iram0.vectors: 1024 @ 0x40080000
Mapping /fw.elf .iram0.text: 89172 @ 0x40080400
Mapping /fw.elf .dram0.data: 15636 @ 0x3ffb0000
Mapping /fw.elf .dram0.bss: 28480 @ 0x3ffb3d18
Mapping /fw.elf .flash.rodata: 171576 @ 0x3f400020
Mapping /fw.elf .flash.text: 725527 @ 0x400d0020
Dump contains FreeRTOS task info
Loaded core dump from last snippet in /core
0x400d3e36 in schedule_next_timer (td=0x3ffbef50, now=<optimized out>) at /mongoose-os/src/mgos_timers.c:72
72 /mongoose-os/src/mgos_timers.c: No such file or directory.
#0 0x400d3e36 in schedule_next_timer (td=0x3ffbef50, now=<optimized out>) at /mongoose-os/src/mgos_timers.c:72
#1 0x400d3e83 in schedule_next_timer (td=<optimized out>, now=8.3990927621331054e-309) at /mongoose-os/src/mgos_timers.c:74
#2 0x4016a4dc in lwip_netconn_do_delconn (m=0x0) at /opt/Espressif/esp-idf/components/lwip/lwip/src/api/api_msg.c:1248
#3 0x40082940 in mgos_mg_poll_cb (arg=<optimized out>)
at /data/fwbuild-volumes/latest/apps/esp_xxxxxx/esp32/build_contexts/build_ctx_310884764/deps/freertos/src/mgos_freertos.c:81
#4 0x4008284a in mgos_task (arg=<optimized out>)
at /data/fwbuild-volumes/latest/apps/esp_xxxxxx/esp32/build_contexts/build_ctx_310884764/deps/freertos/src/mgos_freertos.c:200
(gdb) 

Thanks for the help

Dear @nliviu,
I believe that the failed mos update that updated 2.18.0 to 74~brew was the source of this issue. I am at 2.19.0 now and running again.
All the best and thanks for all the help,
Jim