Hi,
I'm working on a project using the Thingy91x for prototyping. I'm using A-GNSS from nRF Cloud and although this is working, I'm not sure of the correct order of commands to use it correctly without resorting to unnecessary delays.
At the moment, I issue nrf_cloud_agnss_request_all() and then poll nrf_cloud_agnss_request_in_progress(). The problem is that the MQTT data arrives in two batches and request_in_progress only seems to cover the first one. I'm also unsure of when to disconnect from nRF Cloud, prior to starting the modem in GNSS mode. Can you give me advice on the most reliable way to confirm delivery of both agnss packets and how to tell when the modem has been loaded with the data?
Here is my current code:
struct nrf_modem_gnss_agnss_data_frame lastAgnss;
// Get A-GNSS data. In this case all data.
int result { nrf_cloud_agnss_request_all() };
if (result < 0)
{
LOG_ERR("A-GNSS request failed: error %d!", result);
return locationResult;
}
LOG_INF("A-GNSS request sent, waiting for processing...");
// POLL until request is complete
int64_t startTime = k_uptime_get();
int64_t timeoutMs = 10000; // 10 second timeout
while (nrf_cloud_agnss_request_in_progress()) {
if (k_uptime_delta(&startTime) > timeoutMs) {
LOG_WRN("A-GNSS request timeout!");
break;
}
k_sleep(K_MSEC(1000));
}
nrf_cloud_agnss_processed(&lastAgnss);
LOG_INF("ephe 0x%08llx, alm 0x%08llx, flags 0x%02x",
lastAgnss.system->sv_mask_ephe,
lastAgnss.system->sv_mask_alm,
lastAgnss.data_flags);
int64_t elapsed = k_uptime_delta(&startTime);
LOG_INF("A-GNSS processing complete in %lld ms", elapsed);
//////////////////////////
k_sleep(K_MSEC(3000));
disconnectFromNrfCloud();
// Try GNSS.
LOG_INF("Attempting GNSS positioning...");
locationResult = tryGnss(GNSS_TIMEOUT_SEC);
if (locationResult.success) {
LOG_INF("GNSS fix successful.");
disconnectFromNrfCloud();
return locationResult;
}
// Fallback to WiFi
And here is the relevant output:
[00:00:27.356,048] <inf> location: >>> Cloud event: type=300549, status=0 <<<
[00:00:27.356,048] <inf> location: Nrf Cloud ready.
[00:00:27.356,109] <inf> location: Connected to Nrf Cloud!
[00:00:27.356,628] <inf> nrf_cloud_info: Team ID: 71efa182-08ee-4647-b702-afa3cb32e6c0
[00:00:27.400,543] <dbg> nrf_cloud_codec_internal: json_send_to_cloud: Created request: {"appId":"AGNSS","messageType":"DATA","data":{"mcc":272,"mnc":5,"tac":41600,"eci":1515272,"rsrp":-102,"types":[1,2,3,9,12,11,13,4,5,6,7,8]}} (size: 140)
[00:00:27.400,604] <dbg> nrf_cloud_transport: endp_send: mqtt_publish: id = 1000 len = 140, topic: prod/71efa182-08ee-4647-b702-afa3cb32e6c0/m/d/5034474b-3731-4b68-80d9-0e234ccfe0f0/d2c
[00:00:27.400,665] <dbg> nrf_cloud_transport: endp_send: payload: {"appId":"AGNSS","messageType":"DATA","data":{"mcc":272,"mnc":5,"tac":41600,"eci":1515272,"rsrp":-102,"types":[1,2,3,9,12,11,13,4,5,6,7,8]}}
[00:00:27.402,648] <dbg> nrf_cloud_codec_internal: json_send_to_cloud: Request sent to cloud
[00:00:27.402,954] <inf> location: A-GNSS request sent, waiting for processing...
[00:00:27.826,324] <dbg> nrf_cloud_transport: nct_mqtt_evt_handler: MQTT_EVT_PUBACK: id = 1000 result = 0
[00:00:28.477,325] <dbg> nrf_cloud_transport: nct_mqtt_evt_handler: MQTT_EVT_PUBLISH: id = 1 len = 1945, topic = prod/71efa182-08ee-4647-b702-afa3cb32e6c0/m/d/5034474b-3731-4b68-80d9-0e234ccfe0f0/agnss/r
[00:00:28.564,208] <dbg> nrf_cloud_fsm: agnss_process: A-GNSS data processed
[00:00:28.716,491] <dbg> nrf_cloud_transport: nct_mqtt_evt_handler: MQTT_EVT_PUBLISH: id = 2 len = 1521, topic = prod/71efa182-08ee-4647-b702-afa3cb32e6c0/m/d/5034474b-3731-4b68-80d9-0e234ccfe0f0/agnss/r
[00:00:28.799,499] <dbg> nrf_cloud_fsm: agnss_process: A-GNSS data processed
[00:00:29.403,228] <inf> location: ephe 0xfffffffffbffffff, alm 0xffffffffffffffff, flags 0x3f
[00:00:29.403,259] <inf> location: A-GNSS processing complete in 1000 ms
[00:00:32.403,381] <inf> location: Attempting GNSS positioning...
[00:00:32.403,411] <inf> location: Configuring GNSS...
[00:00:32.403,411] <inf> location: GNSS config step 1: Setting fix retry to 0...
[00:00:32.410,675] <inf> location: Fix retry set.
[00:00:32.410,705] <inf> location: GNSS config step 2: Setting fix interval to 0...
[00:00:32.417,968] <inf> location: Fix interval set.
[00:00:32.417,999] <inf> location: GNSS config step 3: Setting use case...
[00:00:32.419,281] <inf> location: Use case set.
[00:00:32.419,311] <inf> location: GNSS configured for single fix with A-GNSS.
[00:00:32.542,327] <dbg> nrf_cloud: nrf_cloud_run: Socket error: POLLERR
[00:00:32.542,358] <dbg> nrf_cloud: nrf_cloud_run: Cloud connection was unexpectedly closed
[00:00:32.542,694] <dbg> nrf_cloud: nfsm_set_current_state_and_notify: state: 1
[00:00:32.542,694] <inf> location: >>> Cloud event: type=300556, status=3 <<<
[00:00:32.542,724] <inf> location: Nrf Cloud disconnected.
[00:00:32.542,724] <dbg> nrf_cloud_transport: nct_disconnect: Disconnecting
[00:00:32.546,875] <dbg> nrf_cloud_transport: nct_mqtt_evt_handler: MQTT_EVT_DISCONNECT: result = -115
[00:00:32.546,905] <dbg> nrf_cloud_fsm: drop_event_handler: Dropping FSM transition 10, current state 1
[00:00:32.707,977] <inf> modem: 2-RRC mode: Idle.
[00:00:32.844,635] <inf> modem: Sending AT command: AT+CFUN?
[00:00:32.845,031] <inf> modem: AT response: +CFUN: 4
OK
.
[00:00:32.845,062] <inf> modem: Sending AT command: AT+CFUN?
[00:00:32.845,428] <inf> modem: AT response: +CFUN: 4
OK
.
[00:00:32.845,428] <inf> location: powerOff: 370688, offline: 370689
[00:00:34.851,409] <inf> location: Starting GNSS and requesting A-GNSS data...
[00:00:34.851,440] <inf> location: startGNSS: Initialising state flags...
[00:00:34.851,440] <inf> location: startGNSS: Calling nrf_modem_gnss_start()...
[00:00:34.864,654] <inf> location: GNSS started successfully.
[00:00:34.864,654] <inf> location: Waiting for GNSS fix (timeout: 60 seconds)...
[00:00:34.926,605] <inf> location: === GNSS Event Handler >> Event: 1 ===
[00:00:34.926,635] <inf> location: GNSS: PVT event.
[00:00:35.909,301] <inf> location: === GNSS Event Handler >> Event: 1 ===
Any help would be greatly appreciated.
Andy