Skip to content
Open
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
52 changes: 52 additions & 0 deletions examples/proximity-ranger-app/esp32/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#
# Copyright (c) 2021 Project CHIP Authors
# All rights reserved.
#
# 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.

# The following lines of boilerplate have to be in your project's
# CMakeLists in this exact order for cmake to work correctly
cmake_minimum_required(VERSION 3.20)

set(PROJECT_VER "v1.0")
set(PROJECT_VER_NUMBER 1)

set(is_debug true CACHE BOOL "Optimization variable")
if(NOT is_debug)
set(SDKCONFIG_DEFAULTS "sdkconfig.optimize.defaults")
endif()

include($ENV{IDF_PATH}/tools/cmake/project.cmake)
include(${CMAKE_CURRENT_LIST_DIR}/third_party/connectedhomeip/examples/common/cmake/idf_flashing.cmake)


set(EXTRA_COMPONENT_DIRS
"${CMAKE_CURRENT_LIST_DIR}/third_party/connectedhomeip/config/esp32/components"
"${CMAKE_CURRENT_LIST_DIR}/third_party/connectedhomeip/examples/common/QRCode"
)

project(chip-proximity-ranger-app)
idf_build_set_property(CXX_COMPILE_OPTIONS "-std=gnu++17;-Os;-DCHIP_HAVE_CONFIG_H" APPEND)
idf_build_set_property(C_COMPILE_OPTIONS "-Os" APPEND)
# For the C3, project_include.cmake sets -Wno-format, but does not clear various
# flags that depend on -Wformat
idf_build_set_property(COMPILE_OPTIONS "-Wno-format-nonliteral;-Wno-format-security" APPEND)

# -Wmaybe-uninitialized has too many false positives, including on std::optional
# and chip::Optional. Make it nonfatal.
#
# See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80635
idf_build_set_property(COMPILE_OPTIONS "-Wno-error=maybe-uninitialized" APPEND)
idf_build_set_property(COMPILE_OPTIONS "-Wno-error=missing-field-initializers" APPEND)

flashing_script()
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Copyright (c) 2026 Project CHIP Authors
* All rights reserved.
*
* 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 "BleRssiRangingAdapter.h"

ProximityRanging::ResultCodeEnum BleRssiRangingAdapter::StartSession(
uint8_t sessionId, const ProximityRanging::Commands::StartRangingRequest::DecodableType & request, Callback & callback)
{
// TODO: Implement ESP32 BLE RSSI scanning
return ProximityRanging::ResultCodeEnum::kRejectedInfeasibleRanging;
}

CHIP_ERROR BleRssiRangingAdapter::StopSession(uint8_t sessionId)
{
// TODO: Implement ESP32 session stop
return CHIP_ERROR_NOT_IMPLEMENTED;
}
84 changes: 84 additions & 0 deletions examples/proximity-ranger-app/esp32/main/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
#
# Copyright (c) 2021 Project CHIP Authors
# All rights reserved.
#
# 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.
#
#

get_filename_component(CHIP_ROOT ${CMAKE_SOURCE_DIR}/third_party/connectedhomeip REALPATH)
get_filename_component(APP_COMMON_GEN_DIR ${CHIP_ROOT}/zzz_generated/app-common/app-common/zap-generated REALPATH)
get_filename_component(PROX_RANGER_COMMON_DIR ${CHIP_ROOT}/examples/proximity-ranger-app/proximity-ranger-common REALPATH)

set(PRIV_INCLUDE_DIRS_LIST
"${CMAKE_CURRENT_LIST_DIR}/include"
"${PROX_RANGER_COMMON_DIR}/include"
"${CHIP_ROOT}/examples/platform/esp32"
"${CHIP_ROOT}/examples/providers"
)
set(SRC_DIRS_LIST
"${CMAKE_CURRENT_LIST_DIR}"
"${PROX_RANGER_COMMON_DIR}/src"
"${APP_COMMON_GEN_DIR}/attributes"
"${APP_COMMON_GEN_DIR}"
"${CHIP_ROOT}/examples/providers"
"${CHIP_ROOT}/examples/platform/esp32/ota"
"${CHIP_ROOT}/examples/platform/esp32/common"
"${CHIP_ROOT}/examples/platform/esp32/shell_extension"
)

if (CONFIG_ENABLE_PW_RPC)
# Append additional directories for RPC build
set(PRIV_INCLUDE_DIRS_LIST "${PRIV_INCLUDE_DIRS_LIST}"
"${CHIP_ROOT}/examples/platform/esp32/pw_sys_io/public"
"${CHIP_ROOT}/examples/common"
"${CHIP_ROOT}/examples/common/pigweed"
"${CHIP_ROOT}/examples/common/pigweed/esp32"
"${CHIP_ROOT}/src/lib/support"
)


if (${IDF_VERSION_MAJOR} LESS 5)
list(APPEND PRIV_INCLUDE_DIRS_LIST "${IDF_PATH}/components/freertos/include/freertos")
else()
list(APPEND PRIV_INCLUDE_DIRS_LIST "${IDF_PATH}/components/freertos/FreeRTOS-Kernel/include/freertos")
endif()

set(SRC_DIRS_LIST "${SRC_DIRS_LIST}"
"${CHIP_ROOT}/examples/platform/esp32"
"${CHIP_ROOT}/examples/common/pigweed"
"${CHIP_ROOT}/examples/common/pigweed/esp32"
)
endif (CONFIG_ENABLE_PW_RPC)

if (CONFIG_CHIP_ENABLE_ESP_DIAGNOSTICS)
list(APPEND PRIV_INCLUDE_DIRS_LIST "${CHIP_ROOT}/examples/platform/esp32/diagnostics")
list(APPEND SRC_DIRS_LIST "${CHIP_ROOT}/examples/platform/esp32/diagnostics")
endif (CONFIG_CHIP_ENABLE_ESP_DIAGNOSTICS)

idf_component_register(PRIV_INCLUDE_DIRS ${PRIV_INCLUDE_DIRS_LIST}
SRC_DIRS ${SRC_DIRS_LIST})

include(${CHIP_ROOT}/src/app/chip_data_model.cmake)
chip_configure_data_model(${COMPONENT_LIB}
ZAP_FILE ${CHIP_ROOT}/examples/proximity-ranger-app/proximity-ranger-common/proximity-ranger-app.zap
)

if ((CONFIG_CHIP_ENABLE_ESP_DIAGNOSTICS) AND (CONFIG_ESP_INSIGHTS_ENABLED))
target_add_binary_data(${COMPONENT_TARGET} "insights_auth_key.txt" TEXT)
endif()

target_compile_options(${COMPONENT_LIB} PRIVATE "-DCHIP_HAVE_CONFIG_H")
target_compile_options(${COMPONENT_LIB} PUBLIC
"-DCHIP_ADDRESS_RESOLVE_IMPL_INCLUDE_HEADER=<lib/address_resolve/AddressResolve_DefaultImpl.h>"
)
41 changes: 41 additions & 0 deletions examples/proximity-ranger-app/esp32/main/DeviceCallbacks.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
*
* Copyright (c) 2024 Project CHIP Authors
* All rights reserved.
*
* 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.
*/

/**
* @file DeviceCallbacks.cpp
*
* Implements all the callbacks to the application from the CHIP Stack
*
**/
#include "DeviceCallbacks.h"
#include <esp_log.h>

static const char TAG[] = "proximity-ranger-devicecallbacks";

using namespace ::chip;
using namespace ::chip::Inet;
using namespace ::chip::System;

void AppDeviceCallbacks::PostAttributeChangeCallback(EndpointId endpointId, ClusterId clusterId, AttributeId attributeId,
uint8_t type, uint16_t size, uint8_t * value)
{
ESP_LOGI(TAG, "PostAttributeChangeCallback - Cluster ID: '0x%" PRIx32 "', EndPoint ID: '0x%x', Attribute ID: '0x%" PRIx32 "'",
clusterId, endpointId, attributeId);

ESP_LOGI(TAG, "Current free heap: %d\n", heap_caps_get_free_size(MALLOC_CAP_8BIT));
}
56 changes: 56 additions & 0 deletions examples/proximity-ranger-app/esp32/main/Kconfig.projbuild
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#
# Copyright (c) 2024 Project CHIP Authors
# All rights reserved.
#
# 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.
#
# Description:
# Configuration options CHIP ESP32 demo application.
#

menu "Demo"

choice
prompt "Rendezvous Mode"
default RENDEZVOUS_MODE_BLE
help
Specifies the Rendezvous mode of the peripheral.

config RENDEZVOUS_MODE_WIFI
bool "Wi-Fi"
config RENDEZVOUS_MODE_BLE
bool "BLE"
config RENDEZVOUS_MODE_THREAD
bool "Thread"
config RENDEZVOUS_MODE_ETHERNET
bool "Ethernet"
endchoice

config RENDEZVOUS_MODE
int
range 0 8
default 1 if RENDEZVOUS_MODE_WIFI
default 2 if RENDEZVOUS_MODE_BLE
default 4 if RENDEZVOUS_MODE_THREAD
default 8 if RENDEZVOUS_MODE_ETHERNET

menu "Proximity Ranging Technology"
config PROXIMITY_RANGING_BLE_RSSI
bool "BLE RSSI"
default y
help
Enable BLE RSSI proximity ranging. Requires BLE to remain active
after commissioning (USE_BLE_ONLY_FOR_COMMISSIONING must be disabled).
endmenu

endmenu
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* Copyright (c) 2026 Project CHIP Authors
* All rights reserved.
*
* 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.
*/
#pragma once

#include <RangingAdapter.h>

using namespace ::chip::app::Clusters;

class BleRssiRangingAdapter : public ProximityRanging::RangingAdapter
{
public:
BleRssiRangingAdapter() = default;
~BleRssiRangingAdapter() override = default;

ProximityRanging::RangingTechEnum GetTechnology() const override
{
return ProximityRanging::RangingTechEnum::kBLEBeaconRSSIRanging;
}

ProximityRanging::Structs::RangingCapabilitiesStruct::Type GetCapabilities() const override
{
ProximityRanging::Structs::RangingCapabilitiesStruct::Type capabilities = {};
capabilities.technology = GetTechnology();
capabilities.frequencyBand = chip::BitMask<ProximityRanging::RadioBandBitmap>(ProximityRanging::RadioBandBitmap::k2g4);
capabilities.periodicRangingSupport = true;
return capabilities;
}

ProximityRanging::ResultCodeEnum StartSession(uint8_t sessionId,
const ProximityRanging::Commands::StartRangingRequest::DecodableType & request,
Callback & callback) override;
CHIP_ERROR StopSession(uint8_t sessionId) override;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
*
* Copyright (c) 2024 Project CHIP Authors
* All rights reserved.
*
* 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.
*/

#pragma once

#define CHIP_DEVICE_CONFIG_ENABLE_COMMISSIONER_DISCOVERY 0

#define CHIP_DEVICE_CONFIG_ENABLE_EXTENDED_DISCOVERY 1

#define CHIP_DEVICE_CONFIG_ENABLE_COMMISSIONABLE_DEVICE_TYPE 1

#define CHIP_DEVICE_CONFIG_DEVICE_TYPE 0x0152 // Proximity Ranger
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We used to hardcode these this way, but generally wondering if we should use generated constants instead of manual ones. This ID shows up as chip::app::Device::kProximityRangerDeviceTypeId in

https://github.com/project-chip/connectedhomeip/blob/master/zzz_generated/app-common/devices/Ids.h#L230


#define CHIP_DEVICE_CONFIG_ENABLE_COMMISSIONABLE_DEVICE_NAME 1

#define CHIP_DEVICE_CONFIG_DEVICE_NAME "Proximity Ranger"
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
*
* Copyright (c) 2024 Project CHIP Authors
* All rights reserved.
*
* 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.
*/

/**
* @file DeviceCallbacks.h
*
* Implementations for the DeviceManager callbacks for this application
*
**/

#ifndef DEVICE_CALLBACKS_H
#define DEVICE_CALLBACKS_H

#include <common/CHIPDeviceManager.h>
#include <common/CommonDeviceCallbacks.h>

class AppDeviceCallbacks : public CommonDeviceCallbacks
{
public:
virtual void PostAttributeChangeCallback(chip::EndpointId endpointId, chip::ClusterId clusterId, chip::AttributeId attributeId,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this callbacks class required for this example? All we seem to do is logging...

uint8_t type, uint16_t size, uint8_t * value);
};

#endif // DEVICE_CALLBACKS_H
Loading
Loading