Skip to content

Commit

Permalink
net: lib: nrf_cloud: handle anchor type
Browse files Browse the repository at this point in the history
Handle location request responses fulfilled by a Wi-Fi anchor.
IRIS-7940

Signed-off-by: Justin Morton <[email protected]>
  • Loading branch information
jayteemo authored and cvinayak committed Jan 12, 2024
1 parent f72bdb3 commit bfd26ec
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -680,6 +680,7 @@ Libraries for networking
* An :c:struct:`nrf_cloud_obj_shadow_data` structure to the :c:struct:`nrf_cloud_evt` structure to be used during shadow update events.
* The :kconfig:option:`CONFIG_NRF_CLOUD_SEND_SERVICE_INFO_FOTA` Kconfig option to enable sending configured FOTA service info on the device's initial connection to nRF Cloud.
* The :kconfig:option:`CONFIG_NRF_CLOUD_SEND_SERVICE_INFO_UI` Kconfig option to enable sending configured UI service info on the device's initial connection to nRF Cloud.
* Support for handling location request responses fulfilled by a Wi-Fi anchor.

* Updated:

Expand Down
4 changes: 4 additions & 0 deletions include/net/nrf_cloud_defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@
#define NRF_CLOUD_LOCATION_KEY_DOREPLY "doReply"
#define NRF_CLOUD_LOCATION_JSON_KEY_WIFI "wifi"
#define NRF_CLOUD_LOCATION_JSON_KEY_APS "accessPoints"
#define NRF_CLOUD_LOCATION_JSON_KEY_ANCHORS "anchors"
#define NRF_CLOUD_LOCATION_JSON_KEY_ANC_NAME "name"
#define NRF_CLOUD_LOCATION_JSON_KEY_ANC_MAC "macAddress"
#define NRF_CLOUD_LOCATION_JSON_KEY_WIFI_MAC "macAddress"
#define NRF_CLOUD_LOCATION_JSON_KEY_WIFI_CH "channel"
#define NRF_CLOUD_LOCATION_JSON_KEY_WIFI_RSSI "signalStrength"
Expand All @@ -87,6 +90,7 @@
#define NRF_CLOUD_LOCATION_TYPE_VAL_MCELL "MCELL"
#define NRF_CLOUD_LOCATION_TYPE_VAL_SCELL "SCELL"
#define NRF_CLOUD_LOCATION_TYPE_VAL_WIFI "WIFI"
#define NRF_CLOUD_LOCATION_TYPE_VAL_ANCHOR "ANCHOR"

/* P-GPS */
#define NRF_CLOUD_JSON_PGPS_PRED_COUNT "predictionCount"
Expand Down
29 changes: 29 additions & 0 deletions subsys/net/lib/nrf_cloud/src/nrf_cloud_codec_internal.c
Original file line number Diff line number Diff line change
Expand Up @@ -2823,6 +2823,7 @@ static int nrf_cloud_parse_location_json(const cJSON *const loc_obj,
}

cJSON *lat, *lon, *unc;
bool anchor = false;
char *type;

lat = cJSON_GetObjectItem(loc_obj,
Expand All @@ -2849,13 +2850,41 @@ static int nrf_cloud_parse_location_json(const cJSON *const loc_obj,
location_out->type = LOCATION_TYPE_SINGLE_CELL;
} else if (!strcmp(type, NRF_CLOUD_LOCATION_TYPE_VAL_WIFI)) {
location_out->type = LOCATION_TYPE_WIFI;
} else if (!strcmp(type, NRF_CLOUD_LOCATION_TYPE_VAL_ANCHOR)) {
location_out->type = LOCATION_TYPE_WIFI;
anchor = true;
} else {
LOG_WRN("Unhandled location type: %s", type);
}
} else {
LOG_WRN("Location type not found in message");
}

/* Print anchor info */
if (anchor) {
cJSON *anchors, *mac, *name;
int anc_cnt;

/* Anchor info is provided in an array of objects */
anchors = cJSON_GetObjectItem(loc_obj, NRF_CLOUD_LOCATION_JSON_KEY_ANCHORS);
anc_cnt = cJSON_GetArraySize(anchors);

for (int idx = 0; idx < anc_cnt; ++idx) {
cJSON *anc = cJSON_GetArrayItem(anchors, idx);

mac = cJSON_GetObjectItem(anc, NRF_CLOUD_LOCATION_JSON_KEY_ANC_MAC);
name = cJSON_GetObjectItem(anc, NRF_CLOUD_LOCATION_JSON_KEY_ANC_NAME);

if (cJSON_IsString(mac)) {
LOG_DBG("Wi-Fi anchor MAC: %s", mac->valuestring);
}

if (cJSON_IsString(name)) {
LOG_INF("Wi-Fi anchor name: %s", name->valuestring);
}
}
}

return 0;
}

Expand Down

0 comments on commit bfd26ec

Please sign in to comment.