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

Commit

Permalink
fix: update from upstream
Browse files Browse the repository at this point in the history
  • Loading branch information
GitHub Actions committed Feb 19, 2021
1 parent 42e0cd5 commit c3d9b95
Show file tree
Hide file tree
Showing 9 changed files with 76 additions and 42 deletions.
34 changes: 13 additions & 21 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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::
Expand Down Expand Up @@ -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
===================
Expand All @@ -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::

Expand Down Expand Up @@ -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|
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions prj.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 8 additions & 1 deletion src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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";
}
Expand Down Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -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;
Expand Down
12 changes: 11 additions & 1 deletion src/modules/cloud_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand Down Expand Up @@ -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";
}
Expand Down Expand Up @@ -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)) {
Expand Down Expand Up @@ -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;
Expand Down
9 changes: 8 additions & 1 deletion src/modules/data_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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";
}
Expand Down Expand Up @@ -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)) {
Expand Down Expand Up @@ -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;
Expand Down
12 changes: 11 additions & 1 deletion src/modules/gps_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand Down Expand Up @@ -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";
}
Expand Down Expand Up @@ -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);
}
}

Expand All @@ -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;
Expand Down
12 changes: 6 additions & 6 deletions src/modules/modem_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand Down Expand Up @@ -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";
}
Expand Down Expand Up @@ -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);
}
}
Expand Down Expand Up @@ -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);
Expand Down
12 changes: 11 additions & 1 deletion src/modules/sensor_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand Down Expand Up @@ -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";
}
Expand Down Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -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;
Expand Down
14 changes: 6 additions & 8 deletions src/modules/ui_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand Down Expand Up @@ -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";
}
Expand Down Expand Up @@ -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)) {
Expand Down Expand Up @@ -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.");
Expand Down

0 comments on commit c3d9b95

Please sign in to comment.