From c3d9b95f8c82de2629989878dae8143dd5fd535c Mon Sep 17 00:00:00 2001 From: GitHub Actions Date: Fri, 19 Feb 2021 00:10:32 +0000 Subject: [PATCH] fix: update from upstream See https://github.com/nrfconnect/sdk-nrf/tree/f81ece1993930a2f353b3d9b77eebf3533969e36/applications/asset_tracker_v2 --- README.rst | 34 +++++++++++++--------------------- prj.conf | 4 ++-- src/main.c | 9 ++++++++- src/modules/cloud_module.c | 12 +++++++++++- src/modules/data_module.c | 9 ++++++++- src/modules/gps_module.c | 12 +++++++++++- src/modules/modem_module.c | 12 ++++++------ src/modules/sensor_module.c | 12 +++++++++++- src/modules/ui_module.c | 14 ++++++-------- 9 files changed, 76 insertions(+), 42 deletions(-) diff --git a/README.rst b/README.rst index 5e0b5079..eebf5061 100644 --- a/README.rst +++ b/README.rst @@ -11,13 +11,13 @@ The Asset Tracker v2 is a real-time configurable ultra-low-power capable applica It is a complete rework of the :ref:`asset_tracker` application. This application introduces a set of new features, which are not present in the :ref:`asset_tracker` application: -* **Ultra-low power by design** - The application highlights the power saving features of the nRF9160 SiP, which is critical for successfully developing small form-factor devices and/or products which need very long battery lifetime. -* **Offline first** - Highly-mobile cellular IoT products need to handle unreliable connections gracefully by implementing mechanisms to retry the failed sending of data. -* **Timestamping on the device** - Sensor data is timestamped on the device using multiple time sources. When the device is offline (planned or unplanned), the timestamping does not rely on the cloud side. -* **Batching of data** - Data can be batched to reduce the number of messages transmitted, and to be able to retain collected data while the device is offline. -* **Configurable at run-time** - The application behavior (for example, accelerometer sensitivity, or GPS timeout) can be configured at run-time. This improves the development experience with individual devices or when debugging the device behavior in specific areas and situations. It also reduces the cost for transmitting data to the devices by reducing the frequency of sending firmware updates to the devices. +* *Ultra-low power by design* - The application highlights the power saving features of the nRF9160 SiP, which is critical for successfully developing small form-factor devices and/or products which need very long battery lifetime. +* *Offline first* - Highly-mobile cellular IoT products need to handle unreliable connections gracefully by implementing mechanisms to retry the failed sending of data. +* *Timestamping on the device* - Sensor data is timestamped on the device using multiple time sources. When the device is offline (planned or unplanned), the timestamping does not rely on the cloud side. +* *Batching of data* - Data can be batched to reduce the number of messages transmitted, and to be able to retain collected data while the device is offline. +* *Configurable at run-time* - The application behavior (for example, accelerometer sensitivity or GPS timeout) can be configured at run-time. This improves the development experience with individual devices or when debugging the device behavior in specific areas and situations. It also reduces the cost for transmitting data to the devices by reducing the frequency of sending firmware updates to the devices. -To implement the above features, a rework of the existing application was necessary. +Implementation of the above features required a rework of the existing application. Hence, this application is not backward compatible to the :ref:`asset_tracker` application. .. note:: @@ -256,17 +256,11 @@ You must check and configure the following :ref:`lib_aws_iot` library options th * :option:`CONFIG_AWS_IOT_BROKER_HOST_NAME` * :option:`CONFIG_AWS_IOT_SEC_TAG` -The application makes use of the heap when encoding and sending data to the cloud. -More information can be found in :ref:`memory_allocation` -For configuring the heap size, check and configure the following configuration option: +Additionally, you can add the following optional configurations to configure the heap or to provide additional information such as APN to the modem for registering with an LTE network: -* :option:`CONFIG_HEAP_MEM_POOL_SIZE` - -In some cases, you might need to provide additional information such as APN, to the modem for registering with an LTE network. -To manually configure the APN, set the following options: - -* :option:`CONFIG_LTE_PDP_CMD` - Set the option to ``y`` -* :option:`CONFIG_LTE_PDP_CONTEXT` - Set the option to ``0,\"IP\",\"apn.example.com\"`` +* :option:`CONFIG_HEAP_MEM_POOL_SIZE` - Configures the size of the heap that is used by the application when encoding and sending data to the cloud. More information can be found in :ref:`memory_allocation`. +* :option:`CONFIG_LTE_PDP_CMD` - Used for manual configuration of the APN. Set the option to ``y`` to enable PDP define using ``AT+CGDCONT``. +* :option:`CONFIG_LTE_PDP_CONTEXT` - Used for manual configuration of the APN. An example is ``0,\"IP\",\"apn.example.com\"``. Configuration files =================== @@ -293,6 +287,7 @@ Building and running ******************** Before building and running the firmware ensure that the cloud side is set up. +Also, the device must be provisioned and configured with the certificates according to the instructions for the respective cloud for the connection attempt to succeed. .. note:: @@ -323,9 +318,6 @@ If some options are defined in both files, the options set in the overlay take p Testing ======= -Before running the application, the cloud must be configured. -Also, the device must be provisioned and configured with certificates according to the instructions for the respective cloud for the connection attempt to succeed. - After programming the application and all the prerequisites to your development kit, test the application by performing the following steps: 1. |connect_kit| @@ -403,7 +395,7 @@ When an event is sent from a module, all subscribers receive that event in the r Modules may also receive events from other sources such as drivers and libraries. For instance, the cloud module will also receive events from the configured cloud backend. -The eventhandler converts the events to messages. +The event handler converts the events to messages. The messages are then queued in the case of the cloud module or processed directly in the case of modules that do not have a processing thread. .. figure:: /images/asset_tracker_v2_module_structure.svg @@ -457,7 +449,7 @@ Following is the basic structure for all the threads: switch (state) { case STATE_DISCONNECTED: - on_tate_disconnected(&msg); + on_state_disconnected(&msg); break; case STATE_CONNECTED: on_state_connected(&msg); diff --git a/prj.conf b/prj.conf index 7f8e3095..140d04fe 100644 --- a/prj.conf +++ b/prj.conf @@ -24,8 +24,8 @@ CONFIG_LOG_IMMEDIATE=y # DK - Used for buttons and LEDs in UI module. CONFIG_DK_LIBRARY_INVERT_LEDS=n -# BSD library -CONFIG_BSD_LIBRARY=y +# nRF modem library +CONFIG_NRF_MODEM_LIB=y # Network CONFIG_NETWORKING=y diff --git a/src/main.c b/src/main.c index c1b27a51..c9640472 100644 --- a/src/main.c +++ b/src/main.c @@ -50,7 +50,8 @@ struct app_msg_data { /* Application module super states. */ static enum state_type { STATE_INIT, - STATE_RUNNING + STATE_RUNNING, + STATE_SHUTDOWN } state; /* Application sub states. The application can be in either active or passive @@ -111,6 +112,8 @@ static char *state2str(enum state_type new_state) return "STATE_INIT"; case STATE_RUNNING: return "STATE_RUNNING"; + case STATE_SHUTDOWN: + return "STATE_SHUTDOWN"; default: return "Unknown"; } @@ -421,6 +424,7 @@ static void on_all_events(struct app_msg_data *msg) k_timer_stop(&movement_resolution_timer); SEND_EVENT(app, APP_EVT_SHUTDOWN_READY); + state_set(STATE_SHUTDOWN); } } @@ -474,6 +478,9 @@ void main(void) on_state_running(&msg); break; + case STATE_SHUTDOWN: + /* The shutdown state has no transition. */ + break; default: LOG_WRN("Unknown application state"); break; diff --git a/src/modules/cloud_module.c b/src/modules/cloud_module.c index 9fa89437..cfdbf270 100644 --- a/src/modules/cloud_module.c +++ b/src/modules/cloud_module.c @@ -44,7 +44,8 @@ struct cloud_msg_data { /* Cloud module super states. */ static enum state_type { STATE_LTE_DISCONNECTED, - STATE_LTE_CONNECTED + STATE_LTE_CONNECTED, + STATE_SHUTDOWN } state; /* Cloud module sub states. */ @@ -99,6 +100,8 @@ static char *state2str(enum state_type state) return "STATE_LTE_DISCONNECTED"; case STATE_LTE_CONNECTED: return "STATE_LTE_CONNECTED"; + case STATE_SHUTDOWN: + return "STATE_SHUTDOWN"; default: return "Unknown"; } @@ -560,7 +563,11 @@ static void on_sub_state_cloud_disconnected(struct cloud_msg_data *msg) static void on_all_states(struct cloud_msg_data *msg) { if (IS_EVENT(msg, util, UTIL_EVT_SHUTDOWN_REQUEST)) { + /* The module doesn't have anything to shut down and can + * report back immediately. + */ SEND_EVENT(cloud, CLOUD_EVT_SHUTDOWN_READY); + state_set(STATE_SHUTDOWN); } if (is_data_module_event(&msg->module.data.header)) { @@ -618,6 +625,9 @@ static void module_thread_fn(void) case STATE_LTE_DISCONNECTED: on_state_lte_disconnected(&msg); break; + case STATE_SHUTDOWN: + /* The shutdown state has no transition. */ + break; default: LOG_ERR("Unknown Cloud module state."); break; diff --git a/src/modules/data_module.c b/src/modules/data_module.c index 1d2f7ce6..49ae6231 100644 --- a/src/modules/data_module.c +++ b/src/modules/data_module.c @@ -58,7 +58,8 @@ struct data_msg_data { /* Data module super states. */ static enum state_type { STATE_CLOUD_DISCONNECTED, - STATE_CLOUD_CONNECTED + STATE_CLOUD_CONNECTED, + STATE_SHUTDOWN } state; /* Ringbuffers. All data received by the Data module are stored in ringbuffers. @@ -165,6 +166,8 @@ static char *state2str(enum state_type new_state) return "STATE_CLOUD_DISCONNECTED"; case STATE_CLOUD_CONNECTED: return "STATE_CLOUD_CONNECTED"; + case STATE_SHUTDOWN: + return "STATE_SHUTDOWN"; default: return "Unknown"; } @@ -856,6 +859,7 @@ static void on_all_states(struct data_msg_data *msg) * report back immediately. */ SEND_EVENT(data, DATA_EVT_SHUTDOWN_READY); + state_set(STATE_SHUTDOWN); } if (IS_EVENT(msg, app, APP_EVT_DATA_GET)) { @@ -1050,6 +1054,9 @@ static void module_thread_fn(void) case STATE_CLOUD_CONNECTED: on_cloud_state_connected(&msg); break; + case STATE_SHUTDOWN: + /* The shutdown state has no transition. */ + break; default: LOG_WRN("Unknown sub state."); break; diff --git a/src/modules/gps_module.c b/src/modules/gps_module.c index 00d29b15..39c51bf7 100644 --- a/src/modules/gps_module.c +++ b/src/modules/gps_module.c @@ -39,7 +39,8 @@ struct gps_msg_data { /* GPS module super states. */ static enum state_type { STATE_INIT, - STATE_RUNNING + STATE_RUNNING, + STATE_SHUTDOWN } state; /* GPS module sub states. */ @@ -78,6 +79,8 @@ static char *state2str(enum state_type new_state) return "STATE_INIT"; case STATE_RUNNING: return "STATE_RUNNING"; + case STATE_SHUTDOWN: + return "STATE_SHUTDOWN"; default: return "Unknown"; } @@ -378,7 +381,11 @@ static void on_all_states(struct gps_msg_data *msg) } if (IS_EVENT(msg, util, UTIL_EVT_SHUTDOWN_REQUEST)) { + /* The module doesn't have anything to shut down and can + * report back immediately. + */ SEND_EVENT(gps, GPS_EVT_SHUTDOWN_READY); + state_set(STATE_SHUTDOWN); } } @@ -403,6 +410,9 @@ static void message_handler(struct gps_msg_data *msg) on_state_running(msg); break; + case STATE_SHUTDOWN: + /* The shutdown state has no transition. */ + break; default: LOG_ERR("Unknown GPS module state."); break; diff --git a/src/modules/modem_module.c b/src/modules/modem_module.c index 766daa7b..14e395e2 100644 --- a/src/modules/modem_module.c +++ b/src/modules/modem_module.c @@ -41,7 +41,7 @@ static enum state_type { STATE_DISCONNECTED, STATE_CONNECTING, STATE_CONNECTED, - STATE_SHUTTING_DOWN, + STATE_SHUTDOWN, } state; /* Struct that holds data from the modem information module. */ @@ -78,8 +78,8 @@ static char *state2str(enum state_type state) return "STATE_CONNECTING"; case STATE_CONNECTED: return "STATE_CONNECTED"; - case STATE_SHUTTING_DOWN: - return "STATE_SHUTTING_DOWN"; + case STATE_SHUTDOWN: + return "STATE_SHUTDOWN"; default: return "Unknown state"; } @@ -608,7 +608,7 @@ static void on_all_states(struct modem_msg_data *msg) if (IS_EVENT(msg, util, UTIL_EVT_SHUTDOWN_REQUEST)) { lte_lc_power_off(); - state_set(STATE_SHUTTING_DOWN); + state_set(STATE_SHUTDOWN); SEND_EVENT(modem, MODEM_EVT_SHUTDOWN_READY); } } @@ -643,8 +643,8 @@ static void module_thread_fn(void) case STATE_CONNECTED: on_state_connected(&msg); break; - case STATE_SHUTTING_DOWN: - LOG_WRN("No action allowed in STATE_SHUTTING_DOWN"); + case STATE_SHUTDOWN: + /* The shutdown state has no transition. */ break; default: LOG_WRN("Invalid state: %d", state); diff --git a/src/modules/sensor_module.c b/src/modules/sensor_module.c index 91b32c70..31cd4b48 100644 --- a/src/modules/sensor_module.c +++ b/src/modules/sensor_module.c @@ -35,7 +35,8 @@ struct sensor_msg_data { /* Sensor module super states. */ static enum state_type { STATE_INIT, - STATE_RUNNING + STATE_RUNNING, + STATE_SHUTDOWN } state; /* Sensor module message queue. */ @@ -63,6 +64,8 @@ static char *state2str(enum state_type new_state) return "STATE_INIT"; case STATE_RUNNING: return "STATE_RUNNING"; + case STATE_SHUTDOWN: + return "STATE_SHUTDOWN"; default: return "Unknown"; } @@ -284,7 +287,11 @@ static void on_state_running(struct sensor_msg_data *msg) static void on_all_states(struct sensor_msg_data *msg) { if (IS_EVENT(msg, util, UTIL_EVT_SHUTDOWN_REQUEST)) { + /* The module doesn't have anything to shut down and can + * report back immediately. + */ SEND_EVENT(sensor, SENSOR_EVT_SHUTDOWN_READY); + state_set(STATE_SHUTDOWN); } } @@ -314,6 +321,9 @@ static void module_thread_fn(void) case STATE_RUNNING: on_state_running(&msg); break; + case STATE_SHUTDOWN: + /* The shutdown state has no transition. */ + break; default: LOG_WRN("Unknown sensor module state."); break; diff --git a/src/modules/ui_module.c b/src/modules/ui_module.c index 13af267e..e0a6519a 100644 --- a/src/modules/ui_module.c +++ b/src/modules/ui_module.c @@ -39,7 +39,7 @@ struct ui_msg_data { static enum state_type { STATE_ACTIVE, STATE_PASSIVE, - STATE_ERROR + STATE_SHUTDOWN } state; /* UI module sub states. */ @@ -91,8 +91,8 @@ static char *state2str(enum state_type new_state) return "STATE_ACTIVE"; case STATE_PASSIVE: return "STATE_PASSIVE"; - case STATE_ERROR: - return "STATE_ERROR"; + case STATE_SHUTDOWN: + return "STATE_SHUTDOWN"; default: return "Unknown"; } @@ -369,10 +369,8 @@ static void on_all_states(struct ui_msg_data *msg) if (IS_EVENT(msg, util, UTIL_EVT_SHUTDOWN_REQUEST)) { update_led_pattern(LED_ERROR_SYSTEM_FAULT); - - state_set(STATE_ERROR); - SEND_EVENT(ui, UI_EVT_SHUTDOWN_READY); + state_set(STATE_SHUTDOWN); } if (IS_EVENT(msg, modem, MODEM_EVT_LTE_CONNECTING)) { @@ -415,8 +413,8 @@ static void message_handler(struct ui_msg_data *msg) break; } break; - case STATE_ERROR: - /* The error state has no transition. */ + case STATE_SHUTDOWN: + /* The shutdown state has no transition. */ break; default: LOG_WRN("Unknown ui module state.");