Skip to content

Commit

Permalink
Merge pull request #208 from NordicSemiconductor/readme
Browse files Browse the repository at this point in the history
Readme updated
  • Loading branch information
philips77 authored Jan 15, 2024
2 parents 90d8da2 + 288fd26 commit 89aff64
Show file tree
Hide file tree
Showing 4 changed files with 222 additions and 38 deletions.
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.gradle
/local.properties
/.idea
*.iml
.DS_Store
/build
/key*
34 changes: 19 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
# nRF Connect

(previosly named nRF Master Control Panel)
The nRF Connect for Mobile is an application designed for Bluetooth Low Energy developers. It allows for scanning for BLE devices and communicating with them.

## Application
The nRF Connect for Android application requires Android version 4.3 or later and is available on Google Play or [releases](https://github.com/NordicSemiconductor/Android-nRF-Connect/releases), in case Google Play is not available. We recommend to install the application using Google Play as it will get automatic updates.

The nRF Connect is an application designed for Bluetooth Low Energy developers. It allows for scanning for BLE devices and communicating with them.
<a href='https://play.google.com/store/apps/details?id=no.nordicsemi.android.mcp'><img alt='Get it on Google Play' height='80' src='https://play.google.com/intl/en_us/badges/static/images/badges/en_badge_web_generic.png'/></a>

The nRF Connect for Android application requires Android version 4.3 or later and is available on Google Play:

https://play.google.com/store/apps/details?id=no.nordicsemi.android.mcp

or [here](https://github.com/NordicSemiconductor/Android-nRF-Connect/releases), in case Google Play is not available. We recommend to install the application using Google Play as it will get automatic updates.

**Note: The source code of nRF Connect is not available.**
> [!IMPORTANT]
> The **source code** of nRF Connect is not available. This repo proveds only documentation and Issue tracker.
## Features

Expand All @@ -34,8 +29,13 @@ or [here](https://github.com/NordicSemiconductor/Android-nRF-Connect/releases),

## DFU - Device Firmware Update

The Device Firmware Update BLE protocol may be used to update the Soft Device, Bootloader or application Over-the-Air on nRF5 device.
The full DFU documentation may be found on http://infocenter.nordicsemi.com/.
nRF Connect supports the following DFU proptocols:

Name | SDK | Supported Devices | Documentation
-----|-----|---------|--------------
Legacy DFU | nRF5 SDK | nRF51, nRF52 | [Link](https://infocenter.nordicsemi.com/topic/com.nordic.infocenter.sdk5.v11.0.0/examples_ble_dfu.html?cp=9_5_13_4_3_1)
Secure DFU | nRF5 SDK | nRF52 | [Link](https://infocenter.nordicsemi.com/topic/sdk_nrf5_v17.1.0/lib_bootloader_modules.html?cp=9_1_3_5)
McuManager | nRF Connect SDK, Zephyr, Mynewt | nRF52, nRF53, nRF54, ... | [Link](https://docs.nordicsemi.com/bundle/ncs-latest/page/nrf/config_and_build/dfu/index.html)

## Automated testing

Expand All @@ -45,9 +45,13 @@ Copy those files and the *test.bat* script to your PC and run. Currently only Wi
be called from Mac and Linux as well.

To start the test run the *test.bat* script:

test.bat [-d device_id] [-E KEY EXTRA]* test.xml

```batch
test.bat [-d device_id] [-E KEY EXTRA] test.xml
```
or **test.sh** script:
```sh
./test.sh [-d device_id] [-E KEY EXTRA] test.xml
```
You may specify key-value pairs in execution or inside the test using

<set name="KEY" value="VALUE" />
Expand Down
46 changes: 23 additions & 23 deletions documentation/Automated tests/README.md
Original file line number Diff line number Diff line change
@@ -1,43 +1,43 @@
# Automated tests

Automated tests allow you to configure and run set of tests foor your Bluetooth Smart device using an Android 4.3+ phone. Feel free to submit comments, bugs or feature ideas.
Automated tests allow you to configure and run set of tests foor your Bluetooth Low Energy device using an Android 4.3+ phone. Feel free to submit comments, bugs or feature ideas.

## Resources

1. [test.bat](test.bat) - the Windows script that may be used to run the test on the Android device.
1. Starting script that may be used to run the test on the Android device.
a. [test.bat](test.bat) - for Windows
b. [test.sh](test.sh) - for Unix/Mac
2. [sample_test_hrm.xml](sample_test_hrm.xml) - one of the sample tests. It covers almost all features of the automated tests, except those added in nRF Connect 4.3 or later. It can be run on the HRS_DFU sample application from the SDK. You may modify it to match your application.
3. [sample_test_scanning.xml](sample_test_scanning.xml) - the second sample test. Covers new scanning feature in automated tests added in nRF Connect v. 4.3.

## How to begin

The automated tests should work with any Bluetooth Smart device that communicates over the GATT protocol. A test XML can be created to test that the services, characteristics and descriptors have the correct values and behaviour. A Device Firmware Update (DFU) also may be performed.
The automated tests should work with any Bluetooth LE device that communicates over the GATT protocol. A test XML can be created to test that the services, characteristics and descriptors have the correct values and behaviour. A Device Firmware Update (DFU) also may be performed.

To make an easy start the *sample_test_hrm.xml* file contains a test that can be used with the HRS_DFU sample from the SDK. The instruction below describes steps that should be performed to successfully run this test.

*Note:* Starting from the SDK 8.0, the DFU bootloader, in case the buttonless update is NOT being used, advertises with a device address increased by 1. Therefore, the test may fail in the first run if you have just the Soft Device and Bootloader flashed on the device. After flashing the HRS application onto it, it will start to advertise with a different address and a timeout will be thrown during connection attempt. But the test should work for the second time as the bootloader uses the same address if buttonless update is in use.

1. nRF Connect (nRF Master Control Panel v2.1 or newer) will create the above files in your phone's file system in */Nordic Semiconductor* folder. *Note:* Newly created files may not be visible on the PC when connected with USB. This is beacuse Android must perform a scan of media files. Get the files from GitHub or trigger the media scanner manually: restart the phone/tablet or install and launch the *Rescan SD* application (or similar) from Google Play.
2. Copy the above mentioned files to your PC. You will use the *test.bat* to start the testing service. The sample may be used as a demo or a starting point.
3. Prepare the nRF51 DK for the test flash with the Soft Device and the DFU bootloader. *Note:* This change is not required for newer versions of the DFU bootloader.
1. Flash the Soft Device s110 version 8.0 or newer (for example using nRF Go Studio).
2. Flash the DFU Bootloader from SDK 9.0 or newer (both SD and Bootloader are available on http://developer.nordicsemi.com website).
- If you want to use the buttonless update in DFU bootloader from SDK 7.1, modify the *dfu_transport_ble.c* file in your bootloader source (you may have to unlock the file in Explorer first as it's READ ONLY by default).
- Increase the **APP_DIRECTED_ADV_TIMEOUT** value to 50 (it's 5 by default) in line 62: `#define APP_DIRECTED_ADV_TIMEOUT 50`
- Compile the modified Bootloader and flash the new HEX.
- This change is required for Android to reconnect to the bootloader after switching the device to bootloader mode. By default, the bootloader advertises for 6 seconds (5 * 1.28s) which is shorter than the disconnection timeout on Android. Android, after sending the *jump* command, waits for the disconnection event for about 22 seconds, depending on the device model. Value 50 (1 minute) should be more than enough.
4. Connect your Android device to the PC, enable USB debugging on it and install required drivers and ADB (Android Debug Bridge) on the PC. Add the ABD to the PATH global variable or copy it (and dlls) to the same folder.
5. Try the ADB by writing `adb devices` command in the command line. A list of connected Android devices should be shown.
6. Find out the address of your device. You may use the nRF Connect to do that. Your device should advertise as a DFU Targ. Make sure you are not connected with the bootloader.
7. *Optional:* Install the [nRF Logger](https://play.google.com/store/apps/details?id=no.nordicsemi.android.log) application to get more information about the test progress and syntax errors.
8. Start the sample test with the following command. Use your device address, f.e. AA:BB:CC:DD:EE:FF instead of address*. The -d option is required only when more than one Android device is connected and configured for USB debugging.

`test.bat [-d your_android_device_id] -E EXTRA_ADDRESS address* sample_test_hrm.xml`
> [!NOTE]
> Starting from the SDK 8.0, the DFU bootloader, in case the buttonless update is NOT being used, advertises with a device address increased by 1. Therefore, the test may fail in the first run if you have just the Soft Device and Bootloader flashed on the device. After flashing the HRS application onto it, it will start to advertise with a different address and a timeout will be thrown during connection attempt. But the test should work for the second time as the bootloader uses the same address if buttonless update is in use.
1. Copy the files to your PC. You will use the *test.bat/sh* to start the testing service. The sample may be used as a demo or a starting point.
2. Prepare the device for the test flash with initial firmware.
3. Connect your Android device to the PC, enable USB debugging on it and install required drivers and ADB (Android Debug Bridge) on the PC. Add the ABD to the PATH global variable.
4. Try the ADB by writing `adb devices` command in the command line. A list of connected Android devices should be shown.
5. Find out the address of your device. You may use the nRF Connect to do that. Your device should advertise as a DFU Targ. Make sure you are not connected with the bootloader.
6. *Optional:* Install the [nRF Logger](https://play.google.com/store/apps/details?id=no.nordicsemi.android.log) application to get more information about the test progress and syntax errors.
7. Start the sample test with the following command. Use your device address, f.e. AA:BB:CC:DD:EE:FF instead of address*. The -d option is required only when more than one Android device is connected and configured for USB debugging.

```batch
test.bat [-d your_android_device_id] -E EXTRA_ADDRESS address* sample_test_hrm.xml
```
or
```sh
./test.sh [-d your_android_device_id] -E EXTRA_ADDRESS address* sample_test_hrm.xml
```

9. A *Test in progress...* notification will be shown. If you had the nRF Logger installed click the notification to display the test progress.
10. When test is completed the *sample_test_hrm_result.txt* file will be created in the script location. The result of the sample HRM test is [here](sample_test_hrm_result.txt).

To test the HRM sample test on nRF52 device you have to modify the XML script and either remove the run-test with the id *dfu*, or modify the FIRMWARE_PATH constant to ```/Nordic Semiconductor/Board/pca10040/ble_app_hrm_dfu_s132_v2_0_0_sdk_11_0.zip``` and make sure the Soft Device 2.0.0 and HRM_DFU app is flashed.

**Scanning sample test** - the second test does not require providing the device address. The test service will perform a BLE scan and find a device that advertises with HRM service UUID, connect and do some basic operations just to prove it works.

## Documentation
Expand Down
173 changes: 173 additions & 0 deletions documentation/Automated tests/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
#!/bin/bash
# Copyright (c) 2024, Nordic Semiconductor
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
# * Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
# * Neither the name of nRF Toolbox nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
# Description:
# ------------
# The script allows to run automated tests using Android phone.
# The script may be run on Unix / Mac / Linux.
#
# Requirements:
# -------------
# 1. Android device with Android version 4.3+ connected by USB cable with the PC
# 2. The path to Android platform-tools directory must be added to %PATH% environment variable
# 3. nRF Connect (2.1.0+) application installed on the Android device
# 4. "Developer options" and "USB debugging" must be enabled on the Android device
#
# Usage:
# ------
# 1. Open console
# 2. Type "./test.sh --help" and press ENTER
#
# Android Debug Bridge (adb):
# ---------------------------
# You must have Android platform tools installed on the computer.
# Go to http://developer.android.com/sdk/index.html for more information how to install it on the computer.
# You do not need the whole ADT Bundle (with Eclipse or Android Studio). Only SDK Tools with Platform Tools are required.

# Set variables
PROGRAM="$0"
DEVICE=""
S_DEVICE=""
EXTRAS=""

# Check ADB
if ! command -v adb > /dev/null 2>&1; then
echo "Error: adb is not recognized as an external command."
echo " Add [Android Bundle path]/sdk/platform-tools to \$PATH"
exit 1
fi

# Check help
if [ -z "$1" ] || [ "$1" = "--help" ]; then
echo "Usage: $PROGRAM [-D device_id] [-E key value] script.xml"
echo "Info:"
echo "device_id - Call: \"adb devices\" to get a list of serial numbers"
echo "key value - You may pass 0+ parameters to the Test Service, e.g.,"
echo " -E EXTRA_ADDRESS \"AA:BB:CC:DD:EE:FF\" -E SOMETHING \"important\""
echo " and use them in the script.xml file as e.g.:"
echo " ..address=\"\${EXTRA_ADDRESS}\"..."
exit 1
fi

# Read target device id
if [ "$1" = "-d" ]; then
TARGET_DEVICE_SET=1
shift
DEVICE="$1"
S_DEVICE="-s $1"
shift
fi

# Read optional extra parameters
while [ "$1" = "-e" ]; do
EXTRAS_SET=1
shift
EXTRAS="$EXTRAS -e $1 \"$2\""
shift 2
done

# Write intro
echo "================================================="
echo "Nordic Semiconductor Automated Tests shell script"
echo "================================================="

# Read file name and fully qualified path name to the XML file
if [ -z "$1" ]; then
echo "Error: Test script file name not specified."
exit 1
fi

XML_FILE=$(basename "$1")
RESULT_FILE="${1%.*}_result.txt"
XML_PATH=$(realpath "$1")

if [ ! -e "$XML_PATH" ]; then
echo "Error: The given test script file has not been found."
exit 1
fi

# Check if there is only one device connected
if [ -z "$DEVICE" ]; then
DEVICE_COUNT=$(adb devices | grep -v "devices" | grep -c "device\|unauthorized\|emulator")
echo $DEVICE_COUNT
if [ "$DEVICE_COUNT" -eq 0 ]; then
echo "Error: No device connected."
exit 1
elif [ "$DEVICE_COUNT" -gt 1 ]; then
echo "Error: More than one device connected."
echo " Specify the device serial number using -D option:"
adb devices
exit 1
fi
else
# Check if specified device is connected
if ! adb devices | grep -q "$DEVICE"; then
echo "Error: Device with serial number \"$DEVICE\" is not connected."
adb devices
exit 1
fi
fi

# Remove old result file (if exists)
echo -n "Removing old result file..."
adb $S_DEVICE shell rm "/sdcard/Android/data/no.nordicsemi.android.mcp/files/Test/$RESULT_FILE" > /dev/null 2>&1
echo "OK"

# Copy selected file onto the device
echo -n "Copying \"$XML_FILE\" to /sdcard/Android/data/no.nordicsemi.android.mcp/files/Test..."
adb $S_DEVICE push "$XML_PATH" "/sdcard/Android/data/no.nordicsemi.android.mcp/files/Test/$XML_FILE" > /dev/null 2>&1
if [ $? -ne 0 ]; then
echo "FAIL"
echo "Error: Device not found."
exit 1
else
echo "OK"
fi

# Start test service on the device
echo -n "Starting test service..."
adb $S_DEVICE shell am start-foreground-service -a no.nordicsemi.android.action.START_TEST $EXTRAS -e no.nordicsemi.android.test.extra.EXTRA_FILE_PATH "/sdcard/Android/data/no.nordicsemi.android.mcp/files/Test/$XML_FILE" > /dev/null 2>&1
if [ $? -ne 0 ]; then
echo "FAIL"
echo "Error: Required application not installed."
exit 1
else
echo "OK"
echo "Test started...OK"
fi

# Try to obtain the result. Wait 10 seconds before every try.
echo -n "Waiting for the result..."
while true; do
# Wait 10 sec, this IP address is reserved and does not exist
sleep 10
adb $S_DEVICE pull "/sdcard/Android/data/no.nordicsemi.android.mcp/files/Test/$RESULT_FILE" "$RESULT_FILE" > /dev/null 2>&1
if [ $? -eq 0 ]; then
break
fi
done
echo "OK"
echo "Result saved in \"$RESULT_FILE\"."
exit 0

0 comments on commit 89aff64

Please sign in to comment.