Skip to content

Commit

Permalink
Resolved merge conflicts and addressed review comment
Browse files Browse the repository at this point in the history
  • Loading branch information
jadhavrohit924 committed Apr 20, 2022
1 parent f5c77a4 commit 900f2d0
Show file tree
Hide file tree
Showing 12 changed files with 150 additions and 104 deletions.
2 changes: 2 additions & 0 deletions examples/all-clusters-app/esp32/main/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,15 @@ set(PRIV_INCLUDE_DIRS_LIST
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/zzz_generated/all-clusters-app"
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/examples/all-clusters-app/all-clusters-common/include"
"${CMAKE_CURRENT_LIST_DIR}/include"
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip"
)
set(SRC_DIRS_LIST
"${CMAKE_CURRENT_LIST_DIR}"
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/zzz_generated/all-clusters-app/zap-generated"
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/zzz_generated/app-common/app-common/zap-generated/attributes"
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/zzz_generated/app-common/app-common/zap-generated"
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/examples/platform/esp32/route_hook"
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/examples/platform/esp32/ota"
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/examples/platform/esp32/shell_extension"
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/server"
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/util"
Expand Down
17 changes: 16 additions & 1 deletion examples/all-clusters-app/esp32/main/DeviceCallbacks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
#include <app/server/Dnssd.h>
#include <app/util/basic-types.h>
#include <app/util/util.h>
#include <examples/platform/esp32/ota/InitOTAR.h>
#include <lib/dnssd/Advertiser.h>
#include <lib/support/CodeUtils.h>

Expand All @@ -55,7 +56,8 @@ using namespace ::chip::System;
using namespace ::chip::DeviceLayer;
using namespace chip::app;

constexpr uint32_t kIdentifyTimerDelayMS = 250;
constexpr uint32_t kIdentifyTimerDelayMS = 250;
constexpr uint32_t mInitOTARequestorDelaySec = 3;

void OnIdentifyTriggerEffect(Identify * identify)
{
Expand Down Expand Up @@ -200,13 +202,26 @@ void DeviceCallbacks::PostAttributeChangeCallback(EndpointId endpointId, Cluster
ESP_LOGI(TAG, "Current free heap: %zu\n", heap_caps_get_free_size(MALLOC_CAP_8BIT));
}

void InitOTARequestorHandler(System::Layer * systemLayer, void * appState)
{
InitOTA::Instance().InitOTARequestor();
}

void DeviceCallbacks::OnInternetConnectivityChange(const ChipDeviceEvent * event)
{
static bool IsOTAInitialized = false;
if (event->InternetConnectivityChange.IPv4 == kConnectivity_Established)
{
ESP_LOGI(TAG, "Server ready at: %s:%d", event->InternetConnectivityChange.address, CHIP_PORT);
wifiLED.Set(true);
chip::app::DnssdServer::Instance().StartServer();

if (!IsOTAInitialized)
{
chip::DeviceLayer::SystemLayer().StartTimer(chip::System::Clock::Seconds32(mInitOTARequestorDelaySec),
InitOTARequestorHandler, nullptr);
IsOTAInitialized = true;
}
}
else if (event->InternetConnectivityChange.IPv4 == kConnectivity_Lost)
{
Expand Down
26 changes: 1 addition & 25 deletions examples/all-clusters-app/esp32/main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,21 +70,12 @@ using namespace ::chip::DeviceLayer;
// Used to indicate that an IP address has been added to the QRCode
#define EXAMPLE_VENDOR_TAG_IP 1

const char * TAG = "all-clusters-app";
const uint32_t delayConfirmImageSec = 10;
const char * TAG = "all-clusters-app";

static DeviceCallbacks EchoCallbacks;

namespace {

#if CONFIG_ENABLE_OTA_REQUESTOR
DefaultOTARequestor gRequestorCore;
DefaultOTARequestorStorage gRequestorStorage;
DefaultOTARequestorDriver gRequestorUser;
BDXDownloader gDownloader;
OTAImageProcessorImpl gImageProcessor;
#endif

app::Clusters::NetworkCommissioning::Instance
sWiFiNetworkCommissioningInstance(0 /* Endpoint Id */, &(NetworkCommissioning::ESPWiFiDriver::GetInstance()));

Expand All @@ -107,19 +98,6 @@ constexpr EndpointId kNetworkCommissioningEndpointSecondary = 0xFFFE;

} // namespace

static void InitOTARequestor(void)
{
#if CONFIG_ENABLE_OTA_REQUESTOR
SetRequestorInstance(&gRequestorCore);
gRequestorStorage.Init(Server::GetInstance().GetPersistentStorage());
gRequestorCore.Init(Server::GetInstance(), gRequestorStorage, gRequestorUser, gDownloader);
gImageProcessor.SetOTADownloader(&gDownloader);
gDownloader.SetImageProcessorDelegate(&gImageProcessor);
gRequestorUser.SetDelayConfirmCurrentImageSec(delayConfirmImageSec);
gRequestorUser.Init(&gRequestorCore, &gImageProcessor);
#endif
}

static void InitServer(intptr_t context)
{
// Init ZCL Data Model and CHIP App Server
Expand All @@ -138,8 +116,6 @@ static void InitServer(intptr_t context)
#if CONFIG_DEVICE_TYPE_M5STACK
SetupPretendDevices();
#endif

InitOTARequestor();
}

extern "C" void app_main()
Expand Down
2 changes: 2 additions & 0 deletions examples/lighting-app/esp32/main/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@ idf_component_register(PRIV_INCLUDE_DIRS
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/zzz_generated/lighting-app"
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/examples/lighting-app/lighting-common/color_format"
"${CMAKE_CURRENT_LIST_DIR}/include"
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip"
SRC_DIRS
"${CMAKE_CURRENT_LIST_DIR}"
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/zzz_generated/app-common/app-common/zap-generated/attributes"
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/zzz_generated/app-common/app-common/zap-generated"
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/zzz_generated/lighting-app/zap-generated"
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/examples/platform/esp32/route_hook"
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/examples/platform/esp32/ota"
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/examples/platform/esp32/shell_extension"
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/examples/lighting-app/lighting-common/color_format"
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/server"
Expand Down
17 changes: 16 additions & 1 deletion examples/lighting-app/esp32/main/DeviceCallbacks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,11 @@
#include <app-common/zap-generated/cluster-id.h>
#include <app/server/Dnssd.h>
#include <app/util/util.h>
#include <examples/platform/esp32/ota/InitOTAR.h>
#include <lib/support/CodeUtils.h>

static const char * TAG = "light-app-callbacks";
static const char * TAG = "light-app-callbacks";
constexpr uint32_t mInitOTARequestorDelaySec = 3;

extern LEDWidget AppLED;

Expand Down Expand Up @@ -149,12 +151,25 @@ void DeviceCallbacks::PostAttributeChangeCallback(EndpointId endpointId, Cluster
ESP_LOGI(TAG, "Current free heap: %zu\n", heap_caps_get_free_size(MALLOC_CAP_8BIT));
}

void InitOTARequestorHandler(System::Layer * systemLayer, void * appState)
{
InitOTA::Instance().InitOTARequestor();
}

void DeviceCallbacks::OnInternetConnectivityChange(const ChipDeviceEvent * event)
{
static bool IsOTAInitialized = false;
if (event->InternetConnectivityChange.IPv4 == kConnectivity_Established)
{
ESP_LOGI(TAG, "Server ready at: %s:%d", event->InternetConnectivityChange.address, CHIP_PORT);
chip::app::DnssdServer::Instance().StartServer();

if (!IsOTAInitialized)
{
chip::DeviceLayer::SystemLayer().StartTimer(chip::System::Clock::Seconds32(mInitOTARequestorDelaySec),
InitOTARequestorHandler, nullptr);
IsOTAInitialized = true;
}
}
else if (event->InternetConnectivityChange.IPv4 == kConnectivity_Lost)
{
Expand Down
31 changes: 1 addition & 30 deletions examples/lighting-app/esp32/main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,35 +27,21 @@
#include "nvs_flash.h"
#include "shell_extension/launch.h"
#include <app/clusters/network-commissioning/network-commissioning.h>
#include <app/clusters/ota-requestor/BDXDownloader.h>
#include <app/clusters/ota-requestor/DefaultOTARequestor.h>
#include <app/clusters/ota-requestor/DefaultOTARequestorDriver.h>
#include <app/clusters/ota-requestor/DefaultOTARequestorStorage.h>
#include <app/server/Dnssd.h>
#include <app/server/OnboardingCodesUtil.h>
#include <app/server/Server.h>
#include <credentials/DeviceAttestationCredsProvider.h>
#include <credentials/examples/DeviceAttestationCredsExample.h>
#include <platform/ESP32/NetworkCommissioningDriver.h>
#include <platform/ESP32/OTAImageProcessorImpl.h>

using namespace ::chip;
using namespace ::chip::Credentials;
using namespace ::chip::DeviceManager;
using namespace ::chip::DeviceLayer;

#if CONFIG_ENABLE_OTA_REQUESTOR
DefaultOTARequestor gRequestorCore;
DefaultOTARequestorStorage gRequestorStorage;
DefaultOTARequestorDriver gRequestorUser;
BDXDownloader gDownloader;
OTAImageProcessorImpl gImageProcessor;
#endif

LEDWidget AppLED;

static const char * TAG = "light-app";
const uint32_t delayConfirmImageSec = 10;
static const char * TAG = "light-app";

static DeviceCallbacks EchoCallbacks;
namespace {
Expand All @@ -65,19 +51,6 @@ app::Clusters::NetworkCommissioning::Instance
#endif
} // namespace

static void InitOTARequestor(void)
{
#if CONFIG_ENABLE_OTA_REQUESTOR
SetRequestorInstance(&gRequestorCore);
gRequestorStorage.Init(Server::GetInstance().GetPersistentStorage());
gRequestorCore.Init(Server::GetInstance(), gRequestorStorage, gRequestorUser, gDownloader);
gImageProcessor.SetOTADownloader(&gDownloader);
gDownloader.SetImageProcessorDelegate(&gImageProcessor);
gRequestorUser.SetDelayConfirmCurrentImageSec(delayConfirmImageSec);
gRequestorUser.Init(&gRequestorCore, &gImageProcessor);
#endif
}

static void InitServer(intptr_t context)
{
// Print QR Code URL
Expand All @@ -100,8 +73,6 @@ static void InitServer(intptr_t context)
chip::app::DnssdServer::Instance().StartServer();
}
#endif

InitOTARequestor();
}

extern "C" void app_main()
Expand Down
6 changes: 4 additions & 2 deletions examples/ota-requestor-app/esp32/main/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ idf_component_register(PRIV_INCLUDE_DIRS
"${CMAKE_CURRENT_LIST_DIR}/include"
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src"
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/zzz_generated/ota-requestor-app/"
SRC_DIRS
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip"
SRC_DIRS
"${CMAKE_CURRENT_LIST_DIR}"
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/zzz_generated/ota-requestor-app/zap-generated"
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/zzz_generated/app-common/app-common/zap-generated/attributes"
Expand Down Expand Up @@ -49,7 +50,8 @@ idf_component_register(PRIV_INCLUDE_DIRS
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/clusters/network-commissioning"
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/clusters/operational-credentials-server"
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/clusters/ota-requestor"
PRIV_REQUIRES chip QRCode bt console app_update)
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/examples/platform/esp32/ota"
PRIV_REQUIRES chip QRCode bt console app_update)

set_property(TARGET ${COMPONENT_LIB} PROPERTY CXX_STANDARD 14)
target_compile_options(${COMPONENT_LIB} PRIVATE "-DLWIP_IPV6_SCOPES=0" "-DCHIP_HAVE_CONFIG_H")
Expand Down
16 changes: 15 additions & 1 deletion examples/ota-requestor-app/esp32/main/DeviceCallbacks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,11 @@
#include <app-common/zap-generated/attribute-id.h>
#include <app-common/zap-generated/cluster-id.h>
#include <app/server/Dnssd.h>
#include <examples/platform/esp32/ota/InitOTAR.h>
#include <lib/support/CodeUtils.h>

static const char * TAG = "echo-devicecallbacks";
static const char * TAG = "echo-devicecallbacks";
constexpr uint32_t mInitOTARequestorDelaySec = 3;

using namespace ::chip;
using namespace ::chip::Inet;
Expand Down Expand Up @@ -78,12 +80,24 @@ void DeviceCallbacks::PostAttributeChangeCallback(EndpointId endpointId, Cluster
ESP_LOGI(TAG, "Current free heap: %d\n", heap_caps_get_free_size(MALLOC_CAP_8BIT));
}

void InitOTARequestorHandler(System::Layer * systemLayer, void * appState)
{
InitOTA::Instance().InitOTARequestor();
}

void DeviceCallbacks::OnInternetConnectivityChange(const ChipDeviceEvent * event)
{
static bool IsOTAInitialized = false;
if (event->InternetConnectivityChange.IPv4 == kConnectivity_Established)
{
ESP_LOGI(TAG, "Server ready at: %s:%d", event->InternetConnectivityChange.address, CHIP_PORT);
chip::app::DnssdServer::Instance().StartServer();
if (!IsOTAInitialized)
{
chip::DeviceLayer::SystemLayer().StartTimer(chip::System::Clock::Seconds32(mInitOTARequestorDelaySec),
InitOTARequestorHandler, nullptr);
IsOTAInitialized = true;
}
}
else if (event->InternetConnectivityChange.IPv4 == kConnectivity_Lost)
{
Expand Down
23 changes: 1 addition & 22 deletions examples/ota-requestor-app/esp32/main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,6 @@
#include "freertos/task.h"
#include "nvs_flash.h"
#include <app/clusters/network-commissioning/network-commissioning.h>
#include <app/clusters/ota-requestor/BDXDownloader.h>
#include <app/clusters/ota-requestor/DefaultOTARequestor.h>
#include <app/clusters/ota-requestor/DefaultOTARequestorDriver.h>
#include <app/clusters/ota-requestor/DefaultOTARequestorStorage.h>
#include <app/server/Server.h>
#include <platform/ESP32/NetworkCommissioningDriver.h>

Expand All @@ -41,25 +37,16 @@

#include <lib/support/ErrorStr.h>

#include "OTAImageProcessorImpl.h"

using namespace ::chip;
using namespace ::chip::System;
using namespace ::chip::Credentials;
using namespace ::chip::DeviceManager;
using namespace ::chip::DeviceLayer;

namespace {
const char * TAG = "ota-requester-app";
const uint32_t delayConfirmImageSec = 10;
const char * TAG = "ota-requester-app";
static DeviceCallbacks EchoCallbacks;

DefaultOTARequestor gRequestorCore;
DefaultOTARequestorStorage gRequestorStorage;
DefaultOTARequestorDriver gRequestorUser;
BDXDownloader gDownloader;
OTAImageProcessorImpl gImageProcessor;

app::Clusters::NetworkCommissioning::Instance
sWiFiNetworkCommissioningInstance(0 /* Endpoint Id */, &(NetworkCommissioning::ESPWiFiDriver::GetInstance()));

Expand All @@ -73,14 +60,6 @@ static void InitServer(intptr_t context)
SetDeviceAttestationCredentialsProvider(Examples::GetExampleDACProvider());

sWiFiNetworkCommissioningInstance.Init();

SetRequestorInstance(&gRequestorCore);
gRequestorStorage.Init(Server::GetInstance().GetPersistentStorage());
gRequestorCore.Init(Server::GetInstance(), gRequestorStorage, gRequestorUser, gDownloader);
gImageProcessor.SetOTADownloader(&gDownloader);
gDownloader.SetImageProcessorDelegate(&gImageProcessor);
gRequestorUser.SetDelayConfirmCurrentImageSec(delayConfirmImageSec);
gRequestorUser.Init(&gRequestorCore, &gImageProcessor);
}

} // namespace
Expand Down
31 changes: 31 additions & 0 deletions examples/platform/esp32/ota/InitOTAR.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
*
* Copyright (c) 2021 Project CHIP Authors
*
* 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.
*/

#include "InitOTAR.h"

void InitOTA::InitOTARequestor()
{

#if CONFIG_ENABLE_OTA_REQUESTOR
SetRequestorInstance(&gRequestorCore);
gRequestorStorage.Init(Server::GetInstance().GetPersistentStorage());
gRequestorCore.Init(Server::GetInstance(), gRequestorStorage, gRequestorUser, gDownloader);
gImageProcessor.SetOTADownloader(&gDownloader);
gDownloader.SetImageProcessorDelegate(&gImageProcessor);
gRequestorUser.Init(&gRequestorCore, &gImageProcessor);
#endif
}
Loading

0 comments on commit 900f2d0

Please sign in to comment.