Skip to content

Commit

Permalink
Added delay from device side
Browse files Browse the repository at this point in the history
  • Loading branch information
jadhavrohit924 committed Jun 3, 2022
1 parent 6162fc2 commit 6d60c8d
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 15 deletions.
9 changes: 0 additions & 9 deletions examples/platform/esp32/common/CommonDeviceCallbacks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
#include <app/server/Dnssd.h>
#include <app/util/util.h>
#include <lib/support/CodeUtils.h>
#include <platform/ESP32/ESP32Utils.h>
#if CONFIG_ENABLE_OTA_REQUESTOR
#include <ota/OTAHelper.h>
#endif
Expand All @@ -59,14 +58,6 @@ void CommonDeviceCallbacks::DeviceEventCallback(const ChipDeviceEvent * event, i
OnSessionEstablished(event);
break;

case DeviceEventType::kFailSafeTimerExpired: {
CHIP_ERROR error = chip::DeviceLayer::Internal::ESP32Utils::ClearWiFiStationProvision();
if (error != CHIP_NO_ERROR)
{
ChipLogError(DeviceLayer, "ClearWiFiStationProvision failed: %s", chip::ErrorStr(error));
}
}
break;
case DeviceEventType::kCHIPoBLEConnectionEstablished:
ESP_LOGI(TAG, "CHIPoBLE connection established");
break;
Expand Down
5 changes: 1 addition & 4 deletions src/controller/AutoCommissioner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -297,14 +297,11 @@ Optional<System::Clock::Timeout> AutoCommissioner::GetCommandTimeout(Commissioni
// Per spec, all commands that are sent with the arm failsafe held need at least a 30s timeout.
// Network clusters can indicate the time required to connect, so if we are connecting, use that time as long as it is > 30s.
app::Clusters::NetworkCommissioning::Attributes::ConnectMaxTimeSeconds::TypeInfo::DecodableType seconds = 30;
// Client will wait for some time to receive connect network response.
app::Clusters::NetworkCommissioning::Attributes::ConnectMaxTimeSeconds::TypeInfo::DecodableType extraSeconds = 1;

switch (stage)
{
case CommissioningStage::kWiFiNetworkEnable:
ChipLogError(Controller, "Setting wifi connection time min = %u", mDeviceCommissioningInfo.network.wifi.minConnectionTime);
seconds = std::max(static_cast<uint8_t>(mDeviceCommissioningInfo.network.wifi.minConnectionTime + extraSeconds), seconds);
seconds = std::max(mDeviceCommissioningInfo.network.wifi.minConnectionTime, seconds);
break;
case CommissioningStage::kThreadNetworkEnable:
seconds = std::max(mDeviceCommissioningInfo.network.thread.minConnectionTime, seconds);
Expand Down
8 changes: 7 additions & 1 deletion src/platform/ESP32/NetworkCommissioningDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,11 @@ void ESPWiFiDriver::OnConnectWiFiNetworkFailed()

void ESPWiFiDriver::OnConnectWiFiNetworkFailed(chip::System::Layer * aLayer, void * aAppState)
{
CHIP_ERROR error = chip::DeviceLayer::Internal::ESP32Utils::ClearWiFiStationProvision();
if (error != CHIP_NO_ERROR)
{
ChipLogError(DeviceLayer, "ClearWiFiStationProvision failed: %s", chip::ErrorStr(error));
}
ESPWiFiDriver::GetInstance().OnConnectWiFiNetworkFailed();
}

Expand All @@ -212,7 +217,8 @@ void ESPWiFiDriver::ConnectNetwork(ByteSpan networkId, ConnectCallback * callbac
reinterpret_cast<const char *>(mStagingNetwork.credentials), mStagingNetwork.credentialsLen);

err = DeviceLayer::SystemLayer().StartTimer(
static_cast<System::Clock::Timeout>((kWiFiConnectNetworkTimeoutSeconds) *secToMiliSec), OnConnectWiFiNetworkFailed, NULL);
static_cast<System::Clock::Timeout>((kWiFiConnectNetworkTimeoutSeconds - kClientCommunicationDalay) * secToMiliSec),
OnConnectWiFiNetworkFailed, NULL);
mpConnectCallback = callback;
exit:
if (err != CHIP_NO_ERROR)
Expand Down
3 changes: 2 additions & 1 deletion src/platform/ESP32/NetworkCommissioningDriver.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ namespace NetworkCommissioning {
namespace {
constexpr uint8_t kMaxWiFiNetworks = 1;
constexpr uint8_t kWiFiScanNetworksTimeOutSeconds = 10;
constexpr uint8_t kWiFiConnectNetworkTimeoutSeconds = 30;
constexpr uint8_t kClientCommunicationDalay = 10;
constexpr uint8_t kWiFiConnectNetworkTimeoutSeconds = 30 + kClientCommunicationDalay;
} // namespace

class ESPScanResponseIterator : public Iterator<WiFiScanResponse>
Expand Down

0 comments on commit 6d60c8d

Please sign in to comment.