Cellular: LTE Sensor Gateway
The LTE Sensor Gateway sample demonstrates how to transmit sensor data from an nRF9160 development kit to the nRF Cloud.
The sensor data is collected using Bluetooth® Low Energy. Therefore, this sample acts as a gateway between the Bluetooth LE and the LTE connections to nRF Cloud.
Requirements
The sample supports the following development kit:
Hardware platforms |
PCA |
Board name |
Board target |
---|---|---|---|
PCA10090 |
|
The sample also requires a Nordic Thingy:52.
When built for a board target with the */ns
variant, the sample is configured to compile and run as a non-secure application with Cortex-M Security Extensions enabled.
Therefore, it automatically includes Trusted Firmware-M that prepares the required peripherals and secure services to be available for the application.
Overview
The sample connects using Bluetooth LE to a Thingy:52 running the factory preloaded application. When the connection is established, it starts collecting data from two sensors:
The flip state of the Thingy:52
The GNSS position data of the nRF9160 DK
The sample aggregates the data from both sensors in memory.
You can then trigger an alarm that sends the aggregated data over LTE to nRF Cloud by flipping the Thingy:52, which causes a change in the flip state to UPSIDE_DOWN
.
This sample is also supported on the Thingy:91. However, it must be programmed using a debugger and a 10-pin SWD cable. Serial communication and firmware updates over serial using MCUboot are not supported in this configuration.
Configuration
See Configuring and building an application for information about how to permanently or temporarily change the configuration.
Additional configuration
Check and configure the following library option that is used by the sample:
CONFIG_MODEM_ANTENNA_GNSS_EXTERNAL
- Selects an external GNSS antenna.
Sending traces over UART on an nRF91 Series DK
To send modem traces over UART on an nRF91 Series DK, configuration must be added for the UART device in the devicetree and Kconfig. This is done by adding the modem trace UART snippet when building and programming.
Use the Cellular Monitor app for capturing and analyzing modem traces.
TF-M logging must use the same UART as the application. For more details, see shared TF-M logging.
User interface
When the connection is established, set switch 2 to N.C. to send GNSS data to nRF Cloud, if available.
On the nRF9160 DK, the LEDs display the following information regarding the application state:
- LED 3 and LED 4:
LED 3 blinking: The device is connecting to the LTE network.
LED 3 lit: The device is connected to the LTE network.
LED 4 blinking: The device is connecting to nRF Cloud.
LED 3 and LED 4 blinking: The MQTT connection has been established and the user association procedure with nRF Cloud has been initiated.
LED 4 lit: The device is connected and ready for sensor data transfer.
- All LEDs (1-4):
Blinking in groups of two (LED 1 and LED 3, LED 2 and LED 4): Modem fault.
Blinking in a cross pattern (LED 1 and LED 4, LED 2 and LED 3): Communication error with nRF Cloud.
Blinking in groups of two (LED 1 and LED 2, LED 3 and LED 4): Other error.
Building and running
This sample can be found under samples/cellular/lte_ble_gateway
in the nRF Connect SDK folder structure.
When built as firmware image for a board target with the */ns
variant, the sample has Cortex-M Security Extensions (CMSE) enabled and separates the firmware between Non-Secure Processing Environment (NSPE) and Secure Processing Environment (SPE).
Because of this, it automatically includes the Trusted Firmware-M (TF-M).
To read more about CMSE, see Processing environments.
To build the sample, follow the instructions in Configuring and building an application for your preferred building environment. See also Programming an application for programming steps and Testing and optimization for general information about testing and debugging in the nRF Connect SDK.
Note
When building repository applications in the SDK repositories, building with sysbuild is enabled by default.
If you work with out-of-tree freestanding applications, you need to manually pass the --sysbuild
parameter to every build command or configure west to always use it.
Programming the sample
When you connect the nRF9160 development kit to your computer, three virtual serial ports of the USB CDC class should become available:
The first port is connected to the main controller on the nRF9160 development kit, the nRF9160.
The second port is connected to the board controller on the nRF9160 development kit, the nRF52840.
You must program the board controller with the Bluetooth: HCI low power UART sample first, before programming the main controller with the LTE Sensor Gateway sample application. Program the board controller as follows:
Set the SW10 switch, marked as debug/prog, in the NRF52 position. On nRF9160 DK board version 0.9.0 and earlier versions, the switch was called SW5.
Build the Bluetooth: HCI low power UART sample for the
nrf9160dk/nrf52840
board target and program the board controller with it.Note
To build the sample successfully, you must specify the board version along with the board target. The board version is printed on the label of your DK, just below the PCA number. For example, for board version 1.1.0, the sample must be built in the following way:
west build --board nrf9160dk@1.1.0/nrf52840
Verify that the programming was successful. Use a terminal emulator, like nRF Connect Serial Terminal, to connect to the second serial port and check the output. See Testing and optimization for the required settings and steps.
After programming the board controller, you must program the main controller with the LTE Sensor Gateway sample. Program the main controller as follows:
Set the SW10 switch, marked as debug/prog, in the NRF91 position. On nRF9160 DK board version 0.9.0 and earlier versions, the switch was called SW5.
Build the LTE Sensor Gateway sample (this sample) for the
nrf9160dk/nrf9160/ns
board target and program the main controller with it.Note
To build the sample successfully, you must specify the board version along with the board target. For example, for board version 1.1.0, the sample must be built in the following way:
west build --board nrf9160dk@1.1.0/nrf9160/ns
Verify that the programming was successful. To do so, use a terminal emulator, like nRF Connect Serial Terminal, to connect to the first serial port and check the output. See Testing and optimization for the required settings and steps.
Testing
After programming the main controller with the sample, test it by performing the following steps:
Power on your Thingy:52 and observe that it starts blinking blue.
Open a web browser and navigate to https://nrfcloud.com/. Follow the instructions to set up your account and to add an LTE device. See Creating an nRF Cloud account for more information.
Power on or reset the DK.
Observe in the terminal window connected to the first serial port that the DK starts up. This is indicated by an output similar to the following line:
***** Booting Zephyr OS build v3.0.99-ncs1-9-g8ffc2ab25eaa *****
Observe that the message
LTE Sensor Gateway sample started
is shown in the terminal window, to ensure that the application has started.The nRF9160 DK now connects to the network. This might take several minutes.
Observe that LED 3 starts blinking as the connection to nRF Cloud is established.
The first time you start the sample the device will be paired to your account.
Observe that LED 4 is turned on to indicate that the connection to nRF Cloud is established.
In the nRF Cloud portal, select Device Management in the left pane and select Devices.
Observe that the device is shown as connected in the Devices screen.
Set Switch 2 in the position marked as N.C.. If a GNSS position fix is acquired, GNSS data is now added to the sensor data.
Make sure that the Thingy:52 has established a connection to the application. This is indicated by its led blinking green.
Select the device from your device list in the nRF Cloud portal.
Flip the Thingy:52, with the USB port pointing upward, to trigger the sending of the sensor data to nRF Cloud.
Observe that the sensor data is received from the DK to the nRF Cloud.
Dependencies
This sample uses the following nRF Connect SDK libraries:
It uses the following sdk-nrfxlib library:
It uses the following Zephyr library:
It also uses the following sample:
In addition, it uses the following secure firmware component: