@@ -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+
1722static cloud_wrap_evt_handler_t wrapper_evt_handler ;
1823
1924static 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+
6481static 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