17
17
#endif /* CONFIG_MEMFAULT */
18
18
19
19
#include "message_channel.h"
20
- #include "app_object_decode.h"
21
20
22
21
/* Register log module */
23
22
LOG_MODULE_REGISTER (app , CONFIG_APP_LOG_LEVEL );
@@ -37,16 +36,13 @@ BUILD_ASSERT(CONFIG_APP_MODULE_WATCHDOG_TIMEOUT_SECONDS > CONFIG_APP_MODULE_EXEC
37
36
static void shadow_get (bool delta_only )
38
37
{
39
38
int err ;
40
- struct app_object app_object = { 0 };
41
- struct configuration configuration = { 0 };
42
- uint8_t buf_cbor [CONFIG_APP_MODULE_RECV_BUFFER_SIZE ] = { 0 };
43
- size_t buf_cbor_len = sizeof (buf_cbor );
44
- size_t not_used ;
39
+ uint8_t recv_buf [CONFIG_APP_MODULE_RECV_BUFFER_SIZE ] = { 0 };
40
+ size_t recv_buf_len = sizeof (recv_buf );
45
41
46
- LOG_DBG ("Requesting device configuration from the device shadow " );
42
+ LOG_DBG ("Requesting device shadow from the device" );
47
43
48
- err = nrf_cloud_coap_shadow_get (buf_cbor , & buf_cbor_len , delta_only ,
49
- COAP_CONTENT_FORMAT_APP_CBOR );
44
+ err = nrf_cloud_coap_shadow_get (recv_buf , & recv_buf_len , delta_only ,
45
+ COAP_CONTENT_FORMAT_APP_JSON );
50
46
if (err == - EACCES ) {
51
47
LOG_WRN ("Not connected, error: %d" , err );
52
48
return ;
@@ -65,111 +61,7 @@ static void shadow_get(bool delta_only)
65
61
return ;
66
62
}
67
63
68
- if (buf_cbor_len == 0 ) {
69
- LOG_DBG ("No shadow delta changes available" );
70
- return ;
71
- }
72
-
73
- /* Workaroud: Sometimes nrf_cloud_coap_shadow_get() returns 0 even though obtaining
74
- * the shadow failed. Ignore the payload if the first 10 bytes are zero.
75
- */
76
- if (!memcmp (buf_cbor , "\0\0\0\0\0\0\0\0\0\0" , 10 )) {
77
- LOG_WRN ("Returned buffer is empty, ignore" );
78
- return ;
79
- }
80
-
81
- err = cbor_decode_app_object (buf_cbor , buf_cbor_len , & app_object , & not_used );
82
- if (err ) {
83
- /* Do not throw an error if decoding fails. This might occur if the shadow
84
- * structure or content changes. In such cases, we need to ensure the possibility
85
- * of performing a Firmware Over-The-Air (FOTA) update to address the issue.
86
- * Hardfaulting would prevent FOTA, hence it should be avoided.
87
- */
88
- LOG_ERR ("Ignoring incoming configuration change due to decoding error: %d" , err );
89
- LOG_HEXDUMP_ERR (buf_cbor , buf_cbor_len , "CBOR data" );
90
-
91
- IF_ENABLED (CONFIG_MEMFAULT ,
92
- (MEMFAULT_TRACE_EVENT_WITH_STATUS (cbor_decode_app_object , err )));
93
-
94
- return ;
95
- }
96
-
97
- if (!app_object .lwm2m_present ) {
98
- LOG_DBG ("No LwM2M object present in shadow, ignoring" );
99
- return ;
100
- }
101
-
102
- if (app_object .lwm2m .lwm2m ._1424010_present ) {
103
- configuration .led_present = true;
104
-
105
- configuration .led_red = app_object .lwm2m .lwm2m ._1424010 ._1424010 ._0 ._0 ._0 ;
106
- configuration .led_red_present =
107
- app_object .lwm2m .lwm2m ._1424010 ._1424010 ._0 ._0_present ;
108
-
109
- configuration .led_green = app_object .lwm2m .lwm2m ._1424010 ._1424010 ._0 ._1 ._1 ;
110
- configuration .led_green_present =
111
- app_object .lwm2m .lwm2m ._1424010 ._1424010 ._0 ._1_present ;
112
-
113
- configuration .led_blue = app_object .lwm2m .lwm2m ._1424010 ._1424010 ._0 ._2 ._2 ;
114
- configuration .led_blue_present =
115
- app_object .lwm2m .lwm2m ._1424010 ._1424010 ._0 ._2_present ;
116
-
117
- LOG_DBG ("LED object (1424010) values received from cloud:" );
118
-
119
- if (configuration .led_red_present ) {
120
- LOG_DBG ("New RED value: %d" , configuration .led_red );
121
- }
122
-
123
- if (configuration .led_green_present ) {
124
- LOG_DBG ("New GREEN value: %d" , configuration .led_green );
125
- }
126
-
127
- if (configuration .led_blue_present ) {
128
- LOG_DBG ("New BLUE value: %d" , configuration .led_blue );
129
- }
130
-
131
- LOG_DBG ("Timestamp: %lld" , app_object .lwm2m .lwm2m ._1424010 ._1424010 ._0 ._99 );
132
- }
133
-
134
- if (app_object .lwm2m .lwm2m ._1430110_present ) {
135
- configuration .config_present = true;
136
-
137
- configuration .update_interval = app_object .lwm2m .lwm2m ._1430110 ._1430110 ._0 ._0 ._0 ;
138
- configuration .update_interval_present =
139
- app_object .lwm2m .lwm2m ._1430110 ._1430110 ._0 ._0_present ;
140
-
141
- configuration .gnss = app_object .lwm2m .lwm2m ._1430110 ._1430110 ._0 ._1 ._1 ;
142
- configuration .gnss_present = app_object .lwm2m .lwm2m ._1430110 ._1430110 ._0 ._1_present ;
143
-
144
- LOG_DBG ("Application configuration object (1430110) values received from cloud:" );
145
-
146
- if (configuration .update_interval_present ) {
147
- LOG_DBG ("New update interval: %lld" , configuration .update_interval );
148
- }
149
-
150
- if (configuration .gnss_present ) {
151
- LOG_DBG ("New GNSS setting: %d" , configuration .gnss );
152
- }
153
-
154
- LOG_DBG ("Timestamp: %lld" , app_object .lwm2m .lwm2m ._1430110 ._1430110 ._0 ._99 );
155
- }
156
-
157
- /* Distribute configuration */
158
- err = zbus_chan_pub (& CONFIG_CHAN , & configuration , K_SECONDS (1 ));
159
- if (err ) {
160
- LOG_ERR ("zbus_chan_pub, error: %d" , err );
161
- SEND_FATAL_ERROR ();
162
- return ;
163
- }
164
-
165
- /* Send the received configuration back to the reported shadow section. */
166
- err = nrf_cloud_coap_patch ("state/reported" , NULL , (uint8_t * )buf_cbor ,
167
- buf_cbor_len , COAP_CONTENT_FORMAT_APP_CBOR , true, NULL , NULL );
168
- if (err < 0 ) {
169
- LOG_ERR ("Failed to send PATCH request: %d" , err );
170
- } else if (err > 0 ) {
171
- LOG_ERR ("Error from server: %d" , err );
172
- }
64
+ /* No further processing of shadow is implemented */
173
65
}
174
66
175
67
static void task_wdt_callback (int channel_id , void * user_data )
0 commit comments