Skip to content

Commit 06089f2

Browse files
plskeggsrlubos
authored andcommitted
net: lib: nrf_cloud: misc improvements
Add missing support for NRF_CLOUD_TOPIC_STATE_TF. This should have been done for the MQTT JSONata Transform feature added a while back (unrelated to the gateway). Fix uninitialized variable issue in in_last_job(). Remove most of the conditionals for the gateway, but add one to fix up topic suffix. Signed-off-by: Pete Skeggs <peter.skeggs@nordicsemi.no>
1 parent 2276840 commit 06089f2

File tree

6 files changed

+20
-44
lines changed

6 files changed

+20
-44
lines changed

include/net/nrf_cloud.h

-8
Original file line numberDiff line numberDiff line change
@@ -625,14 +625,6 @@ struct nrf_cloud_gnss_data {
625625
};
626626
};
627627

628-
#ifdef CONFIG_NRF_CLOUD_GATEWAY
629-
/** @brief Structure to hold message received from nRF Cloud. */
630-
struct nrf_cloud_gw_data {
631-
struct nrf_cloud_data data;
632-
uint16_t id;
633-
};
634-
#endif
635-
636628
/** @brief Data to control behavior of the nrf_cloud library from the
637629
* cloud side. This data is stored in the device shadow.
638630
*/

subsys/net/lib/nrf_cloud/include/nrf_cloud_codec_internal.h

-12
Original file line numberDiff line numberDiff line change
@@ -413,18 +413,6 @@ int nrf_cloud_json_to_url_params_convert(char *const buf, const size_t buf_size,
413413
int nrf_cloud_ground_fix_url_encode(char *buf, size_t size, const char *base,
414414
const struct nrf_cloud_location_config *config);
415415

416-
#ifdef CONFIG_NRF_CLOUD_GATEWAY
417-
typedef int (*gateway_state_handler_t)(void *root_obj);
418-
419-
/** @brief Register a callback, which is called whenever the shadow changes.
420-
* The callback is passed a pointer to the shadow JSON document. The callback
421-
* should return 0 to allow further processing of shadow changes in
422-
* nrf_cloud_codec.c. It should return a negative error code only when the
423-
* shadow is malformed.
424-
*/
425-
void nrf_cloud_register_gateway_state_handler(gateway_state_handler_t handler);
426-
#endif
427-
428416
/** @brief Encode a log output buffer for transport to the cloud */
429417
int nrf_cloud_log_json_encode(struct nrf_cloud_log_context *ctx, uint8_t *buf, size_t size,
430418
struct nrf_cloud_data *output);

subsys/net/lib/nrf_cloud/src/nrf_cloud.c

+7
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,13 @@ int nrf_cloud_send(const struct nrf_cloud_tx_data *msg)
355355
if (current_state < STATE_CC_CONNECTED) {
356356
return -EACCES;
357357
}
358+
#if defined(CONFIG_NRF_CLOUD_MQTT_SHADOW_TRANSFORMS)
359+
} else if (msg->topic_type == NRF_CLOUD_TOPIC_STATE_TF) {
360+
/* State (shadow) updates need to have the control channel connected */
361+
if (current_state < STATE_CC_CONNECTED) {
362+
return -EACCES;
363+
}
364+
#endif
358365
} else {
359366
/* All other topics require device channel connected */
360367
if (current_state != STATE_DC_CONNECTED) {

subsys/net/lib/nrf_cloud/src/nrf_cloud_codec_internal.c

-23
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,6 @@ static bool modem_inf_initd;
5555
static int init_modem_info(void);
5656
#endif
5757

58-
#if defined(CONFIG_NRF_CLOUD_MQTT) && defined(CONFIG_NRF_CLOUD_GATEWAY)
59-
static gateway_state_handler_t gateway_state_handler;
60-
#endif
6158
static int shadow_connection_info_update(cJSON * device_obj);
6259

6360
static const char *const sensor_type_str[] = {
@@ -458,13 +455,6 @@ int nrf_cloud_sensor_data_encode(const struct nrf_cloud_sensor_data *sensor,
458455
return 0;
459456
}
460457

461-
#ifdef CONFIG_NRF_CLOUD_GATEWAY
462-
void nrf_cloud_register_gateway_state_handler(gateway_state_handler_t handler)
463-
{
464-
gateway_state_handler = handler;
465-
}
466-
#endif
467-
468458
int nrf_cloud_state_encode(uint32_t reported_state, const bool update_desired_topic,
469459
const bool add_info_sections, struct nrf_cloud_data *output)
470460
{
@@ -750,19 +740,6 @@ int nrf_cloud_shadow_data_state_decode(const struct nrf_cloud_obj_shadow_data *c
750740
cJSON *pairing_state_obj = NULL;
751741
cJSON *topic_prefix_obj = NULL;
752742

753-
#ifdef CONFIG_NRF_CLOUD_GATEWAY
754-
if (gateway_state_handler) {
755-
ret = gateway_state_handler(input->json);
756-
if (ret != 0) {
757-
LOG_ERR("Error from gateway_state_handler: %d", ret);
758-
return ret;
759-
}
760-
} else {
761-
LOG_ERR("No gateway state handler registered");
762-
return -EINVAL;
763-
}
764-
#endif /* CONFIG_NRF_CLOUD_GATEWAY */
765-
766743
if (input->type == NRF_CLOUD_OBJ_SHADOW_TYPE_ACCEPTED) {
767744
desired_obj = input->accepted->desired.json;
768745
} else if (input->type == NRF_CLOUD_OBJ_SHADOW_TYPE_DELTA) {

subsys/net/lib/nrf_cloud/src/nrf_cloud_fota.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ static void update_last_job(char const *const job_id)
121121

122122
static bool is_last_job(char const *const job_id)
123123
{
124-
bool match;
124+
bool match = false;
125125

126126
K_SPINLOCK(&last_job_slock) {
127127
match = (strncmp(last_job, job_id, sizeof(last_job)) == 0);

subsys/net/lib/nrf_cloud/src/nrf_cloud_transport.c

+12
Original file line numberDiff line numberDiff line change
@@ -1118,6 +1118,18 @@ int nct_dc_connect(void)
11181118
.message_id = NCT_MSG_ID_DC_SUB
11191119
};
11201120

1121+
#if defined(CONFIG_NRF_CLOUD_GATEWAY)
1122+
/** The topic for cloud to device we receive in the shadow for
1123+
* BLE gateway devices is incorrect. The <device_id>/+/r suffix is invalid and
1124+
* must be corrected here to be <device_id>/c2g. Using it without this
1125+
* change results in immediate disconnection from nRF Cloud.
1126+
*/
1127+
char *p = (char *)subscribe_topic.topic.utf8;
1128+
int l = subscribe_topic.topic.size;
1129+
1130+
memcpy(&p[l - 3], NRF_CLOUD_JSON_KEY_CLOUD_TO_DEVICE, 3);
1131+
#endif
1132+
11211133
LOG_DBG("Subscribing to:");
11221134
for (int i = 0; i < subscription_list.list_count; i++) {
11231135
LOG_DBG("%.*s", subscription_list.list[i].topic.size,

0 commit comments

Comments
 (0)