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

Commit 5d4db96

Browse files
author
GitHub Actions
committed
1 parent 6ad48de commit 5d4db96

10 files changed

Lines changed: 205 additions & 46 deletions

File tree

README.rst

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ Data types
6464
Data from multiple sensor sources are collected to construct information about the location, environment, and the health of the nRF9160-based device.
6565
The application supports the following data types:
6666

67+
.. _app_data_types:
68+
6769
+----------------+----------------------------+-----------------------------------------------+
6870
| Data type | Description | Identifiers |
6971
+================+============================+===============================================+
@@ -89,26 +91,29 @@ The application can be either in an active or in a passive state depending on th
8991
The device mode is a part of the application's real-time configurations.
9092
The device modes and their descriptions are listed in the following table:
9193

92-
+-------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------+----------------+
93-
| Real-time Configurations | Description | Default values |
94-
+=====================================+=============================================================================================================================================+================+
95-
| Device mode | Either in active or passive mode. | Active |
96-
+---------------+---------------------+---------------------------------------------------------------------------------------------------------------------------------------------+----------------+
97-
| Active | | Sample and publish data at regular intervals. | |
98-
| +---------------------+---------------------------------------------------------------------------------------------------------------------------------------------+----------------+
99-
| | Active wait time | Number of seconds between each sampling/publication. | 120 seconds |
100-
+---------------+---------------------+---------------------------------------------------------------------------------------------------------------------------------------------+----------------+
101-
| Passive | | Sample and publish data only if movement has been detected. | |
102-
| +---------------------+---------------------------------------------------------------------------------------------------------------------------------------------+----------------+
103-
| | Movement resolution | Sample and publish data after detecting movement. | |
104-
| | | Wait for a duration specified by the parameter until a movement triggers the next update. | 120 seconds |
105-
| +---------------------+---------------------------------------------------------------------------------------------------------------------------------------------+----------------+
106-
| | Movement timeout | Sample and publish data at a minimum of the time interval specified by the parameter. Not dependent on movement. | 3600 seconds |
107-
+---------------+---------------------+---------------------------------------------------------------------------------------------------------------------------------------------+----------------+
108-
| GPS timeout | Timeout for acquiring a GPS fix during sampling of the data. | 60 seconds |
109-
+-------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------+----------------+
110-
| Accelerometer threshold | Accelerometer threshold in m/s². Minimal absolute value in m/s² for the accelerometer readings to be considered as a valid movement. | 10 m/s² |
111-
+-------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------+----------------+
94+
+--------------------------------+--------------------------------------------------------------------------------------------------------------------------------------+----------------+
95+
| Real-time Configurations | Description | Default values |
96+
+================================+======================================================================================================================================+================+
97+
| Device mode | Either in active or passive mode. | Active |
98+
+----------+---------------------+--------------------------------------------------------------------------------------------------------------------------------------+----------------+
99+
| Active | | Sample and publish data at regular intervals. | |
100+
| +---------------------+--------------------------------------------------------------------------------------------------------------------------------------+----------------+
101+
| | Active wait time | Number of seconds between each sampling/publication. | 120 seconds |
102+
+----------+---------------------+--------------------------------------------------------------------------------------------------------------------------------------+----------------+
103+
| Passive | | Sample and publish data only if movement has been detected. | |
104+
| +---------------------+--------------------------------------------------------------------------------------------------------------------------------------+----------------+
105+
| | Movement resolution | Sample and publish data after detecting movement. | |
106+
| | | Wait for a duration specified by the parameter until a movement triggers the next update. | 120 seconds |
107+
| +---------------------+--------------------------------------------------------------------------------------------------------------------------------------+----------------+
108+
| | Movement timeout | Sample and publish data at a minimum of the time interval specified by the parameter. Not dependent on movement. | 3600 seconds |
109+
+----------+---------------------+--------------------------------------------------------------------------------------------------------------------------------------+----------------+
110+
| GPS timeout | Timeout for acquiring a GPS fix during sampling of the data. | 60 seconds |
111+
+--------------------------------+--------------------------------------------------------------------------------------------------------------------------------------+----------------+
112+
| Accelerometer threshold | Accelerometer threshold in m/s². Minimal absolute value in m/s² for the accelerometer readings to be considered as a valid movement. | 10 m/s² |
113+
+--------------------------------+--------------------------------------------------------------------------------------------------------------------------------------+----------------+
114+
| No Data List (NOD) | List containing :ref:`data types <app_data_types>` that is not included when the application samples data. | No entries |
115+
| | Currently, the application supports only APP_DATA_GNSS and APP_DATA_NEIGHBOR_CELLS. | (Request all) |
116+
+--------------------------------+--------------------------------------------------------------------------------------------------------------------------------------+----------------+
112117

113118
See :ref:`Kconfig options for default device configuration values <default_config_values>` for a list of configuration options that can set the default values of the device configuration parameters.
114119

src/cloud/cloud_codec/cloud_codec.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,17 @@ struct cloud_data_gps {
8080
bool queued : 1;
8181
};
8282

83+
/** Structure containing boolean variables used to enable/disable inclusion of the corresponding
84+
* data type in sample requests sent out by the application module.
85+
*/
86+
struct cloud_data_no_data {
87+
/** If this flag is set GNSS data is not included in sample requests. */
88+
bool gnss;
89+
90+
/** If this flag is set neighbor cell data is not included sample requests. */
91+
bool neighbor_cell;
92+
};
93+
8394
struct cloud_data_cfg {
8495
/** Device mode. */
8596
bool active_mode;
@@ -95,6 +106,8 @@ struct cloud_data_cfg {
95106
int movement_timeout;
96107
/** Accelerometer trigger threshold value in m/s2. */
97108
double accelerometer_threshold;
109+
/** Variable used to govern what data types are requested by the application. */
110+
struct cloud_data_no_data no_data;
98111

99112
/** Flags to signify if the corresponding data value is fresh and can be used. */
100113
bool active_mode_fresh : 1;
@@ -103,6 +116,7 @@ struct cloud_data_cfg {
103116
bool movement_resolution_fresh : 1;
104117
bool movement_timeout_fresh : 1;
105118
bool accelerometer_threshold_fresh : 1;
119+
bool nod_list_fresh : 1;
106120
};
107121

108122
struct cloud_data_accelerometer {

src/cloud/cloud_codec/json_common.c

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -840,6 +840,48 @@ int json_common_config_add(cJSON *parent, struct cloud_data_cfg *data, const cha
840840
values_added = true;
841841
}
842842

843+
if (data->nod_list_fresh) {
844+
cJSON *nod_list = cJSON_CreateArray();
845+
846+
if (nod_list == NULL) {
847+
err = -ENOMEM;
848+
goto exit;
849+
}
850+
851+
/* If a flag in the no_data structure is set to true the corresponding JSON entry is
852+
* added to the no data array configuration.
853+
*/
854+
if (data->no_data.gnss) {
855+
cJSON *gnss_str = cJSON_CreateString(CONFIG_NO_DATA_LIST_GNSS);
856+
857+
if (gnss_str == NULL) {
858+
cJSON_Delete(nod_list);
859+
err = -ENOMEM;
860+
goto exit;
861+
}
862+
863+
json_add_obj_array(nod_list, gnss_str);
864+
}
865+
866+
if (data->no_data.neighbor_cell) {
867+
cJSON *ncell_str = cJSON_CreateString(CONFIG_NO_DATA_LIST_NEIGHBOR_CELL);
868+
869+
if (ncell_str == NULL) {
870+
cJSON_Delete(nod_list);
871+
err = -ENOMEM;
872+
goto exit;
873+
}
874+
875+
json_add_obj_array(nod_list, ncell_str);
876+
}
877+
878+
/* If there are no flag set in the no_data structure, an empty array is
879+
* encoded.
880+
*/
881+
values_added = true;
882+
json_add_obj(config_obj, CONFIG_NO_DATA_LIST, nod_list);
883+
}
884+
843885
if (!values_added) {
844886
err = -ENODATA;
845887
LOG_WRN("No valid configuration data values present");
@@ -863,6 +905,7 @@ void json_common_config_get(cJSON *parent, struct cloud_data_cfg *data)
863905
cJSON *move_res = cJSON_GetObjectItem(parent, CONFIG_MOVE_RES);
864906
cJSON *move_timeout = cJSON_GetObjectItem(parent, CONFIG_MOVE_TIMEOUT);
865907
cJSON *acc_thres = cJSON_GetObjectItem(parent, CONFIG_ACC_THRESHOLD);
908+
cJSON *nod_list = cJSON_GetObjectItem(parent, CONFIG_NO_DATA_LIST);
866909

867910
if (gps_timeout != NULL) {
868911
data->gps_timeout = gps_timeout->valueint;
@@ -887,6 +930,30 @@ void json_common_config_get(cJSON *parent, struct cloud_data_cfg *data)
887930
if (acc_thres != NULL) {
888931
data->accelerometer_threshold = acc_thres->valuedouble;
889932
}
933+
934+
if (nod_list != NULL && cJSON_IsArray(nod_list)) {
935+
cJSON *item;
936+
bool gnss_found = false;
937+
bool ncell_found = false;
938+
939+
for (int i = 0; i < cJSON_GetArraySize(nod_list); i++) {
940+
item = cJSON_GetArrayItem(nod_list, i);
941+
942+
if (strcmp(item->valuestring, CONFIG_NO_DATA_LIST_GNSS) == 0) {
943+
gnss_found = true;
944+
}
945+
946+
if (strcmp(item->valuestring, CONFIG_NO_DATA_LIST_NEIGHBOR_CELL) == 0) {
947+
ncell_found = true;
948+
}
949+
}
950+
951+
/* If a supported entry is present in the no data list we set the corresponding flag
952+
* to true. Signifying that no data is to be sampled for that data type.
953+
*/
954+
data->no_data.gnss = gnss_found;
955+
data->no_data.neighbor_cell = ncell_found;
956+
}
890957
}
891958

892959
int json_common_batch_data_add(cJSON *parent, enum json_common_buffer_type type, void *buf,

src/cloud/cloud_codec/json_protocol_names.h

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,15 @@
6464
#define DATA_NEIGHBOR_CELLS_NEIGHBOR_MEAS "nmr"
6565
#define DATA_NEIGHBOR_CELLS_PCI "cell"
6666

67-
#define CONFIG_DEVICE_MODE "activeMode"
68-
#define CONFIG_ACTIVE_TIMEOUT "activeWaitTime"
69-
#define CONFIG_MOVE_TIMEOUT "movementTimeout"
70-
#define CONFIG_MOVE_RES "movementResolution"
71-
#define CONFIG_GPS_TIMEOUT "gpsTimeout"
72-
#define CONFIG_ACC_THRESHOLD "movementThreshold"
67+
#define CONFIG_DEVICE_MODE "activeMode"
68+
#define CONFIG_ACTIVE_TIMEOUT "activeWaitTime"
69+
#define CONFIG_MOVE_TIMEOUT "movementTimeout"
70+
#define CONFIG_MOVE_RES "movementResolution"
71+
#define CONFIG_GPS_TIMEOUT "gpsTimeout"
72+
#define CONFIG_ACC_THRESHOLD "movementThreshold"
73+
#define CONFIG_NO_DATA_LIST "nod"
74+
#define CONFIG_NO_DATA_LIST_GNSS "gnss"
75+
#define CONFIG_NO_DATA_LIST_NEIGHBOR_CELL "ncell"
7376

7477
#define OBJECT_CONFIG "config"
7578
#define OBJECT_REPORTED "reported"
@@ -97,12 +100,15 @@
97100
#define MODEM_CELL_ID "cell"
98101
#define MODEM_IP_ADDRESS "ip"
99102

100-
#define CONFIG_DEVICE_MODE "act"
101-
#define CONFIG_ACTIVE_TIMEOUT "actwt"
102-
#define CONFIG_MOVE_TIMEOUT "mvt"
103-
#define CONFIG_MOVE_RES "mvres"
104-
#define CONFIG_GPS_TIMEOUT "gpst"
105-
#define CONFIG_ACC_THRESHOLD "acct"
103+
#define CONFIG_DEVICE_MODE "act"
104+
#define CONFIG_ACTIVE_TIMEOUT "actwt"
105+
#define CONFIG_MOVE_TIMEOUT "mvt"
106+
#define CONFIG_MOVE_RES "mvres"
107+
#define CONFIG_GPS_TIMEOUT "gpst"
108+
#define CONFIG_ACC_THRESHOLD "acct"
109+
#define CONFIG_NO_DATA_LIST "nod"
110+
#define CONFIG_NO_DATA_LIST_GNSS "gnss"
111+
#define CONFIG_NO_DATA_LIST_NEIGHBOR_CELL "ncell"
106112

107113
#define DATA_VALUE "v"
108114
#define DATA_TIMESTAMP "ts"

src/main.c

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -325,43 +325,47 @@ static void data_get(void)
325325
struct app_module_event *app_module_event = new_app_module_event();
326326
size_t count = 0;
327327

328+
/* Specify a timeout that each module has to fetch data. If data is not
329+
* fetched within this timeout, the data that is available is sent.
330+
*/
331+
app_module_event->timeout = 10;
332+
328333
/* Specify which data that is to be included in the transmission. */
329334
app_module_event->data_list[count++] = APP_DATA_MODEM_DYNAMIC;
330335
app_module_event->data_list[count++] = APP_DATA_BATTERY;
331336
app_module_event->data_list[count++] = APP_DATA_ENVIRONMENTAL;
332337

333-
if (IS_ENABLED(CONFIG_APP_REQUEST_NEIGHBOR_CELLS_DATA)) {
338+
if (IS_ENABLED(CONFIG_APP_REQUEST_NEIGHBOR_CELLS_DATA) && !app_cfg.no_data.neighbor_cell) {
334339
app_module_event->data_list[count++] = APP_DATA_NEIGHBOR_CELLS;
335340
}
336341

337-
/* Specify a timeout that each module has to fetch data. If data is not
338-
* fetched within this timeout, the data that is available is sent.
339-
*
340-
* The reason for having at least 65 seconds timeout is that the GNSS
341-
* module in nRF9160 will always search for at least 60 seconds for the
342+
/* The reason for having at least 75 seconds timeout in the case of requesting GNSS data
343+
* is that the GNSS module in nRF9160 will always search for at least 60 seconds for the
342344
* first position fix after a reboot.
343345
*
344-
* The addition of 5 seconds to the configured GPS timeout is done
346+
* The addition of 15 seconds to the configured GPS timeout is done
345347
* to let the GPS module run the currently ongoing search until
346348
* the end. If the timeout for sending data is exactly the same as for
347349
* the GPS search, a fix occurring at the same time as timeout is
348350
* triggered will be missed and not sent to cloud before the next
349351
* interval has passed in active mode, or until next movement in
350352
* passive mode.
351353
*/
352-
app_module_event->timeout = MAX(app_cfg.gps_timeout + 15, 75);
353354

354355
if (first) {
355-
if (IS_ENABLED(CONFIG_APP_REQUEST_GPS_ON_INITIAL_SAMPLING)) {
356+
if (IS_ENABLED(CONFIG_APP_REQUEST_GPS_ON_INITIAL_SAMPLING) &&
357+
!app_cfg.no_data.gnss) {
356358
app_module_event->data_list[count++] = APP_DATA_GNSS;
357-
} else {
358-
app_module_event->timeout = 10;
359+
app_module_event->timeout = MAX(app_cfg.gps_timeout + 15, 75);
359360
}
360361

361362
app_module_event->data_list[count++] = APP_DATA_MODEM_STATIC;
362363
first = false;
363364
} else {
364-
app_module_event->data_list[count++] = APP_DATA_GNSS;
365+
if (!app_cfg.no_data.gnss) {
366+
app_module_event->data_list[count++] = APP_DATA_GNSS;
367+
app_module_event->timeout = MAX(app_cfg.gps_timeout + 15, 75);
368+
}
365369
}
366370

367371
/* Set list count to number of data types passed in app_module_event. */

src/modules/Kconfig.app_module

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,12 @@ config APP_REQUEST_GPS_ON_INITIAL_SAMPLING
1212

1313
config APP_REQUEST_NEIGHBOR_CELLS_DATA
1414
bool "Request neighbor cells data"
15+
depends on AWS_IOT
16+
default y
1517
help
1618
Include LTE neighbor cell measurement data in regular sampling requests.
1719
The data will be encoded together with the other sampled data and sent to cloud,
1820
where it can be used to determine the device's location.
21+
Currently this option is only implemented when configuring for AWS IoT.
1922

2023
endmenu

src/modules/Kconfig.data_module

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,22 @@ config DATA_GPS_TIMEOUT_SECONDS
135135
help
136136
Timeout for acquiring a GPS fix during sampling of data.
137137

138+
config DATA_SAMPLE_GNSS_DEFAULT
139+
bool "Include GNSS in sample requests"
140+
default y
141+
help
142+
If this configuration is enabled the application will by default include GNSS data in
143+
sample requests sent to other modules. This configuration can be overwritten by changing
144+
the application's real-time configuration using the cloud-side state.
145+
146+
config DATA_SAMPLE_NEIGHBOR_CELLS_DEFAULT
147+
bool "Include neighbor cells in sample requests"
148+
default y
149+
help
150+
If this configuration is enabled the application will by default include neighbor cell
151+
data in sample requests sent to other modules. This configuration can be overwritten by
152+
changing the application's real-time configuration using the cloud-side state.
153+
138154
endif # DATA_MODULE
139155

140156
module = DATA_MODULE

0 commit comments

Comments
 (0)