diff --git a/app/src/common/message_channel.h b/app/src/common/message_channel.h index 1b842dcf..c8ad3eda 100644 --- a/app/src/common/message_channel.h +++ b/app/src/common/message_channel.h @@ -43,9 +43,11 @@ enum cloud_status { }; struct configuration { + bool led_present; int led_red; int led_green; int led_blue; + bool config_present; bool gnss; uint64_t update_interval; }; diff --git a/app/src/modules/app/app.c b/app/src/modules/app/app.c index 50f42134..fa8cfc9b 100644 --- a/app/src/modules/app/app.c +++ b/app/src/modules/app/app.c @@ -69,24 +69,31 @@ static void shadow_get(bool get_desired) return; } - struct configuration configuration = { - .led_red = app_object.lwm2m._1424010._0._0, - .led_green = app_object.lwm2m._1424010._0._1, - .led_blue = app_object.lwm2m._1424010._0._2, - .gnss = app_object.lwm2m._1430110._0._1, - .update_interval = app_object.lwm2m._1430110._0._0, - }; - - LOG_DBG("LED object (1424010) values received from cloud:"); - LOG_DBG("R: %d", app_object.lwm2m._1424010._0._0); - LOG_DBG("G: %d", app_object.lwm2m._1424010._0._1); - LOG_DBG("B: %d", app_object.lwm2m._1424010._0._2); - LOG_DBG("Timestamp: %lld", app_object.lwm2m._1424010._0._99); - - LOG_DBG("Application configuration object (1430110) values received from cloud:"); - LOG_DBG("Update interval: %lld", app_object.lwm2m._1430110._0._0); - LOG_DBG("GNSS: %d", app_object.lwm2m._1430110._0._1); - LOG_DBG("Timestamp: %lld", app_object.lwm2m._1430110._0._99); + struct configuration configuration = { 0 }; + + if (app_object.lwm2m._1424010_present) { + configuration.led_present = true; + configuration.led_red = app_object.lwm2m._1424010._1424010._0._0; + configuration.led_green = app_object.lwm2m._1424010._1424010._0._1; + configuration.led_blue = app_object.lwm2m._1424010._1424010._0._2; + + LOG_DBG("LED object (1424010) values received from cloud:"); + LOG_DBG("R: %d", app_object.lwm2m._1424010._1424010._0._0); + LOG_DBG("G: %d", app_object.lwm2m._1424010._1424010._0._1); + LOG_DBG("B: %d", app_object.lwm2m._1424010._1424010._0._2); + LOG_DBG("Timestamp: %lld", app_object.lwm2m._1424010._1424010._0._99); + } + + if (app_object.lwm2m._1430110_present) { + configuration.config_present = true; + configuration.update_interval = app_object.lwm2m._1430110._1430110._0._0; + configuration.gnss = app_object.lwm2m._1430110._1430110._0._1; + + LOG_DBG("Application configuration object (1430110) values received from cloud:"); + LOG_DBG("Update interval: %lld", app_object.lwm2m._1430110._1430110._0._0); + LOG_DBG("GNSS: %d", app_object.lwm2m._1430110._1430110._0._1); + LOG_DBG("Timestamp: %lld", app_object.lwm2m._1430110._1430110._0._99); + } /* Distribute configuration */ err = zbus_chan_pub(&CONFIG_CHAN, &configuration, K_SECONDS(1)); diff --git a/app/src/modules/app/app_object.cddl b/app/src/modules/app/app_object.cddl index ae7aa4a2..a5522dd3 100644 --- a/app/src/modules/app/app_object.cddl +++ b/app/src/modules/app/app_object.cddl @@ -1,7 +1,7 @@ ; Define the basic structure of the JSON object app-object = { - "nrfcloud_mqtt_topic_prefix": tstr, - "pairing": pairing-type, + ? "nrfcloud_mqtt_topic_prefix": tstr, + ? "pairing": pairing-type, "lwm2m": lwm2m-map } @@ -15,15 +15,15 @@ pairing-type = { } lwm2m-map = { - "14240:1.0": led, - "14301:1.0": config + ? "14240:1.0": led, + ? "14301:1.0": config } led = { - "0": lwm2m_inner_object_1 + "0": led_inner_object } -lwm2m_inner_object_1 = { +led_inner_object = { "0": int .size 4, "1": int .size 4, "2": int .size 4, @@ -31,10 +31,10 @@ lwm2m_inner_object_1 = { } config = { - "0": lwm2m_inner_object + "0": config_inner_object } -lwm2m_inner_object = { +config_inner_object = { "0": int .size 8, "1": bool, "99": int .size 8 diff --git a/app/src/modules/led/led.c b/app/src/modules/led/led.c index 22ae3e13..7cb972be 100644 --- a/app/src/modules/led/led.c +++ b/app/src/modules/led/led.c @@ -48,6 +48,11 @@ void led_callback(const struct zbus_channel *chan) const struct configuration *config = zbus_chan_const_msg(chan); + if (config->led_present == false) { + LOG_DBG("LED configuration not present"); + return; + } + LOG_DBG("LED configuration: red:%d, green:%d, blue:%d", config->led_red, config->led_green, config->led_blue); diff --git a/app/src/modules/trigger/trigger.c b/app/src/modules/trigger/trigger.c index 6e5dbfc7..232b23a7 100644 --- a/app/src/modules/trigger/trigger.c +++ b/app/src/modules/trigger/trigger.c @@ -69,6 +69,11 @@ void trigger_callback(const struct zbus_channel *chan) /* Get update interval configuration from channel. */ const struct configuration *config = zbus_chan_const_msg(chan); + if (config->config_present == false) { + LOG_DBG("Configuration not present"); + return; + } + LOG_DBG("New update interval: %lld", config->update_interval); update_interval = K_SECONDS(config->update_interval);