/* * 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 #include #include #include #include "settings.h" LOG_MODULE_DECLARE(settings); int init_settings(void) { int ret = settings_subsys_init(); if (ret < 0) { LOG_ERR("Subsystem init failed (%d)", ret); return ret; } LOG_INF("Subsystem initialized"); ret = settings_load(); if (ret < 0) { LOG_ERR("Failed to load settings (%d)", ret); return ret; } LOG_INF("Loaded settings"); return 0; } SYS_INIT(init_settings, APPLICATION, 50); int settings_to_json(void *buffer, size_t len) { static const char format[] = "{\"syslog\":{\"target\":{\"ip\":\"%s\"}}}\n"; char ip[100]; int ret = settings_runtime_get("syslog/target/ip", ip, sizeof(ip)); if (ret < 0) { LOG_ERR("Failed to get runtime setting syslog/target/ip (%d)", ret); return ret; } ret = snprintf(buffer, len, format, ip); if (ret >= len) { LOG_ERR("Buffer too small to serialize settings as JSON"); return -ENOMEM; } if (ret < 0) { LOG_ERR("Failed to serialize settings as JSON"); } return ret; }