mirror of
https://github.com/espressif/esp-idf.git
synced 2025-07-31 19:24:33 +02:00
openthread: add openthread autostart for sleep device
This commit is contained in:
@@ -40,7 +40,7 @@ extern "C" {
|
||||
#define REGDMA_IOMUX_LINK(_pri) ((0x12 << 8) | _pri)
|
||||
#define REGDMA_SPIMEM_LINK(_pri) ((0x13 << 8) | _pri)
|
||||
#define REGDMA_SYSTIMER_LINK(_pri) ((0x14 << 8) | _pri)
|
||||
#define REGDMA_MODEM_BT_BB_LINK(_pri) ((0x15 << 8) | _pri)
|
||||
#define REGDMA_MODEM_BT_BB_LINK(_pri) ((0x15 << 8) | _pri)
|
||||
#define REGDMA_MODEM_IEEE802154_LINK(_pri) ((0x16 << 8) | _pri)
|
||||
#define REGDMA_MODEM_FE_LINK(_pri) ((0xFF << 8) | _pri)
|
||||
|
||||
|
@@ -16,7 +16,7 @@ The example demonstrates the Thread Sleepy End Device (SED), the device will ent
|
||||
## Configure the Openthread Dataset
|
||||
|
||||
* Run [ot_cli](../ot_cli/) on another ESP32-C6 device to create openthread dataset configuration and start an openthread network as the leader.
|
||||
* Configure the Openthread dataset (`CONFIG_OPENTHREAD_NETWORK_DATASET`) in [ot_power_save](../ot_power_save/main/esp_ot_power_save_config.h), ensuring that the device's dataset matches the dataset of the leader.
|
||||
* Configure the Openthread dataset using `idf.py menuconfig` in `Component config ---> Openthread ---> Thread Operation Dataset`, ensuring that the openthread sleepy device's dataset matches the dataset of the leader.
|
||||
|
||||
## Erase the ot_storage
|
||||
|
||||
|
@@ -39,46 +39,9 @@
|
||||
|
||||
#define TAG "ot_esp_power_save"
|
||||
|
||||
static int hex_digit_to_int(char hex)
|
||||
{
|
||||
if ('A' <= hex && hex <= 'F') {
|
||||
return 10 + hex - 'A';
|
||||
}
|
||||
if ('a' <= hex && hex <= 'f') {
|
||||
return 10 + hex - 'a';
|
||||
}
|
||||
if ('0' <= hex && hex <= '9') {
|
||||
return hex - '0';
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
static size_t hex_string_to_binary(const char *hex_string, uint8_t *buf)
|
||||
{
|
||||
int num_char = strlen(hex_string);
|
||||
|
||||
if (num_char % 2 == true) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < num_char; i += 2) {
|
||||
int digit0 = hex_digit_to_int(hex_string[i]);
|
||||
int digit1 = hex_digit_to_int(hex_string[i + 1]);
|
||||
|
||||
if (digit0 < 0 || digit1 < 0) {
|
||||
return 0;
|
||||
}
|
||||
buf[i / 2] = (digit0 << 4) + digit1;
|
||||
}
|
||||
|
||||
return num_char/2;
|
||||
}
|
||||
|
||||
static void create_config_network(otInstance *instance)
|
||||
{
|
||||
otLinkModeConfig linkMode;
|
||||
uint16_t dataset_str_len = strlen(CONFIG_OPENTHREAD_NETWORK_DATASET);
|
||||
otOperationalDatasetTlvs datasetTlvs;
|
||||
memset(&linkMode, 0, sizeof(otLinkModeConfig));
|
||||
|
||||
linkMode.mRxOnWhenIdle = false;
|
||||
@@ -94,33 +57,7 @@ static void create_config_network(otInstance *instance)
|
||||
ESP_LOGE(TAG, "Failed to set OpenThread linkmode.");
|
||||
abort();
|
||||
}
|
||||
|
||||
if (dataset_str_len > (OT_OPERATIONAL_DATASET_MAX_LENGTH * 2)) {
|
||||
ESP_LOGE(TAG, "dataset length error.");
|
||||
abort();
|
||||
}
|
||||
|
||||
datasetTlvs.mLength = hex_string_to_binary(CONFIG_OPENTHREAD_NETWORK_DATASET, datasetTlvs.mTlvs);
|
||||
|
||||
if (!datasetTlvs.mLength) {
|
||||
ESP_LOGE(TAG, "Failed convert configured dataset");
|
||||
abort();
|
||||
}
|
||||
|
||||
if (otDatasetSetActiveTlvs(instance, &datasetTlvs) != OT_ERROR_NONE) {
|
||||
ESP_LOGE(TAG, "Failed to set OpenThread otDatasetSetActiveTlvs.");
|
||||
abort();
|
||||
}
|
||||
|
||||
if(otIp6SetEnabled(instance, true) != OT_ERROR_NONE) {
|
||||
ESP_LOGE(TAG, "Failed to enable OpenThread IP6 link");
|
||||
abort();
|
||||
}
|
||||
|
||||
if(otThreadSetEnabled(instance, true) != OT_ERROR_NONE) {
|
||||
ESP_LOGE(TAG, "Failed to enable OpenThread");
|
||||
abort();
|
||||
}
|
||||
ESP_ERROR_CHECK(esp_openthread_auto_start(NULL));
|
||||
}
|
||||
|
||||
static esp_netif_t *init_openthread_netif(const esp_openthread_platform_config_t *config)
|
||||
|
@@ -16,7 +16,6 @@
|
||||
|
||||
#include "esp_openthread_types.h"
|
||||
|
||||
# define CONFIG_OPENTHREAD_NETWORK_DATASET "0e080000000000010000000300000b35060004001fffe002084c14b4d26855fcd00708fdf7e918eb62e2a905107ca0e75a6ead4b960cfe073386943605030f4f70656e5468726561642d616631360102af1604102b9084b26c9a7d10a1a729bfc2e84ea00c0402a0f7f8"
|
||||
# define CONFIG_OPENTHREAD_NETWORK_POLLPERIOD_TIME 3000
|
||||
|
||||
#if SOC_IEEE802154_SUPPORTED
|
||||
|
Reference in New Issue
Block a user