Skip to content

Commit

Permalink
fix: init server on scheduled task
Browse files Browse the repository at this point in the history
Change-Id: If7c287ea7e9632fb8b4a49e8e4c82af4002cf4e4
  • Loading branch information
rochaferraz committed Mar 31, 2022
1 parent 21d6654 commit 033488c
Showing 1 changed file with 20 additions and 15 deletions.
35 changes: 20 additions & 15 deletions examples/chef/esp32/main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,25 @@ void printQRCode()
}
#endif // CONFIG_HAVE_DISPLAY

void InitServer(intptr_t context)
{
// Start IM server
chip::Server::GetInstance().Init();

// Device Attestation & Onboarding codes
chip::Credentials::SetDeviceAttestationCredentialsProvider(chip::Credentials::Examples::GetExampleDACProvider());
chip::DeviceLayer::ConfigurationMgr().LogDeviceConfig();

if (chip::Server::GetInstance().GetCommissioningWindowManager().OpenBasicCommissioningWindow() != CHIP_NO_ERROR)
{
ChipLogError(Shell, "OpenBasicCommissioningWindow() failed");
}

// Register a function to receive events from the CHIP device layer. Note that calls to
// this function will happen on the CHIP event loop thread, not the app_main thread.
PlatformMgr().AddEventHandler(DeviceEventCallback, reinterpret_cast<intptr_t>(nullptr));
}

extern "C" void app_main(void)
{
ESP_ERROR_CHECK(nvs_flash_init());
Expand All @@ -173,27 +192,13 @@ extern "C" void app_main(void)
// Network connectivity
// Note to integration: StartWiFiManagement does not exist on ESP32

// Start IM server
chip::Server::GetInstance().Init();

// Device Attestation & Onboarding codes
chip::Credentials::SetDeviceAttestationCredentialsProvider(chip::Credentials::Examples::GetExampleDACProvider());
chip::DeviceLayer::ConfigurationMgr().LogDeviceConfig();
chip::DeviceLayer::PlatformMgr().ScheduleWork(InitServer, reinterpret_cast<intptr_t>(nullptr));
PrintOnboardingCodes(chip::RendezvousInformationFlag(chip::RendezvousInformationFlag::kBLE));

#if CONFIG_HAVE_DISPLAY
printQRCode();
#endif // CONFIG_HAVE_DISPLAY

if (chip::Server::GetInstance().GetCommissioningWindowManager().OpenBasicCommissioningWindow() != CHIP_NO_ERROR)
{
ChipLogError(Shell, "OpenBasicCommissioningWindow() failed");
}

// Register a function to receive events from the CHIP device layer. Note that calls to
// this function will happen on the CHIP event loop thread, not the app_main thread.
PlatformMgr().AddEventHandler(DeviceEventCallback, reinterpret_cast<intptr_t>(nullptr));

#if CONFIG_ENABLE_PW_RPC
chip::rpc::Init();
#endif // CONFIG_ENABLE_PW_RPC
Expand Down

0 comments on commit 033488c

Please sign in to comment.