mesh: update mesh libs

1. rename example internal_transceiver to internal_communication
2. bugfix
3. Closes https://github.com/espressif/esp-idf/issues/2014
This commit is contained in:
qiyueixa 2018-06-14 18:33:35 +08:00
parent 4e243fb1c1
commit 0dd750af1a
9 changed files with 52 additions and 74 deletions

View file

@ -936,7 +936,7 @@ bool esp_mesh_get_self_organized(void);
* be expected to find to replace the current one. * be expected to find to replace the current one.
* If no desired root candidate, the vote will try a specified attempts(at least 10 times), if no better * If no desired root candidate, the vote will try a specified attempts(at least 10 times), if no better
* root candidate is found, keep the current one. If a better candidate is found, the new better one will * root candidate is found, keep the current one. If a better candidate is found, the new better one will
* send a root switch request to the current root, current root will respond with a root switch acknowledgement. * send a root switch request to the current root, current root will respond with a root switch acknowledgment.
* After that, the new candidate will connect to the router to be a new root, the previous root will disconnect * After that, the new candidate will connect to the router to be a new root, the previous root will disconnect
* with the router and choose another parent instead. * with the router and choose another parent instead.
* So far, root switch is completed with minimal disruption to the whole mesh network. * So far, root switch is completed with minimal disruption to the whole mesh network.
@ -951,6 +951,8 @@ bool esp_mesh_get_self_organized(void);
* *
* @return * @return
* - ESP_OK * - ESP_OK
* - ESP_ERR_MESH_QUEUE_FULL
* - ESP_ERR_MESH_DISCARD
* - ESP_FAIL * - ESP_FAIL
*/ */
esp_err_t esp_mesh_waive_root(const mesh_vote_t *vote, int reason); esp_err_t esp_mesh_waive_root(const mesh_vote_t *vote, int reason);

@ -1 +1 @@
Subproject commit 166c7dca977dbde9a0703ef040012798bff53f57 Subproject commit e5f0e45e97e550444006b98f9617d2d5e138dbfb

View file

@ -3,7 +3,7 @@
# project subdirectory. # project subdirectory.
# #
PROJECT_NAME := internal_transceiver PROJECT_NAME := internal_communication
include $(IDF_PATH)/make/project.mk include $(IDF_PATH)/make/project.mk

View file

@ -1,4 +1,4 @@
# Mesh Internal Transceiver Example # Mesh Internal Communication Example
This example demonstrates how to use the mesh APIs to set up a mesh network, send and receive messages over the mesh network and etc. This example demonstrates how to use the mesh APIs to set up a mesh network, send and receive messages over the mesh network and etc.

View file

@ -1,4 +1,4 @@
/* Mesh Internal Transceiver Example /* Mesh Internal Communication Example
This example code is in the Public Domain (or CC0 licensed, at your option.) This example code is in the Public Domain (or CC0 licensed, at your option.)

View file

@ -1,4 +1,4 @@
/* Mesh Internal Transceiver Example /* Mesh Internal Communication Example
This example code is in the Public Domain (or CC0 licensed, at your option.) This example code is in the Public Domain (or CC0 licensed, at your option.)
@ -26,28 +26,34 @@
/******************************************************* /*******************************************************
* Variable Definitions * Variable Definitions
*******************************************************/ *******************************************************/
static bool bool_light_inited = false; static bool s_light_inited = false;
/******************************************************* /*******************************************************
* Function Definitions * Function Definitions
*******************************************************/ *******************************************************/
esp_err_t mesh_light_init(void) esp_err_t mesh_light_init(void)
{ {
if (bool_light_inited == true) { if (s_light_inited == true) {
return ESP_OK; return ESP_OK;
} }
bool_light_inited = true; s_light_inited = true;
ledc_timer_config_t ledc_timer = { ledc_timer_config_t ledc_timer = {
.bit_num = LEDC_TIMER_13_BIT, .freq_hz = 5000, .speed_mode = .bit_num = LEDC_TIMER_13_BIT,
LEDC_HIGH_SPEED_MODE, .timer_num = LEDC_TIMER_0 .freq_hz = 5000,
.speed_mode = LEDC_HIGH_SPEED_MODE,
.timer_num = LEDC_TIMER_0
}; };
ledc_timer_config(&ledc_timer); ledc_timer_config(&ledc_timer);
ledc_channel_config_t ledc_channel = { .channel = LEDC_CHANNEL_0, .duty = ledc_channel_config_t ledc_channel = {
100, .gpio_num = LEDC_IO_0, .intr_type = LEDC_INTR_FADE_END, .channel = LEDC_CHANNEL_0,
.speed_mode = LEDC_HIGH_SPEED_MODE, .timer_sel = LEDC_TIMER_0 .duty = 100,
}; .gpio_num = LEDC_IO_0,
.intr_type = LEDC_INTR_FADE_END,
.speed_mode = LEDC_HIGH_SPEED_MODE,
.timer_sel = LEDC_TIMER_0
};
ledc_channel_config(&ledc_channel); ledc_channel_config(&ledc_channel);
ledc_channel.channel = LEDC_CHANNEL_1; ledc_channel.channel = LEDC_CHANNEL_1;
ledc_channel.gpio_num = LEDC_IO_1; ledc_channel.gpio_num = LEDC_IO_1;

View file

@ -1,4 +1,4 @@
/* Mesh Internal Transceiver Example /* Mesh Internal Communication Example
This example code is in the Public Domain (or CC0 licensed, at your option.) This example code is in the Public Domain (or CC0 licensed, at your option.)
@ -20,7 +20,6 @@
* Macros * Macros
*******************************************************/ *******************************************************/
//#define MESH_P2P_TOS_OFF //#define MESH_P2P_TOS_OFF
//#define MESH_ROOT_TO_GROUP
/******************************************************* /*******************************************************
* Constants * Constants
@ -61,27 +60,6 @@ mesh_light_ctl_t light_off = {
/******************************************************* /*******************************************************
* Function Definitions * Function Definitions
*******************************************************/ *******************************************************/
void mesh_send_to_group(const mesh_data_t *data, const mesh_addr_t *group, int seqno)
{
esp_err_t err = esp_mesh_send(group, data,
MESH_DATA_P2P | MESH_DATA_GROUP,
NULL, 0);
if (err) {
ESP_LOGE(MESH_TAG,
"[GROUP:%d][L:%d][rtableSize:%d]parent:"MACSTR" to "MACSTR", heap:%d[err:0x%x, proto:%d, tos:%d]",
seqno, mesh_layer, esp_mesh_get_routing_table_size(),
MAC2STR(mesh_parent_addr.addr), MAC2STR(group->addr),
esp_get_free_heap_size(), err, data->proto, data->tos);
} else {
ESP_LOGW(MESH_TAG,
"[GROUP:%d][L:%d][rtableSize:%d]parent:"MACSTR" to "MACSTR", heap:%d[err:0x%x, proto:%d, tos:%d]",
seqno, mesh_layer, esp_mesh_get_routing_table_size(),
MAC2STR(mesh_parent_addr.addr), MAC2STR(group->addr),
esp_get_free_heap_size(), err, data->proto, data->tos);
}
}
void esp_mesh_p2p_tx_main(void *arg) void esp_mesh_p2p_tx_main(void *arg)
{ {
int i; int i;
@ -125,11 +103,6 @@ void esp_mesh_p2p_tx_main(void *arg)
memcpy(tx_buf, (uint8_t *)&light_off, sizeof(light_off)); memcpy(tx_buf, (uint8_t *)&light_off, sizeof(light_off));
} }
#ifdef MESH_ROOT_TO_GROUP
mesh_send_to_group(&data, (mesh_addr_t *)MESH_GROUP_ID, send_count);
vTaskDelay(1 * 1000 / portTICK_RATE_MS);
continue;
#endif
for (i = 0; i < route_table_size; i++) { for (i = 0; i < route_table_size; i++) {
err = esp_mesh_send(&route_table[i], &data, MESH_DATA_P2P, NULL, 0); err = esp_mesh_send(&route_table[i], &data, MESH_DATA_P2P, NULL, 0);
if (err) { if (err) {
@ -206,22 +179,21 @@ esp_err_t esp_mesh_comm_p2p_start(void)
return ESP_OK; return ESP_OK;
} }
void esp_mesh_event_handler(mesh_event_t event) void mesh_event_handler(mesh_event_t event)
{ {
#ifdef MESH_ROOT_TO_GROUP mesh_addr_t id = {0,};
mesh_addr_t group;
#endif
static uint8_t last_layer = 0; static uint8_t last_layer = 0;
ESP_LOGD(MESH_TAG, "esp_event_handler:%d", event.id); ESP_LOGD(MESH_TAG, "esp_event_handler:%d", event.id);
switch (event.id) { switch (event.id) {
case MESH_EVENT_STARTED: case MESH_EVENT_STARTED:
ESP_LOGI(MESH_TAG, "<MESH_EVENT_STARTED>heap:%d", esp_get_free_heap_size()); esp_mesh_get_id(&id);
ESP_LOGI(MESH_TAG, "<MESH_EVENT_STARTED>ID:"MACSTR"", MAC2STR(id.addr));
is_mesh_connected = false; is_mesh_connected = false;
mesh_layer = esp_mesh_get_layer(); mesh_layer = esp_mesh_get_layer();
break; break;
case MESH_EVENT_STOPPED: case MESH_EVENT_STOPPED:
ESP_LOGI(MESH_TAG, "<MESH_EVENT_STOPPED>heap:%d", esp_get_free_heap_size()); ESP_LOGI(MESH_TAG, "<MESH_EVENT_STOPPED>");
is_mesh_connected = false; is_mesh_connected = false;
mesh_layer = esp_mesh_get_layer(); mesh_layer = esp_mesh_get_layer();
break; break;
@ -251,28 +223,20 @@ void esp_mesh_event_handler(mesh_event_t event)
/* TODO handler for the failure */ /* TODO handler for the failure */
break; break;
case MESH_EVENT_PARENT_CONNECTED: case MESH_EVENT_PARENT_CONNECTED:
esp_mesh_get_id(&id);
mesh_layer = event.info.connected.self_layer; mesh_layer = event.info.connected.self_layer;
memcpy(&mesh_parent_addr.addr, event.info.connected.connected.bssid, 6); memcpy(&mesh_parent_addr.addr, event.info.connected.connected.bssid, 6);
ESP_LOGI(MESH_TAG, ESP_LOGI(MESH_TAG,
"<MESH_EVENT_PARENT_CONNECTED>layer:%d-->%d, parent:"MACSTR"%s", "<MESH_EVENT_PARENT_CONNECTED>layer:%d-->%d, parent:"MACSTR"%s, ID:"MACSTR"",
last_layer, mesh_layer, MAC2STR(mesh_parent_addr.addr), last_layer, mesh_layer, MAC2STR(mesh_parent_addr.addr),
esp_mesh_is_root() ? "<ROOT>" : esp_mesh_is_root() ? "<ROOT>" :
(mesh_layer == 2) ? "<layer2>" : ""); (mesh_layer == 2) ? "<layer2>" : "", MAC2STR(id.addr));
last_layer = mesh_layer; last_layer = mesh_layer;
mesh_connected_indicator(mesh_layer); mesh_connected_indicator(mesh_layer);
is_mesh_connected = true; is_mesh_connected = true;
if (esp_mesh_is_root()) { if (esp_mesh_is_root()) {
tcpip_adapter_dhcpc_start(TCPIP_ADAPTER_IF_STA); tcpip_adapter_dhcpc_start(TCPIP_ADAPTER_IF_STA);
} }
#ifdef MESH_ROOT_TO_GROUP
if (mesh_layer == 3) {
ESP_ERROR_CHECK(
esp_mesh_set_group_id((mesh_addr_t * ) MESH_GROUP_ID, 1))
ESP_ERROR_CHECK(esp_mesh_get_group_list(&group, 1))
ESP_LOGI(MESH_TAG, "num:%d, group "MACSTR"\n",
esp_mesh_get_group_num(), MAC2STR(group.addr));
}
#endif
esp_mesh_comm_p2p_start(); esp_mesh_comm_p2p_start();
break; break;
case MESH_EVENT_PARENT_DISCONNECTED: case MESH_EVENT_PARENT_DISCONNECTED:
@ -281,6 +245,7 @@ void esp_mesh_event_handler(mesh_event_t event)
event.info.disconnected.reason); event.info.disconnected.reason);
is_mesh_connected = false; is_mesh_connected = false;
mesh_disconnected_indicator(); mesh_disconnected_indicator();
mesh_layer = esp_mesh_get_layer();
break; break;
case MESH_EVENT_LAYER_CHANGE: case MESH_EVENT_LAYER_CHANGE:
mesh_layer = event.info.layer_change.new_layer; mesh_layer = event.info.layer_change.new_layer;
@ -328,7 +293,6 @@ void esp_mesh_event_handler(mesh_event_t event)
esp_mesh_get_parent_bssid(&mesh_parent_addr); esp_mesh_get_parent_bssid(&mesh_parent_addr);
ESP_LOGI(MESH_TAG, "<MESH_EVENT_ROOT_SWITCH_ACK>layer:%d, parent:"MACSTR"", mesh_layer, MAC2STR(mesh_parent_addr.addr)); ESP_LOGI(MESH_TAG, "<MESH_EVENT_ROOT_SWITCH_ACK>layer:%d, parent:"MACSTR"", mesh_layer, MAC2STR(mesh_parent_addr.addr));
break; break;
case MESH_EVENT_TODS_STATE: case MESH_EVENT_TODS_STATE:
ESP_LOGI(MESH_TAG, "<MESH_EVENT_TODS_REACHABLE>state:%d", ESP_LOGI(MESH_TAG, "<MESH_EVENT_TODS_REACHABLE>state:%d",
event.info.toDS_state); event.info.toDS_state);
@ -337,6 +301,20 @@ void esp_mesh_event_handler(mesh_event_t event)
ESP_LOGI(MESH_TAG, "<MESH_EVENT_ROOT_FIXED>%s", ESP_LOGI(MESH_TAG, "<MESH_EVENT_ROOT_FIXED>%s",
event.info.root_fixed.is_fixed ? "fixed" : "not fixed"); event.info.root_fixed.is_fixed ? "fixed" : "not fixed");
break; break;
case MESH_EVENT_ROOT_ASKED_YIELD:
ESP_LOGI(MESH_TAG,
"<MESH_EVENT_ROOT_ASKED_YIELD>"MACSTR", rssi:%d, capacity:%d",
MAC2STR(event.info.root_conflict.addr),
event.info.root_conflict.rssi,
event.info.root_conflict.capacity);
break;
case MESH_EVENT_CHANNEL_SWITCH:
ESP_LOGI(MESH_TAG, "<MESH_EVENT_CHANNEL_SWITCH>");
break;
case MESH_EVENT_SCAN_DONE:
ESP_LOGI(MESH_TAG, "<MESH_EVENT_SCAN_DONE>number:%d",
event.info.scan_done.number);
break;
default: default:
ESP_LOGI(MESH_TAG, "unknown id:%d", event.id); ESP_LOGI(MESH_TAG, "unknown id:%d", event.id);
break; break;
@ -382,7 +360,7 @@ void app_main(void)
/* mesh ID */ /* mesh ID */
memcpy((uint8_t *) &cfg.mesh_id, MESH_ID, 6); memcpy((uint8_t *) &cfg.mesh_id, MESH_ID, 6);
/* mesh event callback */ /* mesh event callback */
cfg.event_cb = &esp_mesh_event_handler; cfg.event_cb = &mesh_event_handler;
/* router */ /* router */
cfg.channel = CONFIG_MESH_CHANNEL; cfg.channel = CONFIG_MESH_CHANNEL;
cfg.router.ssid_len = strlen(CONFIG_MESH_ROUTER_SSID); cfg.router.ssid_len = strlen(CONFIG_MESH_ROUTER_SSID);
@ -397,19 +375,11 @@ void app_main(void)
/* set RSSI threshold for connecting to the root */ /* set RSSI threshold for connecting to the root */
mesh_switch_parent_t switch_paras ; mesh_switch_parent_t switch_paras ;
ESP_ERROR_CHECK(esp_mesh_get_switch_parent_paras(&switch_paras)); ESP_ERROR_CHECK(esp_mesh_get_switch_parent_paras(&switch_paras));
switch_paras.backoff_rssi = -45; switch_paras.select_rssi = -55;
switch_paras.cnx_rssi = -65;
switch_paras.duration_ms = 120 * 1000;
switch_paras.switch_rssi = -65;
ESP_ERROR_CHECK(esp_mesh_set_switch_parent_paras(&switch_paras)); ESP_ERROR_CHECK(esp_mesh_set_switch_parent_paras(&switch_paras));
#ifdef MESH_SET_PARENT
/* parent */
wifi_config_t parent = {
.sta = {
.ssid = CONFIG_MESH_PARENT_SSID,
.channel = CONFIG_MESH_CHANNEL,
},
};
ESP_ERROR_CHECK(esp_mesh_set_parent(&parent, MESH_ROOT, 1));
#endif
/* mesh start */ /* mesh start */
ESP_ERROR_CHECK(esp_mesh_start()); ESP_ERROR_CHECK(esp_mesh_start());
ESP_LOGI(MESH_TAG, "mesh starts successfully, heap:%d, %s\n", esp_get_free_heap_size(), ESP_LOGI(MESH_TAG, "mesh starts successfully, heap:%d, %s\n", esp_get_free_heap_size(),