-
My goal is: to publish an ISO8601 Compliant TimeStamp to MQTT
-
My actions are:
-
Note that I have recently updated mos, 2.18.0 -> 74~brew.
-
I have added a
sys.tz_spec
in mymos.yml
and written code using thestrftime()
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
andstrftime()
.
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. */
- 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
- 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()?