Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[example] add minimum thread commissioner example #167

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,30 @@ jobs:
lcov --directory build/ --capture --output-file coverage.info
lcov --list coverage.info
bash <(curl -s https://codecov.io/bash) -f coverage.info
mini-commissioner:
runs-on: ubuntu-18.04
steps:
- uses: actions/checkout@v2
- name: Bootstrap
run: |
script/bootstrap.sh
- name: Build
run: |
cd example && mkdir build && cd build
cmake -GNinja \
-DCMAKE_CXX_STANDARD=11 \
-DCMAKE_CXX_STANDARD_REQUIRED=ON \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_INSTALL_PREFIX=/usr/local \
-DOT_COMM_REFERENCE_DEVICE=ON \
-DOT_COMM_CCM=OFF \
-DOT_COMM_WARNING_AS_ERROR=ON \
..
ninja
sudo ninja install
- name: Run mini-commissioner tests
run: |
cd tests/integration
./bootstrap.sh
./mini_commissioner/test_mini_commissioner.sh
32 changes: 32 additions & 0 deletions example/BUILDING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Build Minimum Thread Commissioner

## CMake Build

```shell
cd ~/ot-commissioner/example
mkdir -p build && cd build
cmake -GNinja -DBUILD_SHARED_LIBS=ON ..
ninja
```

A `mini_commissioner` binary will be generated in `build/`.

## Standalone build

Build and install the OT Commissioner library:

```c++
cd ~/ot-commissioner
mkdir -p build && cd build
cmake -GNinja -DBUILD_SHARED_LIBS=ON ..
sudo ninja install
```

Build the `mini_commissioner` app:

```c++
cd ~/ot-commissioner/example
clang++ -std=c++11 -Wall -g mini_commissioner.cpp -o mini-commissioner -lcommissioner -lcommissioner-common
```

The `mini-commissioner` binary will be generated in current directory.
50 changes: 50 additions & 0 deletions example/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#
# Copyright (c) 2021, The OpenThread Commissioner Authors.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. 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.
# 3. Neither the name of the copyright holder 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.
#

cmake_minimum_required(VERSION 3.10.1)
project(mini-commissioner VERSION 0.1.0)

# The commissioner library requires C++11 or higher.
set(CMAKE_CXX_STANDARD 11)

add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/..
${CMAKE_CURRENT_BINARY_DIR}/commissioner
EXCLUDE_FROM_ALL
)

add_executable(mini-commissioner mini_commissioner.cpp)

target_link_libraries(mini-commissioner
PRIVATE
commissioner
commissioner-common
)

install(TARGETS mini-commissioner
RUNTIME DESTINATION bin
)
83 changes: 83 additions & 0 deletions example/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# Minimum Thread Commissioner

This directory includes an example of building a minimum Thread Commissioner with the OT Commissioner library. The minimum Thread Commissioner petitions to given Border Router, enables MeshCoP for all joiners and commissions joiners.

## Build

See [BUILDING.md](./BUILDING.md) for building this mini Commissioner program. You can find details about the Border Router (`ot-daemon`) and simulation devices in this [codelab](https://openthread.io/codelabs/openthread-simulation-posix).

## Run the Commissioner

### Start the BR (ot-daemon)

See the [codelab](https://openthread.io/codelabs/openthread-simulation-posix).

### Start the Mini Commissioner

After a successful build, we should get a `mini-commissioner` binary which can be started with four arguments:

```shell
./mini-commissioner ::1 49191 00112233445566778899aabbccddeeff ABCDEF
```

You can get the usage by starting `mini-commissioner` with no arguments:

```shell
./minim_commissioner
usage:
mini-commissioner <br-addr> <br-port> <pskc-hex> <pskd>
```

> Note: the WiFi/ethernet interface address of the BR should be used but not the Thread interface address.

If everything go smooth, we will get outputs like below:

```shell
./mini-commissioner ::1 49191 ca117352886a861cce8a91021e65dd1c ABCDEF
===================================================
[Border Router address] : ::1
[Border Router port] : 49191
[PSKc] : ca117352886a861cce8a91021e65dd1c
[PSKd] : ABCDEF
===================================================

===================================================
type CRTL + C to quit!
===================================================

petitioning to [::1]:49191
the commissioner is active: true
enabling MeshCoP for all joiners
waiting for joiners
```

> Note: you are free to quit at any time with `CTRL+C`.

### Start the joiner

See the [codelab](https://openthread.io/codelabs/openthread-simulation-posix).

if everything go smooth, we will get output like below for two times of joining:

```shell
joiner "5ab1f2745b625c90" is requesting join the Thread network
joiner "5ab1f2745b625c90" is connected: OK
joiner "5ab1f2745b625c90" is commissioned
[Vendor Name] : OPENTHREAD
[Vendor Model] : NRF52840
[Vendor SW Version] : 20191113-01632-g
[Vendor Stack Version] : f4ce36000010
[Provisioning URL] :
[Vendor Data] :

joiner "5ab1f2745b625c90" is requesting join the Thread network
joiner "5ab1f2745b625c90" is connected: OK
joiner "5ab1f2745b625c90" is commissioned
[Vendor Name] : OPENTHREAD
[Vendor Model] : NRF52840
[Vendor SW Version] : 20191113-01632-g
[Vendor Stack Version] : f4ce36000010
[Provisioning URL] :
[Vendor Data] :

```
Loading