8000 [nRF Connect] Print PIN and QR Code on door-lock startup by Damian-Nordic · Pull Request #2335 · project-chip/connectedhomeip · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

[nRF Connect] Print PIN and QR Code on door-lock startup #2335

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

Merged
merged 3 commits into from
Aug 29, 2020
Merged
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
1 change: 1 addition & 0 deletions config/nrfconnect/nrfconnect-app.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ set(CHIP_OUTPUT_LIBRARIES
${CHIP_OUTPUT_DIR}/lib/libBleLayer.a
${CHIP_OUTPUT_DIR}/lib/libDeviceLayer.a
${CHIP_OUTPUT_DIR}/lib/libCHIPDataModel.a
${CHIP_OUTPUT_DIR}/lib/libSetupPayload.a
)

# ==================================================
Expand Down
47 changes: 46 additions & 1 deletion examples/lock-app/nrfconnect/main/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,16 @@

#include <dk_buttons_and_leds.h>
#include <logging/log.h>
#include <setup_payload/QRCodeSetupPayloadGenerator.h>
#include <setup_payload/SetupPayload.h>
#include <zephyr.h>

#define FACTORY_RESET_TRIGGER_TIMEOUT 3000
#define FACTORY_RESET_CANCEL_WINDOW_TIMEOUT 3000
#define APP_EVENT_QUEUE_SIZE 10
#define BUTTON_PUSH_EVENT 1
#define BUTTON_RELEASE_EVENT 0
#define EXAMPLE_VENDOR_ID 0xabcd

LOG_MODULE_DECLARE(app);
K_MSGQ_DEFINE(sAppEventQueue, sizeof(AppEvent), APP_EVENT_QUEUE_SIZE, alignof(AppEvent));
Expand Down Expand Up @@ -86,9 +89,51 @@ int AppTask::In 8000 it()
// Init ZCL Data Model
InitDataModelHandler();
StartServer(&sSessions);
PrintQRCode();

return 0;
}

void AppTask::PrintQRCode() const
{
CHIP_ERROR err = CHIP_NO_ERROR;
uint32_t setUpPINCode = 0;
uint32_t setUpDiscriminator = 0;

err = ConfigurationMgr().GetSetupPinCode(setUpPINCode);
if (err != CHIP_NO_ERROR)
{
LOG_INF("ConfigurationMgr().GetSetupPinCode() failed: %s", log_strdup(chip::ErrorStr(err)));
}

err = ConfigurationMgr().GetSetupDiscriminator(setUpDiscriminator);
if (err != CHIP_NO_ERROR)
{
LOG_INF("ConfigurationMgr().GetSetupDiscriminator() failed: %s", log_strdup(chip::ErrorStr(err)));
}

chip::SetupPayload payload;
payload.version = 1;
payload.vendorID = EXAMPLE_VENDOR_ID;
payload.productID = 1;
payload.setUpPINCode = setUpPINCode;
payload.discriminator = setUpDiscriminator;
chip::QRCodeSetupPayloadGenerator generator(payload);

// TODO: Usage of STL will significantly increase the image size, this should be changed to more efficient method for
// generating payload
std::string result;
err = generator.payloadBase41Representation(result);
if (err != CHIP_NO_ERROR)
{
LOG_ERR("Failed to generate QR Code");
}

LOG_INF("SetupPINCode: [%" PRIu32 "]", setUpPINCode);
// There might be whitespace in setup QRCode, add brackets to make it clearer.
LOG_INF("SetupQRCode: [%s]", log_strdup(result.c_str()));
}

int AppTask::StartApp()
{
int ret = Init();
Expand Down Expand Up @@ -318,7 +363,7 @@ void AppTask::JoinerHandler(AppEvent * aEvent)
error = ThreadStackMgr().JoinerStart();
#endif

LOG_INF("Thread joiner triggering result: %s", chip::ErrorStr(error));
LOG_INF("Thread joiner triggering result: %s", log_strdup(chip::ErrorStr(error)));
}

void AppTask::CancelTimer()
Expand Down
1 change: 1 addition & 0 deletions examples/lock-app/nrfconnect/main/include/AppTask.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class AppTask
friend AppTask & GetAppTask(void);

int Init();
void PrintQRCode() const;

static void ActionInitiated(BoltLockManager::Action_t aAction, int32_t aActor);
static void ActionCompleted(BoltLockManager::Action_t aAction);
Expand Down
1 change: 1 addition & 0 deletions examples/lock-app/nrfconnect/prj.conf
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
# NOTE if this option is missing the application may still build successfully, but crash
# later at run-time due to various structure incompatibilities between C and C++.
CONFIG_CPLUSPLUS=y
CONFIG_LIB_CPLUSPLUS=y

# Use newlib since the Zephyr-supplied minimal libc is not enough to build the CHIP
CONFIG_NEWLIB_LIBC=y
Expand Down
0