diff --git a/config/nrfconnect/nrfconnect-app.cmake b/config/nrfconnect/nrfconnect-app.cmake index d8500dd83d03e9..9c8534f1e28085 100644 --- a/config/nrfconnect/nrfconnect-app.cmake +++ b/config/nrfconnect/nrfconnect-app.cmake @@ -76,6 +76,7 @@ chip_configure(ChipConfig ARCH arm-none-eabi CFLAGS ${CHIP_COMMON_FLAGS} --specs=nosys.specs CXXFLAGS ${CHIP_COMMON_FLAGS} + PROJECT_CONFIG ${CMAKE_CURRENT_SOURCE_DIR}/main/include/CHIPProjectConfig.h ) chip_build(ChipLib ChipConfig diff --git a/examples/lock-app/nrfconnect/README.md b/examples/lock-app/nrfconnect/README.md index 17fc318b88acf1..c364edc7d40b5e 100644 --- a/examples/lock-app/nrfconnect/README.md +++ b/examples/lock-app/nrfconnect/README.md @@ -82,7 +82,10 @@ position to another. used to mimick a user manually operating the lock. The button behaves as a toggle, swapping the state every time it is pressed. -The remaining two LEDs and buttons (#3 and #4) are unused. +**Button #3** can be used to trigger a thread joiner. It should be use to +commission to the thread network. Credentials will be presented in log messages. + +The remaining two LEDs (#3 and #4) and button #4 are unused. diff --git a/examples/lock-app/nrfconnect/main/AppTask.cpp b/examples/lock-app/nrfconnect/main/AppTask.cpp index 8e89bc2ecae958..fa8526a087166a 100644 --- a/examples/lock-app/nrfconnect/main/AppTask.cpp +++ b/examples/lock-app/nrfconnect/main/AppTask.cpp @@ -209,6 +209,14 @@ void AppTask::ButtonEventHandler(uint32_t button_state, uint32_t has_changed) button_event.Handler = FunctionHandler; sAppTask.PostEvent(&button_event); } + + if (JOINER_BUTTON_MASK & button_state & has_changed) + { + button_event.ButtonEvent.PinNo = JOINER_BUTTON; + button_event.ButtonEvent.Action = BUTTON_PUSH_EVENT; + button_event.Handler = JoinerHandler; + sAppTask.PostEvent(&button_event); + } } void AppTask::TimerEventHandler(k_timer * timer) @@ -299,6 +307,20 @@ void AppTask::FunctionHandler(AppEvent * aEvent) } } +void AppTask::JoinerHandler(AppEvent * aEvent) +{ + if (aEvent->ButtonEvent.PinNo != JOINER_BUTTON) + return; + + CHIP_ERROR error = CHIP_ERROR_NOT_IMPLEMENTED; + +#if CHIP_DEVICE_CONFIG_ENABLE_THREAD + error = ThreadStackMgr().JoinerStart(); +#endif + + LOG_INF("Thread joiner triggering result: %s", chip::ErrorStr(error)); +} + void AppTask::CancelTimer() { k_timer_stop(&sFunctionTimer); diff --git a/examples/lock-app/nrfconnect/main/include/AppTask.h b/examples/lock-app/nrfconnect/main/include/AppTask.h index a5a8c9b15103fe..84d5272ce08d34 100644 --- a/examples/lock-app/nrfconnect/main/include/AppTask.h +++ b/examples/lock-app/nrfconnect/main/include/AppTask.h @@ -47,6 +47,7 @@ class AppTask static void FunctionTimerEventHandler(AppEvent * aEvent); static void FunctionHandler(AppEvent * aEvent); + static void JoinerHandler(AppEvent * aEvent); static void LockActionEventHandler(AppEvent * aEvent); static void ButtonEventHandler(uint32_t buttons_state, uint32_t has_changed); diff --git a/examples/lock-app/nrfconnect/main/include/CHIPProjectConfig.h b/examples/lock-app/nrfconnect/main/include/CHIPProjectConfig.h new file mode 100644 index 00000000000000..082fe0d5532ddd --- /dev/null +++ b/examples/lock-app/nrfconnect/main/include/CHIPProjectConfig.h @@ -0,0 +1,35 @@ +/* + * + * Copyright (c) 2020 Project CHIP Authors + * All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @file + * Example project configuration file for CHIP. + * + * This is a place to put application or project-specific overrides + * to the default configuration values for general CHIP features. + * + */ + +#ifndef CHIP_PROJECT_CONFIG_H +#define CHIP_PROJECT_CONFIG_H + +// Use a default pairing code if one hasn't been provisioned in flash. +#define CHIP_DEVICE_CONFIG_USE_TEST_SETUP_PIN_CODE 12345678 +#define CHIP_DEVICE_CONFIG_USE_TEST_SETUP_DISCRIMINATOR 0xF00 + +#endif // CHIP_PROJECT_CONFIG_H diff --git a/examples/lock-app/nrfconnect/main/include/app_config.h b/examples/lock-app/nrfconnect/main/include/app_config.h index 9558fbd7503253..2018eb7cabb1f9 100644 --- a/examples/lock-app/nrfconnect/main/include/app_config.h +++ b/examples/lock-app/nrfconnect/main/include/app_config.h @@ -25,6 +25,8 @@ #define LOCK_BUTTON_MASK DK_BTN2_MSK #define FUNCTION_BUTTON DK_BTN1 #define FUNCTION_BUTTON_MASK DK_BTN1_MSK +#define JOINER_BUTTON DK_BTN3 +#define JOINER_BUTTON_MASK DK_BTN3_MSK #define SYSTEM_STATE_LED DK_LED1 #define LOCK_STATE_LED DK_LED2 diff --git a/examples/lock-app/nrfconnect/prj.conf b/examples/lock-app/nrfconnect/prj.conf index 4b6239c7a49ecd..33639abaf1d518 100644 --- a/examples/lock-app/nrfconnect/prj.conf +++ b/examples/lock-app/nrfconnect/prj.conf @@ -114,6 +114,8 @@ CONFIG_OPENTHREAD_BORDER_AGENT=y CONFIG_OPENTHREAD_BORDER_ROUTER=y CONFIG_OPENTHREAD_UDP_FORWARD=y CONFIG_OPENTHREAD_ENABLE_SERVICE=y +CONFIG_OPENTHREAD_JOINER=y +CONFIG_OPENTHREAD_MANUAL_START=y # Enable OpenThread shell CONFIG_OPENTHREAD_SHELL=y