diff options
author | xengineering <me@xengineering.eu> | 2025-03-21 22:07:26 +0100 |
---|---|---|
committer | xengineering <me@xengineering.eu> | 2025-03-21 22:07:26 +0100 |
commit | fcbd6ac3415d4a122d21b2e379ccf170620f45da (patch) | |
tree | 9d13560f540ce89a737192f731bdcfeabb76d899 | |
parent | 5f457c4786b270f0918294b09f32c484f165e2ef (diff) | |
download | iot-contact-fcbd6ac3415d4a122d21b2e379ccf170620f45da.tar iot-contact-fcbd6ac3415d4a122d21b2e379ccf170620f45da.tar.zst iot-contact-fcbd6ac3415d4a122d21b2e379ccf170620f45da.zip |
fw: syslog: Add static syslog logging
Network-based logging via the syslog protocol allows to log from many
IoT devices to a central log server.
This makes reading logs way easier. Choosing UDP removes the need for
logic keeping a state. Maybe dropped packages are acceptable for the use
case but should be rare anyway.
-rw-r--r-- | fw/CMakeLists.txt | 1 | ||||
-rw-r--r-- | fw/prj.conf | 12 | ||||
-rw-r--r-- | fw/src/main.c | 1 | ||||
-rw-r--r-- | fw/src/syslog.c | 23 |
4 files changed, 36 insertions, 1 deletions
diff --git a/fw/CMakeLists.txt b/fw/CMakeLists.txt index 6ba8cec..522a4dd 100644 --- a/fw/CMakeLists.txt +++ b/fw/CMakeLists.txt @@ -20,4 +20,5 @@ project(iot-contact-fw) target_sources(app PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/src/main.c" + "${CMAKE_CURRENT_SOURCE_DIR}/src/syslog.c" ) diff --git a/fw/prj.conf b/fw/prj.conf index 9c84c48..9ac1b51 100644 --- a/fw/prj.conf +++ b/fw/prj.conf @@ -7,3 +7,15 @@ CONFIG_SHELL_PROMPT_UART="[iot-contact] " CONFIG_NETWORKING=y CONFIG_NET_SHELL=y +CONFIG_NET_SOCKETS=y + +CONFIG_LOG=y +CONFIG_LOG_BACKEND_NET=y +CONFIG_LOG_BACKEND_NET_SERVER="[2001:db8::2]:514" +CONFIG_LOG_MODE_DEFERRED=y + +# static IP address configuration is currently required for successful syslog +CONFIG_NET_CONFIG_SETTINGS=y +CONFIG_NET_CONFIG_NEED_IPV6=y +CONFIG_NET_CONFIG_MY_IPV6_ADDR="2001:db8::1" +CONFIG_NET_IF_UNICAST_IPV6_ADDR_COUNT=3 diff --git a/fw/src/main.c b/fw/src/main.c index 228422c..faba14b 100644 --- a/fw/src/main.c +++ b/fw/src/main.c @@ -4,7 +4,6 @@ * obtain one at https://mozilla.org/MPL/2.0/. */ - int main(void) { return 0; diff --git a/fw/src/syslog.c b/fw/src/syslog.c new file mode 100644 index 0000000..fb15ab8 --- /dev/null +++ b/fw/src/syslog.c @@ -0,0 +1,23 @@ +/* + * This Source Code Form is subject to the terms of the Mozilla Public License, + * v. 2.0. If a copy of the MPL was not distributed with this file, You can + * obtain one at https://mozilla.org/MPL/2.0/. + */ + +#include <zephyr/init.h> +#include <zephyr/kernel.h> +#include <zephyr/logging/log.h> + +LOG_MODULE_REGISTER(syslog); + +int init_syslog() +{ + for(int i=0; i<5; i++) { + LOG_INF("Informational message number %d", i); + k_msleep(1000); + } + + return 0; +} + +SYS_INIT(init_syslog, APPLICATION, 50); |