How to properly activate zephyr logs with network syslog backend to work over LTE-M for nrf9160 custom device?
How to properly activate zephyr logs with network syslog backend to work over LTE-M for nrf9160 custom device?
Hi
So, we were able to get this up and running on our end (building for NCS 2.7.0 as v2.0.2 is rather old at this point). Here are the configs and source file used. Also I attached the log:
/* * Copyright (c) 2018 Intel Corporation. * * SPDX-License-Identifier: Apache-2.0 */ #include <zephyr/logging/log.h> LOG_MODULE_REGISTER(net_syslog_lte, LOG_LEVEL_DBG); #include <zephyr/kernel.h> #include <zephyr/logging/log_backend.h> #include <zephyr/logging/log_backend_net.h> #include <zephyr/logging/log_ctrl.h> #include <modem/lte_lc.h> #include <modem/nrf_modem_lib.h> #include <stdlib.h> BUILD_ASSERT(IS_ENABLED(CONFIG_LOG_BACKEND_NET), "syslog backend not enabled"); #define SLEEP_BETWEEN_PRINTS 3 extern const struct log_backend *log_backend_net_get(void); void begin_syslog(void) { LOG_INF("Begin logging to syslog..."); const struct log_backend *log_backend_net = log_backend_net_get(); if (log_backend_net->api->init != NULL) { log_backend_net->api->init(log_backend_net); } log_backend_activate(log_backend_net, NULL); } static int set_normal_mode(void) { int err; printk("Setting modem to normal mode...\n"); err = lte_lc_func_mode_set(LTE_LC_FUNC_MODE_NORMAL); if (err) { return err; } printk("Normal mode set.\n"); return 0; } void lte_connect(void) { // set_normal_mode(); int err = lte_lc_connect(); if (err) { LOG_ERR("Failed to connect to LTE, error: %d", err); return; } LOG_INF("LTE connected successfully"); } #define SLEEP_BETWEEN_LOG_PRINTS 10 // sec #define TOTAL_LOG_TIME 30 // sec void cycle_logs(void) { int i, count; /* Allow some setup time before starting to send data */ k_sleep(K_SECONDS(SLEEP_BETWEEN_LOG_PRINTS)); count = TOTAL_LOG_TIME / SLEEP_BETWEEN_LOG_PRINTS; i = count; do { LOG_ERR("Error message (%d)", i); LOG_WRN("Warning message (%d)", i); LOG_INF("Info message (%d)", i); LOG_DBG("Debug message (%d)", i); k_sleep(K_SECONDS(SLEEP_BETWEEN_LOG_PRINTS)); } while (--i); LOG_DBG("Stopped after %d msg", count); } void main(void) { int err; LOG_INF("Starting application..."); printk("Initializing modem library\n"); err = nrf_modem_lib_init(); if (err) { printk("Modem initialization failed, err %d\n", err); return err; } lte_connect(); begin_syslog(); cycle_logs(); while (1) { k_sleep(K_SECONDS(10)); } }
CONFIG_NCS_SAMPLES_DEFAULTS=y # Modem library CONFIG_NRF_MODEM_LIB=y # LTE link control CONFIG_LTE_LINK_CONTROL=y CONFIG_LTE_NETWORK_MODE_LTE_M=y # CONFIG_ENTROPY_GENERATOR=y # CONFIG_TEST_RANDOM_GENERATOR=y CONFIG_INIT_STACKS=y CONFIG_NET_PKT_RX_COUNT=32 CONFIG_NET_PKT_TX_COUNT=32 CONFIG_NET_BUF_RX_COUNT=32 CONFIG_NET_BUF_TX_COUNT=32 CONFIG_NET_SOCKETS=y CONFIG_NET_IF_UNICAST_IPV6_ADDR_COUNT=3 CONFIG_NET_IF_MCAST_IPV6_ADDR_COUNT=5 CONFIG_NET_LOG=y CONFIG_LOG=y CONFIG_NETWORKING=y CONFIG_NET_NATIVE=n CONFIG_NET_OFFLOAD=y CONFIG_NET_SOCKETS_OFFLOAD=y CONFIG_NET_DEFAULT_IF_OFFLOAD=y CONFIG_NET_IPV6=n CONFIG_NET_IPV4=y CONFIG_NET_UDP=y CONFIG_NET_TCP=y CONFIG_NET_LOG=y # Deferred mode is required, synchronous mode does not work with network syslog # as it would cause the sent packet to be malformed (contains only 1 byte data) CONFIG_LOG_MODE_DEFERRED=y CONFIG_NET_IPV6=n CONFIG_NET_IPV4=y CONFIG_NET_DHCPV4=n # CONFIG_NET_SHELL=y CONFIG_NET_CONFIG_SETTINGS=y CONFIG_NET_CONFIG_NEED_IPV6=n CONFIG_NET_CONFIG_NEED_IPV4=y # CONFIG_NET_CONFIG_MY_IPV6_ADDR="2001:db8::1" # CONFIG_NET_CONFIG_PEER_IPV6_ADDR="2001:db8::2" # CONFIG_NET_CONFIG_MY_IPV4_ADDR="192.0.2.1" # CONFIG_NET_CONFIG_PEER_IPV4_ADDR="192.0.2.2" # logging net backend config CONFIG_LOG_BACKEND_NET=y CONFIG_LOG_BACKEND_NET_SERVER="169.46.82.174:25736" # Get a proper libc by default in order to get working time function support CONFIG_REQUIRES_FULL_LIBC=y
*** Booting nRF Connect SDK v2.7.0-5cb85570ca43 *** *** Using Zephyr OS v3.6.99-100befc70c74 *** [00:00:00.414,154] <wrn> net_config: No auto-started network interface - network-bound app initialization skipped. [00:00:00.414,184] <inf> net_syslog_lte: Starting application... Initializing modem library [00:00:04.194,976] <inf> net_syslog_lte: LTE connected successfully [00:00:04.195,037] <inf> net_syslog_lte: Begin logging to syslog... [00:00:14.195,159] <err> net_syslog_lte: Error message (3) [00:00:14.195,190] <wrn> net_syslog_lte: Warning message (3) [00:00:14.195,190] <inf> net_syslog_lte: Info message (3) [00:00:14.195,220] <dbg> net_syslog_lte: cycle_logs: Debug message (3) [00:00:24.195,312] <err> net_syslog_lte: Error message (2) [00:00:24.195,343] <wrn> net_syslog_lte: Warning message (2) [00:00:24.195,343] <inf> net_syslog_lte: Info message (2) [00:00:24.195,373] <dbg> net_syslog_lte: cycle_logs: Debug message (2) [00:00:34.195,465] <err> net_syslog_lte: Error message (1) [00:00:34.195,495] <wrn> net_syslog_lte: Warning message (1) [00:00:34.195,495] <inf> net_syslog_lte: Info message (1) [00:00:34.195,526] <dbg> net_syslog_lte: cycle_logs: Debug message (1) [00:00:44.195,617] <dbg> net_syslog_lte: cycle_logs: Stopped after 3 msg
Best regards,
Simon
Perfectly. I also have no problems with compilation and logs in the shell. But nothing is received at the specified syslog server address "169.46.82.174:25736". You can specify the address of the server available to you and make sure...
Perfectly. I also have no problems with compilation and logs in the shell. But nothing is received at the specified syslog server address "169.46.82.174:25736". You can specify the address of the server available to you and make sure...