Skip to content

Commit

Permalink
Fix ble connect error in Temperature Measurement app (#7687)
Browse files Browse the repository at this point in the history
* Fix ble connection in Temperature Measurement app

* Fix resolve mdns in temperature measurement app
  • Loading branch information
PSONALl authored and pull[bot] committed Jun 29, 2021
1 parent f2c2f2a commit 1290338
Show file tree
Hide file tree
Showing 5 changed files with 1,293 additions and 364 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "esp_log.h"
#include <app/common/gen/attribute-id.h>
#include <app/common/gen/cluster-id.h>
#include <app/server/Mdns.h>
#include <support/CodeUtils.h>

static const char * TAG = "echo-devicecallbacks";
Expand All @@ -48,6 +49,17 @@ void DeviceCallbacks::DeviceEventCallback(const ChipDeviceEvent * event, intptr_
case DeviceEventType::kSessionEstablished:
OnSessionEstablished(event);
break;
case DeviceEventType::kInterfaceIpAddressChanged:
if ((event->InterfaceIpAddressChanged.Type == InterfaceIpChangeType::kIpV4_Assigned) ||
(event->InterfaceIpAddressChanged.Type == InterfaceIpChangeType::kIpV6_Assigned))
{
// MDNS server restart on any ip assignment: if link local ipv6 is configured, that
// will not trigger a 'internet connectivity change' as there is no internet
// connectivity. MDNS still wants to refresh its listening interfaces to include the
// newly selected address.
chip::app::Mdns::StartServer();
}
break;
}

ESP_LOGI(TAG, "Current free heap: %d\n", heap_caps_get_free_size(MALLOC_CAP_8BIT));
Expand All @@ -70,6 +82,7 @@ void DeviceCallbacks::OnInternetConnectivityChange(const ChipDeviceEvent * event
if (event->InternetConnectivityChange.IPv4 == kConnectivity_Established)
{
ESP_LOGI(TAG, "Server ready at: %s:%d", event->InternetConnectivityChange.address, CHIP_PORT);
chip::app::Mdns::StartServer();
}
else if (event->InternetConnectivityChange.IPv4 == kConnectivity_Lost)
{
Expand All @@ -78,6 +91,7 @@ void DeviceCallbacks::OnInternetConnectivityChange(const ChipDeviceEvent * event
if (event->InternetConnectivityChange.IPv6 == kConnectivity_Established)
{
ESP_LOGI(TAG, "IPv6 Server ready...");
chip::app::Mdns::StartServer();
}
else if (event->InternetConnectivityChange.IPv6 == kConnectivity_Lost)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,77 +251,6 @@ void DispatchServerCommand(app::Command * apCommandObj, CommandId aCommandId, En
{
switch (aCommandId)
{
case ZCL_ADD_THREAD_NETWORK_COMMAND_ID: {
expectArgumentCount = 3;
chip::ByteSpan operationalDataset;
uint64_t breadcrumb;
uint32_t timeoutMs;
bool argExists[3];

memset(argExists, 0, sizeof argExists);

while ((TLVError = aDataTlv.Next()) == CHIP_NO_ERROR)
{
// Since call to aDataTlv.Next() is CHIP_NO_ERROR, the read head always points to an element.
// Skip this element if it is not a ContextTag, not consider it as an error if other values are valid.
if (!TLV::IsContextTag(aDataTlv.GetTag()))
{
continue;
}
currentDecodeTagId = TLV::TagNumFromTag(aDataTlv.GetTag());
if (currentDecodeTagId < 3)
{
if (argExists[currentDecodeTagId])
{
ChipLogProgress(Zcl, "Duplicate TLV tag %" PRIx32, TLV::TagNumFromTag(aDataTlv.GetTag()));
TLVUnpackError = CHIP_ERROR_IM_MALFORMED_COMMAND_DATA_ELEMENT;
break;
}
else
{
argExists[currentDecodeTagId] = true;
validArgumentCount++;
}
}
switch (currentDecodeTagId)
{
case 0: {
const uint8_t * data = nullptr;
TLVUnpackError = aDataTlv.GetDataPtr(data);
operationalDataset = chip::ByteSpan(data, aDataTlv.GetLength());
}
break;
case 1:
TLVUnpackError = aDataTlv.Get(breadcrumb);
break;
case 2:
TLVUnpackError = aDataTlv.Get(timeoutMs);
break;
default:
// Unsupported tag, ignore it.
ChipLogProgress(Zcl, "Unknown TLV tag during processing.");
break;
}
if (CHIP_NO_ERROR != TLVUnpackError)
{
break;
}
}

if (CHIP_END_OF_TLV == TLVError)
{
// CHIP_END_OF_TLV means we have iterated all items in the structure, which is not a real error.
TLVError = CHIP_NO_ERROR;
}

if (CHIP_NO_ERROR == TLVError && CHIP_NO_ERROR == TLVUnpackError && 3 == validArgumentCount)
{
// TODO(#5098) We should pass the Command Object and EndpointId to the cluster callbacks.
wasHandled = emberAfNetworkCommissioningClusterAddThreadNetworkCallback(apCommandObj, operationalDataset,
breadcrumb, timeoutMs);
}
break;
}
case ZCL_ADD_WI_FI_NETWORK_COMMAND_ID: {
expectArgumentCount = 4;
chip::ByteSpan ssid;
Expand Down Expand Up @@ -742,77 +671,6 @@ void DispatchServerCommand(app::Command * apCommandObj, CommandId aCommandId, En
}
break;
}
case ZCL_UPDATE_THREAD_NETWORK_COMMAND_ID: {
expectArgumentCount = 3;
chip::ByteSpan operationalDataset;
uint64_t breadcrumb;
uint32_t timeoutMs;
bool argExists[3];

memset(argExists, 0, sizeof argExists);

while ((TLVError = aDataTlv.Next()) == CHIP_NO_ERROR)
{
// Since call to aDataTlv.Next() is CHIP_NO_ERROR, the read head always points to an element.
// Skip this element if it is not a ContextTag, not consider it as an error if other values are valid.
if (!TLV::IsContextTag(aDataTlv.GetTag()))
{
continue;
}
currentDecodeTagId = TLV::TagNumFromTag(aDataTlv.GetTag());
if (currentDecodeTagId < 3)
{
if (argExists[currentDecodeTagId])
{
ChipLogProgress(Zcl, "Duplicate TLV tag %" PRIx32, TLV::TagNumFromTag(aDataTlv.GetTag()));
TLVUnpackError = CHIP_ERROR_IM_MALFORMED_COMMAND_DATA_ELEMENT;
break;
}
else
{
argExists[currentDecodeTagId] = true;
validArgumentCount++;
}
}
switch (currentDecodeTagId)
{
case 0: {
const uint8_t * data = nullptr;
TLVUnpackError = aDataTlv.GetDataPtr(data);
operationalDataset = chip::ByteSpan(data, aDataTlv.GetLength());
}
break;
case 1:
TLVUnpackError = aDataTlv.Get(breadcrumb);
break;
case 2:
TLVUnpackError = aDataTlv.Get(timeoutMs);
break;
default:
// Unsupported tag, ignore it.
ChipLogProgress(Zcl, "Unknown TLV tag during processing.");
break;
}
if (CHIP_NO_ERROR != TLVUnpackError)
{
break;
}
}

if (CHIP_END_OF_TLV == TLVError)
{
// CHIP_END_OF_TLV means we have iterated all items in the structure, which is not a real error.
TLVError = CHIP_NO_ERROR;
}

if (CHIP_NO_ERROR == TLVError && CHIP_NO_ERROR == TLVUnpackError && 3 == validArgumentCount)
{
// TODO(#5098) We should pass the Command Object and EndpointId to the cluster callbacks.
wasHandled = emberAfNetworkCommissioningClusterUpdateThreadNetworkCallback(apCommandObj, operationalDataset,
breadcrumb, timeoutMs);
}
break;
}
case ZCL_UPDATE_WI_FI_NETWORK_COMMAND_ID: {
expectArgumentCount = 4;
chip::ByteSpan ssid;
Expand Down
15 changes: 0 additions & 15 deletions examples/temperature-measurement-app/esp32/main/gen/callback.h
Original file line number Diff line number Diff line change
Expand Up @@ -773,13 +773,6 @@ bool emberAfGeneralCommissioningClusterCommissioningCompleteCallback(chip::app::
bool emberAfGeneralCommissioningClusterSetRegulatoryConfigCallback(chip::app::Command * commandObj, uint8_t location,
uint8_t * countryCode, uint64_t breadcrumb, uint32_t timeoutMs);

/**
* @brief Network Commissioning Cluster AddThreadNetwork Command callback
*/

bool emberAfNetworkCommissioningClusterAddThreadNetworkCallback(chip::app::Command * commandObj, chip::ByteSpan operationalDataset,
uint64_t breadcrumb, uint32_t timeoutMs);

/**
* @brief Network Commissioning Cluster AddWiFiNetwork Command callback
*/
Expand Down Expand Up @@ -822,14 +815,6 @@ bool emberAfNetworkCommissioningClusterRemoveNetworkCallback(chip::app::Command
bool emberAfNetworkCommissioningClusterScanNetworksCallback(chip::app::Command * commandObj, chip::ByteSpan ssid,
uint64_t breadcrumb, uint32_t timeoutMs);

/**
* @brief Network Commissioning Cluster UpdateThreadNetwork Command callback
*/

bool emberAfNetworkCommissioningClusterUpdateThreadNetworkCallback(chip::app::Command * commandObj,
chip::ByteSpan operationalDataset, uint64_t breadcrumb,
uint32_t timeoutMs);

/**
* @brief Network Commissioning Cluster UpdateWiFiNetwork Command callback
*/
Expand Down
Loading

0 comments on commit 1290338

Please sign in to comment.