Skip to content

Commit 8630a4d

Browse files
committed
app: Remove support for nRF Cloud MQTT
Use more lightweight CoAP protocol instead of MQTT. Signed-off-by: Juha Ylinen <juha.ylinen@nordicsemi.no>
1 parent 4c52d72 commit 8630a4d

9 files changed

Lines changed: 115 additions & 400 deletions

File tree

app/Kconfig

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,9 @@ endif # SM_NRF_CLOUD
262262
config SM_NRF_CLOUD_LOCATION
263263
bool "nRF Cloud Location support"
264264
depends on SM_NRF_CLOUD
265-
select NRF_CLOUD_LOCATION if NRF_CLOUD_MQTT
265+
help
266+
Enable the nRF Cloud Location service for cloud-assisted geolocation.
267+
Supports cellular and Wi-Fi positioning.
266268

267269
config SM_MQTTC
268270
bool "MQTT client support"

app/overlay-nrf_cloud-coap.conf

Lines changed: 0 additions & 17 deletions
This file was deleted.

app/prj.conf

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,8 @@ CONFIG_NVS=y
9696
# nRF Cloud
9797
CONFIG_SM_NRF_CLOUD_LOCATION=y
9898
CONFIG_NRF_CLOUD=y
99-
CONFIG_NRF_CLOUD_MQTT=y
99+
CONFIG_NRF_CLOUD_COAP=y
100+
CONFIG_NRF_CLOUD_COAP_DOWNLOADS=n
100101
CONFIG_NRF_CLOUD_FOTA=n
101102
CONFIG_NRF_CLOUD_AGNSS=y
102103
CONFIG_NRF_CLOUD_AGNSS_FILTERED=n
@@ -109,6 +110,12 @@ CONFIG_DATE_TIME=y
109110
CONFIG_MODEM_INFO=y
110111
CONFIG_MODEM_INFO_ADD_DATE_TIME=n
111112

113+
# CoAP client settings
114+
CONFIG_COAP_CLIENT_BLOCK_SIZE=1024
115+
CONFIG_COAP_CLIENT_THREAD_PRIORITY=0
116+
CONFIG_COAP_EXTENDED_OPTIONS_LEN_VALUE=96
117+
CONFIG_COAP_CLIENT_STACK_SIZE=2048
118+
112119
# UUID and JWT
113120
CONFIG_MODEM_JWT=y
114121

app/src/sm_at_gnss.c

Lines changed: 26 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,9 @@ static struct k_work agnss_req_work;
6161
#endif
6262
#if defined(CONFIG_NRF_CLOUD_PGPS)
6363
static struct k_work pgps_req_work;
64-
#if defined(CONFIG_NRF_CLOUD_COAP)
6564
static struct k_work pgps_coap_req_work;
6665
static struct gps_pgps_request pgps_coap_request;
6766
#endif
68-
#endif
6967

7068
#endif /* CONFIG_SM_NRF_CLOUD */
7169

@@ -322,31 +320,17 @@ static void agnss_requestor(struct k_work *)
322320
{
323321
int err;
324322
struct nrf_modem_gnss_agnss_data_frame req;
323+
static char agnss_rest_data_buf[NRF_CLOUD_AGNSS_MAX_DATA_SIZE];
324+
struct nrf_cloud_rest_agnss_request request = {
325+
NRF_CLOUD_REST_AGNSS_REQ_CUSTOM,
326+
&req,
327+
};
325328

326329
err = read_agnss_req(&req);
327330
if (err) {
328331
LOG_ERR("Failed to read A-GNSS request (%d).", err);
329332
return;
330333
}
331-
#if defined(CONFIG_NRF_CLOUD_MQTT)
332-
err = nrf_cloud_agnss_request(&req);
333-
if (err) {
334-
LOG_ERR("Failed to request A-GNSS data (%d).", err);
335-
} else {
336-
LOG_INF("A-GNSS data requested.");
337-
/* When A-GNSS data is received it gets injected in the background by
338-
* nrf_cloud_agnss_process() without notification. In the case where
339-
* CONFIG_NRF_CLOUD_PGPS=y, nrf_cloud_pgps_inject() (called on PGPS_EVT_AVAILABLE)
340-
* plays a role as A-GNSS expects P-GPS to process some of the data.
341-
*/
342-
}
343-
#endif
344-
#if defined(CONFIG_NRF_CLOUD_COAP)
345-
static char agnss_rest_data_buf[NRF_CLOUD_AGNSS_MAX_DATA_SIZE];
346-
struct nrf_cloud_rest_agnss_request request = {
347-
NRF_CLOUD_REST_AGNSS_REQ_CUSTOM,
348-
&req,
349-
};
350334

351335
struct nrf_cloud_rest_agnss_result result = {agnss_rest_data_buf,
352336
sizeof(agnss_rest_data_buf), 0};
@@ -371,7 +355,6 @@ static void agnss_requestor(struct k_work *)
371355
return;
372356
}
373357
LOG_INF("A-GNSS data received via CoAP.");
374-
#endif
375358
}
376359
#endif /* CONFIG_NRF_CLOUD_AGNSS */
377360

@@ -389,7 +372,6 @@ static void pgps_requestor(struct k_work *)
389372
}
390373
}
391374

392-
#if defined(CONFIG_NRF_CLOUD_COAP)
393375
static void pgps_coap_requestor(struct k_work *)
394376
{
395377
int err;
@@ -430,7 +412,6 @@ static void pgps_coap_requestor(struct k_work *)
430412

431413
LOG_INF("P-GPS predictions requested");
432414
}
433-
#endif
434415

435416
static void pgps_event_handler(struct nrf_cloud_pgps_event *event)
436417
{
@@ -483,10 +464,8 @@ static void pgps_event_handler(struct nrf_cloud_pgps_event *event)
483464
break;
484465
case PGPS_EVT_REQUEST:
485466
LOG_INF("PGPS_EVT_REQUEST");
486-
#if defined(CONFIG_NRF_CLOUD_COAP)
487467
memcpy(&pgps_coap_request, event->request, sizeof(pgps_coap_request));
488468
k_work_submit_to_queue(&sm_work_q, &pgps_coap_req_work);
489-
#endif
490469
break;
491470
}
492471
}
@@ -542,39 +521,43 @@ static int do_cloud_send_obj(struct nrf_cloud_obj *const obj)
542521
{
543522
int err;
544523

545-
#if defined(CONFIG_NRF_CLOUD_MQTT)
546-
struct nrf_cloud_tx_data msg = {
547-
.obj = obj,
548-
.topic_type = NRF_CLOUD_TOPIC_MESSAGE,
549-
.qos = MQTT_QOS_0_AT_MOST_ONCE
550-
};
551-
552-
err = nrf_cloud_send(&msg);
553-
if (err) {
554-
LOG_ERR("nrf_cloud_send failed, error: %d", err);
555-
}
556-
#endif
557-
#if defined(CONFIG_NRF_CLOUD_COAP)
558524
err = nrf_cloud_coap_obj_send(obj, true);
559525
if (err) {
560526
LOG_ERR("nrf_cloud_send failed, error: %d", err);
561527
}
562-
#endif
528+
563529
(void)nrf_cloud_obj_free(obj);
564530

565531
return err;
566532
}
567533

568534
static void send_location(struct nrf_modem_gnss_pvt_data_frame * const pvt_data)
569535
{
536+
#define CLOUD_GNSS_HEADING_ACC_LIMIT (float)60.0
537+
570538
static int64_t last_ts_ms = NRF_CLOUD_NO_TIMESTAMP;
571539
int err;
540+
541+
/* Map modem PVT data to nRF Cloud PVT structure */
542+
struct nrf_cloud_gnss_pvt pvt = {
543+
.lat = pvt_data->latitude,
544+
.lon = pvt_data->longitude,
545+
.accuracy = pvt_data->accuracy,
546+
.alt = pvt_data->altitude,
547+
.has_alt = 1,
548+
.speed = pvt_data->speed,
549+
.has_speed = pvt_data->flags & NRF_MODEM_GNSS_PVT_FLAG_VELOCITY_VALID,
550+
.heading = pvt_data->heading,
551+
.has_heading = pvt_data->heading_accuracy < CLOUD_GNSS_HEADING_ACC_LIMIT ? 1 : 0,
552+
};
553+
572554
struct nrf_cloud_gnss_data gnss = {
573555
.ts_ms = NRF_CLOUD_NO_TIMESTAMP,
574-
.type = NRF_CLOUD_GNSS_TYPE_MODEM_PVT,
575-
.mdm_pvt = pvt_data
556+
.type = NRF_CLOUD_GNSS_TYPE_PVT,
557+
.pvt = pvt,
576558
};
577-
NRF_CLOUD_OBJ_JSON_DEFINE(msg_obj);
559+
560+
NRF_CLOUD_OBJ_COAP_CBOR_DEFINE(msg_obj);
578561
/* On failure, NRF_CLOUD_NO_TIMESTAMP is used and the timestamp is omitted */
579562
(void)date_time_now(&gnss.ts_ms);
580563

@@ -907,9 +890,7 @@ static int sm_at_gnss_init(void)
907890
#endif
908891
#if defined(CONFIG_NRF_CLOUD_PGPS)
909892
k_work_init(&pgps_req_work, pgps_requestor);
910-
#if defined(CONFIG_NRF_CLOUD_COAP)
911893
k_work_init(&pgps_coap_req_work, pgps_coap_requestor);
912-
#endif
913894
#endif /* CONFIG_NRF_CLOUD_PGPS */
914895
#endif /* CONFIG_SM_NRF_CLOUD */
915896
k_work_init(&gnss_fix_send_work, gnss_fix_sender);

0 commit comments

Comments
 (0)