Skip to content
This repository was archived by the owner on Jul 9, 2024. It is now read-only.

Commit af22d70

Browse files
author
GitHub Actions
committed
1 parent 2511347 commit af22d70

2 files changed

Lines changed: 57 additions & 3 deletions

File tree

src/cloud/cloud_codec/nrf_cloud/nrf_cloud_codec.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,13 @@ int cloud_codec_encode_neighbor_cells(struct cloud_codec_data *output,
245245
return -ENODATA;
246246
}
247247

248-
err = nrf_cloud_cell_pos_request_json_get(&info, false, &root_obj);
248+
/* Set the request location flag when encoding the cellular position request.
249+
* In general, the application does not care about
250+
* getting the location back from cellular position requests. However, this is
251+
* needed to ensure that the cellular location of the application
252+
* is visualized in the nRF Cloud web UI.
253+
*/
254+
err = nrf_cloud_cell_pos_request_json_get(&info, true, &root_obj);
249255
if (err) {
250256
LOG_ERR("nrf_cloud_cell_pos_request_json_get, error: %d", err);
251257
return -ENOMEM;

src/cloud/nrf_cloud_integration.c

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ LOG_MODULE_REGISTER(MODULE, CONFIG_CLOUD_INTEGRATION_LOG_LEVEL);
1414

1515
#define REQUEST_DEVICE_STATE_STRING ""
1616

17+
/* String used to filter out responses to
18+
* cellular position requests (neighbor cell measurements).
19+
*/
20+
#define CELL_POS_FILTER_STRING "CELL_POS"
21+
1722
static cloud_wrap_evt_handler_t wrapper_evt_handler;
1823

1924
static void cloud_wrapper_notify_event(const struct cloud_wrap_event *evt)
@@ -61,10 +66,23 @@ static int send_service_info(void)
6166
return 0;
6267
}
6368

69+
/* Function used to filter out responses to cellular position requests. */
70+
static int cell_pos_response_filter(char *response, size_t len)
71+
{
72+
ARG_UNUSED(len);
73+
74+
if (strstr(response, CELL_POS_FILTER_STRING) != NULL) {
75+
return -EINVAL;
76+
}
77+
78+
return 0;
79+
}
80+
6481
static void nrf_cloud_event_handler(const struct nrf_cloud_evt *evt)
6582
{
6683
struct cloud_wrap_event cloud_wrap_evt = { 0 };
6784
bool notify = false;
85+
int err;
6886

6987
switch (evt->type) {
7088
case NRF_CLOUD_EVT_TRANSPORT_CONNECTING:
@@ -78,8 +96,7 @@ static void nrf_cloud_event_handler(const struct nrf_cloud_evt *evt)
7896
cloud_wrap_evt.type = CLOUD_WRAP_EVT_CONNECTED;
7997
notify = true;
8098

81-
int err = send_service_info();
82-
99+
err = send_service_info();
83100
if (err) {
84101
LOG_ERR("Failed to send nRF Cloud service information");
85102
cloud_wrap_evt.type = CLOUD_WRAP_EVT_ERROR;
@@ -105,6 +122,17 @@ static void nrf_cloud_event_handler(const struct nrf_cloud_evt *evt)
105122
break;
106123
case NRF_CLOUD_EVT_RX_DATA:
107124
LOG_DBG("NRF_CLOUD_EVT_RX_DATA");
125+
126+
/* Filter out responses to cellular position requests. The application does not care
127+
* about getting its location back after neighbor cell measurements have been
128+
* sent to cloud.
129+
*/
130+
err = cell_pos_response_filter((char *)evt->data.ptr, evt->data.len);
131+
if (err) {
132+
LOG_DBG("Cellular position response received, aborting");
133+
return;
134+
}
135+
108136
cloud_wrap_evt.type = CLOUD_WRAP_EVT_DATA_RECEIVED;
109137
cloud_wrap_evt.data.buf = (char *)evt->data.ptr;
110138
cloud_wrap_evt.data.len = evt->data.len;
@@ -113,6 +141,26 @@ static void nrf_cloud_event_handler(const struct nrf_cloud_evt *evt)
113141
case NRF_CLOUD_EVT_USER_ASSOCIATION_REQUEST:
114142
LOG_WRN("NRF_CLOUD_EVT_USER_ASSOCIATION_REQUEST");
115143
LOG_WRN("Add the device to nRF Cloud and wait for it to reconnect");
144+
145+
/* It is expected that the application will disconnect and reconnect to nRF Cloud
146+
* several times during device association.
147+
*/
148+
149+
/* Explicitly disconnect the nRF Cloud transport library to clear its
150+
* internal state. This is needed by the library to allow subsequent calls to
151+
* nrf_cloud_connect(), which is necessary to complete device association.
152+
*/
153+
err = nrf_cloud_disconnect();
154+
if (err) {
155+
LOG_ERR("nrf_cloud_disconnect failed, error: %d", err);
156+
157+
/* If disconnection from nRF Cloud fails, the cloud module is notified with
158+
* an error. The application is expected to perform a reboot in order
159+
* to reconnect to nRF Cloud and complete device association.
160+
*/
161+
cloud_wrap_evt.type = CLOUD_WRAP_EVT_ERROR;
162+
notify = true;
163+
}
116164
break;
117165
case NRF_CLOUD_EVT_USER_ASSOCIATED:
118166
LOG_DBG("NRF_CLOUD_EVT_USER_ASSOCIATED");

0 commit comments

Comments
 (0)