mirror of
https://github.com/espressif/esp-matter.git
synced 2026-04-27 19:13:13 +00:00
ESP32 as a ble controller
This commit is contained in:
@@ -29,6 +29,11 @@
|
|||||||
#include <platform/DeviceInstanceInfoProvider.h>
|
#include <platform/DeviceInstanceInfoProvider.h>
|
||||||
#include <platform/DiagnosticDataProvider.h>
|
#include <platform/DiagnosticDataProvider.h>
|
||||||
|
|
||||||
|
#if CONFIG_ENABLE_ESP32_BLE_CONTROLLER
|
||||||
|
#include <platform/internal/BLEManager.h>
|
||||||
|
#include <platform/ESP32/BLEManagerImpl.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
using namespace chip;
|
using namespace chip;
|
||||||
using namespace chip::Credentials;
|
using namespace chip::Credentials;
|
||||||
using namespace chip::DeviceLayer;
|
using namespace chip::DeviceLayer;
|
||||||
@@ -92,6 +97,16 @@ namespace esp_matter {
|
|||||||
namespace commissioner {
|
namespace commissioner {
|
||||||
esp_err_t init(uint16_t commissioner_port)
|
esp_err_t init(uint16_t commissioner_port)
|
||||||
{
|
{
|
||||||
|
#if CONFIG_ENABLE_ESP32_BLE_CONTROLLER
|
||||||
|
CHIP_ERROR err = chip::DeviceLayer::Internal::BLEMgr().Init();
|
||||||
|
err = chip::DeviceLayer::Internal::BLEMgrImpl().ConfigureBle(0, true);
|
||||||
|
|
||||||
|
if (err != CHIP_NO_ERROR) {
|
||||||
|
ChipLogError(DeviceLayer, "BLEManager initialization failed: %s", ErrorStr(err));
|
||||||
|
return ESP_FAIL;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
Controller::FactoryInitParams factoryParams;
|
Controller::FactoryInitParams factoryParams;
|
||||||
Controller::SetupParams setupParams;
|
Controller::SetupParams setupParams;
|
||||||
|
|
||||||
|
|||||||
@@ -68,7 +68,34 @@ static esp_err_t controller_pairing_handler(int argc, char **argv)
|
|||||||
uint32_t pincode = string_to_uint32(argv[2]);
|
uint32_t pincode = string_to_uint32(argv[2]);
|
||||||
return controller::pairing_on_network(nodeId, pincode);
|
return controller::pairing_on_network(nodeId, pincode);
|
||||||
} else if (strncmp(argv[0], "ble-wifi", sizeof("ble-wifi")) == 0) {
|
} else if (strncmp(argv[0], "ble-wifi", sizeof("ble-wifi")) == 0) {
|
||||||
|
#if CONFIG_ENABLE_ESP32_BLE_CONTROLLER
|
||||||
|
if (argc != 6) {
|
||||||
|
return ESP_ERR_INVALID_ARG;
|
||||||
|
}
|
||||||
|
|
||||||
|
char *ssid = NULL, *pwd = NULL;
|
||||||
|
|
||||||
|
ssid = strndup(argv[2], strlen(argv[2]) + 1);
|
||||||
|
pwd = strndup(argv[3], strlen(argv[3]) + 1);
|
||||||
|
if (ssid == NULL || pwd == NULL) {
|
||||||
|
return ESP_ERR_NO_MEM;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint64_t nodeId = string_to_uint64(argv[1]);
|
||||||
|
uint32_t pincode = string_to_uint32(argv[4]);
|
||||||
|
uint16_t disc = string_to_uint16(argv[5]);
|
||||||
|
|
||||||
|
esp_err_t result = controller::pairing_ble_wifi(nodeId, pincode, disc, ssid, pwd);
|
||||||
|
if (result != ESP_OK) {
|
||||||
|
ESP_LOGE(TAG, "Pairing over ble failed");
|
||||||
|
}
|
||||||
|
if (ssid != NULL) free(ssid);
|
||||||
|
if (pwd != NULL) free(pwd);
|
||||||
|
|
||||||
|
return result;
|
||||||
|
#else
|
||||||
return ESP_ERR_NOT_SUPPORTED;
|
return ESP_ERR_NOT_SUPPORTED;
|
||||||
|
#endif
|
||||||
} else if (strncmp(argv[0], "ble-thread", sizeof("ble-thread")) == 0) {
|
} else if (strncmp(argv[0], "ble-thread", sizeof("ble-thread")) == 0) {
|
||||||
return ESP_ERR_NOT_SUPPORTED;
|
return ESP_ERR_NOT_SUPPORTED;
|
||||||
}
|
}
|
||||||
@@ -259,8 +286,8 @@ esp_err_t controller_register_commands()
|
|||||||
{
|
{
|
||||||
.name = "pairing",
|
.name = "pairing",
|
||||||
.description = "Pairing a node.\n"
|
.description = "Pairing a node.\n"
|
||||||
"\tUsage: controller pairing onnetwork [nodeid] [pincode] Or\n"
|
"\tUsage: controller pairing onnetwork [nodeid] [pincode] OR\n"
|
||||||
"\tcontroller pairing ble-wifi [nodeid] [pincode] [discriminator] [ssid] [password] Or\n"
|
"\tcontroller pairing ble-wifi [nodeid] [pincode] [ssid] [password] [discriminator] OR\n"
|
||||||
"\tcontroller pairing ble-thread [nodeid] [pincode] [discriminator] [dataset]",
|
"\tcontroller pairing ble-thread [nodeid] [pincode] [discriminator] [dataset]",
|
||||||
.handler = controller_pairing_handler,
|
.handler = controller_pairing_handler,
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -143,5 +143,18 @@ esp_err_t pairing_on_network(NodeId node_id, uint32_t pincode)
|
|||||||
}
|
}
|
||||||
return ESP_OK;
|
return ESP_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if CONFIG_ENABLE_ESP32_BLE_CONTROLLER
|
||||||
|
esp_err_t pairing_ble_wifi(NodeId node_id, uint32_t pincode, uint16_t disc, const char * ssid, const char * pwd)
|
||||||
|
{
|
||||||
|
RendezvousParameters params = RendezvousParameters().SetSetupPINCode(pincode).SetDiscriminator(disc).SetPeerAddress(chip::Transport::PeerAddress::BLE());
|
||||||
|
|
||||||
|
chip::ByteSpan nameSpan(reinterpret_cast<const uint8_t *>(ssid),strlen(ssid));
|
||||||
|
chip::ByteSpan pwdSpan(reinterpret_cast<const uint8_t *>(pwd),strlen(pwd));
|
||||||
|
CommissioningParameters commissioning_params = CommissioningParameters().SetWiFiCredentials(Controller::WiFiCredentials(nameSpan, pwdSpan));
|
||||||
|
get_device_commissioner()->PairDevice(node_id, params, commissioning_params);
|
||||||
|
return ESP_OK;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
} // namespace controller
|
} // namespace controller
|
||||||
} // namespace esp_matter
|
} // namespace esp_matter
|
||||||
|
|||||||
@@ -80,6 +80,9 @@ private:
|
|||||||
};
|
};
|
||||||
|
|
||||||
esp_err_t pairing_on_network(NodeId node_id, uint32_t pincode);
|
esp_err_t pairing_on_network(NodeId node_id, uint32_t pincode);
|
||||||
|
#if CONFIG_ENABLE_ESP32_BLE_CONTROLLER
|
||||||
|
esp_err_t pairing_ble_wifi(NodeId node_id, uint32_t pincode, uint16_t disc, const char * ssid, const char * pwd);
|
||||||
|
#endif
|
||||||
|
|
||||||
} // namespace controller
|
} // namespace controller
|
||||||
} // namespace esp_matter
|
} // namespace esp_matter
|
||||||
|
|||||||
Submodule connectedhomeip/connectedhomeip updated: 6382144be8...c95efa996d
@@ -49,3 +49,6 @@ CONFIG_MBEDTLS_HKDF_C=y
|
|||||||
# Increase LwIP IPv6 address number to 6 (MAX_FABRIC + 1)
|
# Increase LwIP IPv6 address number to 6 (MAX_FABRIC + 1)
|
||||||
# unique local addresses for fabrics(MAX_FABRIC), a link local address(1)
|
# unique local addresses for fabrics(MAX_FABRIC), a link local address(1)
|
||||||
CONFIG_LWIP_IPV6_NUM_ADDRESSES=6
|
CONFIG_LWIP_IPV6_NUM_ADDRESSES=6
|
||||||
|
|
||||||
|
# Enable ble controller
|
||||||
|
CONFIG_ENABLE_ESP32_BLE_CONTROLLER=y
|
||||||
|
|||||||
Reference in New Issue
Block a user