Skip to content

Commit

Permalink
Sensor Aggregation Use Case v1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
ubx-dich committed Dec 22, 2022
1 parent e47b540 commit f3000a5
Show file tree
Hide file tree
Showing 576 changed files with 98,914 additions and 233,054 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "ubxlib"]
path = ubxlib
url = https://github.com/u-blox/ubxlib.git
7 changes: 6 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ cmake_minimum_required(VERSION 3.20.0)
set(NRF_SUPPORTED_BOARDS nrf5340dk_nrf5340_cpuapp)

list(APPEND ZEPHYR_EXTRA_MODULES ${CMAKE_CURRENT_SOURCE_DIR}/ltr303)
list(APPEND ZEPHYR_EXTRA_MODULES ${CMAKE_CURRENT_SOURCE_DIR}/ubxlib_priv)
list(APPEND ZEPHYR_EXTRA_MODULES ${CMAKE_CURRENT_SOURCE_DIR}/icg20330)
list(APPEND ZEPHYR_EXTRA_MODULES ${CMAKE_CURRENT_SOURCE_DIR}/bq27520)
list(APPEND ZEPHYR_EXTRA_MODULES ${CMAKE_CURRENT_SOURCE_DIR}/ubxlib)
#list(APPEND ZEPHYR_EXTRA_MODULES $ENV{UBXLIB_BASE})


Expand All @@ -24,6 +26,7 @@ target_include_directories(app PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src/ublox_mod
target_include_directories(app PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src/ublox_modules/wifi)
target_include_directories(app PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src/ublox_modules/position)
target_include_directories(app PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src/ublox_modules/ble)
target_include_directories(app PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src/ublox_modules/ble/mobile_app_protocol)
target_include_directories(app PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src/ublox_modules/nfc)
target_include_directories(app PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src/sensors)
target_include_directories(app PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src/data_handle)
Expand All @@ -40,6 +43,7 @@ FILE(GLOB ublox_modules_cell_sources src/ublox_modules/cell/*.c)
FILE(GLOB ublox_modules_wifi_sources src/ublox_modules/wifi/*.c)
FILE(GLOB ublox_modules_position_sources src/ublox_modules/position/*.c)
FILE(GLOB ublox_modules_ble_sources src/ublox_modules/ble/*.c)
FILE(GLOB ublox_modules_mobile_app_protocol_sources src/ublox_modules/ble/mobile_app_protocol/*.c)
FILE(GLOB ublox_modules_nfc_sources src/ublox_modules/nfc/*.c)
FILE(GLOB data_handle_sources src/data_handle/*.c)
FILE(GLOB buttons_leds_sources src/buttons_leds/*.c)
Expand All @@ -54,6 +58,7 @@ target_sources(app PRIVATE ${ublox_modules_cell_sources})
target_sources(app PRIVATE ${ublox_modules_wifi_sources})
target_sources(app PRIVATE ${ublox_modules_position_sources})
target_sources(app PRIVATE ${ublox_modules_ble_sources})
target_sources(app PRIVATE ${ublox_modules_mobile_app_protocol_sources})
target_sources(app PRIVATE ${ublox_modules_nfc_sources})
target_sources(app PRIVATE ${data_handle_sources})
target_sources(app PRIVATE ${buttons_leds_sources})
Expand Down
70 changes: 45 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,25 +1,34 @@
# XPLR-IOT-1-software
This project is intented to be used with the XPLR-IOT-1 device from u-blox. Sensor Aggregation use case v0.3 is compatible with XPLR-IOT-1-00 (PCB Rev B version). More information about XPLR-IOT-1 hardware etc. can be found in the following link: [XPLR-IOT-1 quick start guide](https://developer.thingstream.io/guides/iot-communication-as-a-service/hardware/xplr-iot-1-quick-start-guide)
This project is intented to be used with the XPLR-IOT-1 device from u-blox. Sensor Aggregation use case v1.0 is compatible with XPLR-IOT-1-00 (PCB RevB and RevC version). More information about XPLR-IOT-1 hardware etc. can be found in the following link: [XPLR-IOT-1 quick start guide](https://developer.thingstream.io/guides/iot-communication-as-a-service/hardware/xplr-iot-1-quick-start-guide)

XPLR-IOT-1 comes pre-flashed with the Sensor Aggregation Firmware (v0.3) along with a Serial Bootloader that allows firmware on the device to be updated without the need of a debugger/programmer.
- XPLR-IOT-1 (PCB RevB version) comes pre-flashed with the Sensor Aggregation Firmware (v0.3) along with a Serial Bootloader that allows firmware on the device to be updated without the need of a debugger/programmer.

- XPLR-IOT-1 (PCB RevC and newer versions) comes pre-flashed with the Sensor Aggregation Firmware (v1.0) along with a Serial Bootloader that allows firmware on the device to be updated without the need of a debugger/programmer.

* **All PCB versions work with all firmware versions**.

This project contains the Sensor Aggregation Use Case example for XPLR-IOT-1 and future updates of this application will be uploaded here.

The main function of this use case is to collect information from sensors and send their data to the [Thingstream](https://portal.thingstream.io/?returnUrl=%2Fapp%2Fcommunication-services%2Fthings) platform using either [WiFi](./src/ublox_modules/wifi) or [Cellular](./src/ublox_modules/cell) Network connections.
The main function of this use case is to collect measurements from sensors and send their data to the [Thingstream](https://portal.thingstream.io/?returnUrl=%2Fapp%2Fcommunication-services%2Fthings) platform using either [Wi-Fi](./src/ublox_modules/wifi) or [Cellular](./src/ublox_modules/cell) Network connections.

The user can enable this functionality with the single press of a [button](./src/buttons_leds). However, if the user wants to experiment with the device and the firmware, [commands](./src/shell_cmd) are provided so that the user can configure the device, test its functionality, and customize its operation.

One of the major aspects of the firmware is that it uses [ubxlib](https://github.com/u-blox/ubxlib) library as much as possible to implement its functionality (see [here](./ubxlib_priv)).
#### ubxlib
One of the major aspects of the firmware is that it uses [ubxlib](https://github.com/u-blox/ubxlib) library as much as possible to implement its functionality. ubxlib is a u-blox library that makes it easy to use u-blox modules. ubxlib is used as a submodule in this repository, so make sure when this repo is cloned that ubxlib is also downloaded properly, e.g. by using commands such as:
`clone <repository_link> -recurse-submodules`
or after cloning something like:
`git submodule update --init`


**This project is considered to be used as an *example* and not as a final product code.**
**This project is considered to be used as an *example* and not as a final product code.** (e.g. it is not optimized for low power consumption and may have security vulnerabilities)



# Description
The main function of this use case is to collect information from sensors and send their data to the Thingstream platform using either [WiFi](./src/ublox_modules/wifi) or [Cellular](./src/ublox_modules/cell) Network connections.
The main function of this use case is to collect information from sensors and send their data to the Thingstream platform using either [Wi-Fi](./src/ublox_modules/wifi) or [Cellular](./src/ublox_modules/cell) Network connections.

The main features of the application are:
* 1. [Uart shell](./src/shell_cmd). The user can use a UART terminal to get log messages and send commands to the device
* 1. [UART shell](./src/shell_cmd). The user can use a UART terminal to get log messages and send commands to the device
* 2. Two main modes of operation:
* 2.1. [**Sensor Aggregation Main Functionality:**](./src) Samples all sensors with same update period (including position from MAXM10S module) and sends data in Thingstream platform in 2 ways (and one partly supported):
* 2.1.1. Using [**Wi-Fi**](./src/ublox_modules/wifi) networks and [**MQTT Now**](./src/ublox_modules/wifi) data plan in Thingstream
Expand All @@ -28,14 +37,14 @@ The main features of the application are:
* 2.2. [**Sensor Aggregation custom functionality:**](./src) The user can setup the device to enable/ disable various sensors, publish or not publish their data and have different sampling rate for each sensor.The options for sending data to Thingstream are the same as in Sensor Aggregation Main Functionality.
* 3. Simple [button](./src/buttons_leds) activation/deactivation of the Sensor Aggregation Main Functionality
* 4. [LED](./src/buttons_leds) indication of the Sensor Aggregation Main Functionality
* 5. Allow handling of [ublox modules](./src/ublox_modules) via s-center, m-center, u-center by configuring their UARTs properly. Power up/down u-blox modules.
* 5. Allow handling of [u-blox modules](./src/ublox_modules) via s-center, m-center, u-center by configuring their UARTs properly. Power up/down u-blox modules.
* 6. Control Log messages

The messages sent to Thingstream are compatible with pre-built flows which allow the use of user-hosted dashboard examples using Node Red.
The messages sent to Thingstream are compatible with pre-built flows which allow the use of user-hosted dashboard examples using Node-RED.

Secondary features of the application:
* XPLR-IOT-1 can be scanned by an NFC-enabled device (mobile phone/tablet). Details [here](./src/ublox_modules/nfc/).
* XPLR-IOT-1 imeplements BLE functionality for testing purposes. Details [here](./src/ublox_modules/ble/).
* XPLR-IOT-1 implements Bluetooth LE functionality for testing purposes. Details [here](./src/ublox_modules/ble/).


More information on the functionality is provided in Readmes at the respective [source code](./src) folders
Expand All @@ -53,19 +62,20 @@ The firmware is based on Nordic’s nRF Connect SDK in a Zephyr RTOS environment

The nRF Connect SDK version used in Sensor Aggregation firmware is 1.7.0 so this is the recommended version. Newer or older versions could produce errors during compilation.

The current version of Sensor Aggregation firmware relies on a customized version of ubxlib ( a u-blox library publicly available, which makes the handling of u-blox modules easier). That is why this customized ubxlib version is also included in the project in a folder called [ubxlib_priv](./ubxlib_priv). Code in this folder is not supposed to be changed
.
After installing **nRF Connect SDK** the path of the zephyr folder should be included in your system’s environmental variables as **ZEPHYR_BASE** (this is used by the project to build the firmware. If you use VS code to build the project you may not need to perform this step). Help instaliing nRF Connect can be found in Nordic's help pages like: [SDK installation](https://www.youtube.com/watch?v=2cv_jjqk5hg) and [Creating an application](https://www.youtube.com/watch?v=KwJtcPZHV30)
Sensor Aggregation firmware relies on [ubxlib](https://github.com/u-blox/ubxlib) to handle u-blox modules ( ubxlib is a u-blox library publicly available, which makes the handling of u-blox modules easier).
After installing **nRF Connect SDK** the path of the zephyr folder should be included in your system’s environmental variables as **ZEPHYR_BASE** (this is used by the project to build the firmware. If you use VS code to build the project you may not need to perform this step). Help on installing and basic use of nRF Connect can be found in Nordic's help pages like:
- [SDK installation](https://www.youtube.com/watch?v=2cv_jjqk5hg) and
- [Creating an application](https://www.youtube.com/watch?v=KwJtcPZHV30)

After setting this environmental variable to your system and if the nRF Connect SDK has been installed properly you should be able to build the firmware. You can do that by:
- **Recommended:** Using VS code and build as a normal project (see Nordic help pages like [this](https://www.youtube.com/watch?v=3yi6kuxgdPg))
- Using west commands in a command line (should install west properly to be able to use that):
-- Open a command line or powershell in the project’s folder (the one which contains the ubxlib_priv folder and CMakeLists.txt file) and type the following command:
If nRF Connect SDK has been installed properly you should be able to build the firmware. You can do that by:
* **Recommended:** Using VS code and build as a normal project (see Nordic help pages like [this](https://www.youtube.com/watch?v=3yi6kuxgdPg))
* Using west commands in a command line (should install west properly and set ZEPHYR_BASE environmental variable to be able to use that):
Open a command line or powershell in the project’s folder (the one which contains the ubxlib_priv folder and CMakeLists.txt file) and type the following command:
```
west build -p auto -b nrf5340dk_nrf5340_cpuapp --build-dir .\build .
```
There are three options to compile the project:
1. [Compile a simple image](./compile_options/simple_hex)
1. [Compile a simple image](./compile_options/simple_hex) (default)
1. [Complile an updetable image](./compile_options/updateable_image)
1. [Compile the application along with the bootloader](./compile_options/bootloader_inclusion)

Expand All @@ -79,6 +89,8 @@ XPLR-IOT-1 can be programmed using a J-Link debugger. There are various options

![vscode_flash should be here.](/readme_images/vscode_flash.png "VS Code Flash")

**Note:** This works if you build the firmware using the [simple_hex](./compile_options/simple_hex) or [bootloader_inclusion](./compile_options/bootloader_inclusion) options (by running the respective batch file before building). It does not work for updateable_image option -> in this case the firmware needs to be updated via the bootloader.

2. If you have [nrfjprog tools](https://www.nordicsemi.com/Products/Development-tools/nRF-Command-Line-Tools) installed, you can use commands in a command line to program the device (in case only App Core is used):
```
nrfjprog --eraseall
Expand All @@ -98,6 +110,8 @@ nrfjprog --reset

4. The device can be programmed using [Nordic’s nRF Connect for Desktop](https://www.nordicsemi.com/Products/Development-tools/nRF-Connect-for-desktop) and more specifically the *Programmer app*. The device should be reset after programming.

⚠ If you want to include the bootloader, you need to run the batch file in [bootloader_inclusion folder](./compile_options/bootloader_inclusion) before step one and then build and Flash the firmware.

![nrf connect programmer should be here.](/readme_images/nrfConnect_programmer.png "nrf connect programmer")

### Programming the firmware using the Serial Bootloader
Expand All @@ -107,7 +121,7 @@ To easily update the device using pre-compiled images, you can run the batch fil

##### If you don't want to run the batch script:

In order to update the device using the Serial Bootloader it must be compiled using option 2 [compile an updateable image](./compile_options/updateable_image) from compile options.
In order to update the device using the Serial Bootloader it must be compiled using option 2 [compile an updateable image](./compile_options/updateable_image) from compile options (that means: run the batch script inside that folder before building the project).

- In order to update the firmware:

Expand All @@ -116,21 +130,27 @@ In order to update the device using the Serial Bootloader it must be compiled us

-- Send the necessary command in a command terminal to update the device. UART should be free (not used by another serial terminal while the command is sent). The necessary command is given below.

The Serial Interface to be used is interface 0. Please find the correct COM port number for your setup (in this case COM8) and use it in the command that follows
The Serial Interface to be used is interface 0 (for RevB devices). Please find the correct COM port number for your setup (in this example COM8) and use it in the command that follows.

![usbhub.png should be here.](./readme_images/usbhub.png "usbhub.png")

For RevC and later devices, select the lowest COM port assignment for the FTDI USB-UART device. Please find the correct COM port number for your setup (in this example COM40) and use it in the command that follows.

![usbhubRevC.png should be here.](./readme_images/usbhubRevC.png "usbhubRevC.png")


In order to send the necessary commands for update you need newtmgr.exe (find it in the [tools_and_compiled_images](./tools_and_compiled_images/) folder):
```
newtmgr.exe --conntype serial --connstring "COM8,baud=115200" image upload signed_by_b0_app.bin
newtmgr.exe --conntype serial --connstring "COM8,baud=115200" image upload app_update.bin
```
Then reset the device or use the command:
```
nrfjprog --reset
```
**Side Note:** This application currently uses both the APPLICATION and NET core of NORA-B1 in XPLR-IOT-1. In this case, please program the NET core first, then the APPLICATION core using two separate commands as described above, and then reset the device. If only the application core is used (e.g. you do not use BLE) then the first command to update the net core is not needed.
Then reset the device using one of the following options:
- Use the device's reset button
- Use the `nrfjprog --reset` command, if you have nrftools installed and a J-Link programmer/debugger attached.
- Use the `newtmgr.exe --conntype serial --connstring "COM8,baud=115200" reset` command, right after the update commands (no debugger needed).


**Side Note:** This application currently uses both the APPLICATION and NET core of NORA-B1 in XPLR-IOT-1. In this case, program the NET core first, then the APPLICATION core using two separate commands as described above, and then reset the device. If only the application core is used (e.g. you do not use Bluetooth LE) then the first command to update the net core is not needed.
About the file names used in the commands above, see [here](./compile_options/updateable_image/). Off course the filenames can be anything.


Expand Down
19 changes: 18 additions & 1 deletion Release Notes.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,22 @@
v1.0 -- 22/12/2022
- Ubxlib v1.0.0 supported (ubxlib as submodule)
- Mobile application support (mobile com protocol v1.0)
- Connectionless MQTTSN QOS=3 is not supported (temporarily - need to update to ubxlib v1.1.0 for this)
- Both BQ27421 and BQ27520 Fuel Gauges are supported
- Replaced FXAS21002 sensor with ICG20330
- MaxM10 is not powered on, at startup
- Bluetooth LE Uses u-blox public device address, if this is saved in NORA-B1 OTP registers. Otherwise random device address is used.
- Added commands to enable/disable, disconnect Bluetooth LE. Status of Bluetooth LE is also typed with the "modules status" command
- Added commands to enable/disable NFC. Status of NFC is also typed with the "modules status" command
- ADXL345 sensor has been removed
- Affects dashboard: The JSON message key for battery measurement has been changed from "BQ27421" to "BATTERY"
- fixed a bug in reset nina wifi credentials
- fixed a bug in wifi nina network validity for open networks
- minor changes (mostly debug messages)


v0.3 -- 20/07/2022
- Added BLE basic functionality for Testing with NUS service.
- Added Bluetooth LE basic functionality for Testing with NUS service.
- Added NFC basic functionality for testing.
- Added Serial Com Selection command for NINA-W156 module
- Bug Fix: SARA-R5 remains always on. Proper Handling of SARA pins
Expand Down
6 changes: 6 additions & 0 deletions bq27520/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# BQ27520 Battery Gauge Driver
This folder contains a BQ27520 Battery Gauge basic driver, as a Zephyr module that can be used by the main application.

### Known Issues
Trying to use the `BQ27520_DESIGN_CAPACITY` and `BQ27520_TERMINATE_VOLTAGE` configuration options via the *prj.conf* in your application may trigger compilation errors.
Nevertheless, the battery gauge is set up to work properly with the battery used in XPLR-IOT-1 devices and these configuration options do not need to be altered in the *prj.conf* file for use with an XPLR-IOT-1 device.
10 changes: 10 additions & 0 deletions bq27520/zephyr/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# SPDX-License-Identifier: Apache-2.0

if(CONFIG_BQ27520)
zephyr_include_directories(.)

zephyr_library()

zephyr_library_sources_ifdef(CONFIG_BQ27520 bq27520.c)

endif()
34 changes: 34 additions & 0 deletions bq27520/zephyr/Kconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Copyright (c) 2020 Linumiz
#
# SPDX-License-Identifier: Apache-2.0

config BQ27520
bool "BQ27520 Fuel Gauge"
depends on I2C
help
Enable I2C-based driver for BQ27520 Fuel Gauge.

if BQ27520

config BQ27520_LAZY_CONFIGURE
bool "Configure on first usage instead of init"
default false
help
Configuring the sensor can take a long time, which
we can delay till the first sample request and keep
the boot time as short as possible.

config BQ27520_DESIGN_CAPACITY
int "Battery Design Capacity"
default 1000
help
Battery Design Capacity

config BQ27520_TERMINATE_VOLTAGE
int "Battery Terminate Voltage (V)"
default 3000
help
Battery Terminate Voltage (V)


endif # BQ27520
Loading

0 comments on commit f3000a5

Please sign in to comment.