#define ESP_ERR_MESH_INTERFACE (ESP_ERR_MESH_BASE + 19) /**< low-level WiFi interface error */
#define ESP_ERR_MESH_DISCARD_DUPLICATE (ESP_ERR_MESH_BASE + 20) /**< discard the packet due to the duplicate sequence number */
#define ESP_ERR_MESH_DISCARD (ESP_ERR_MESH_BASE + 21) /**< discard the packet */
+#define ESP_ERR_MESH_VOTING (ESP_ERR_MESH_BASE + 22) /**< vote in progress */
/**
* @brief flags used with esp_mesh_send() and esp_mesh_recv()
/**
* @brief option definitions for esp_mesh_send() and esp_mesh_recv()
*/
-#define MESH_OPT_SEND_GROUP (7) /**< data transmission by group; used with esp_mesh_send() and must have payload */
+#define MESH_OPT_SEND_GROUP (7) /**< data transmission by group; used with esp_mesh_send() and shall have payload */
#define MESH_OPT_RECV_DS_ADDR (8) /**< return a remote IP address; used with esp_mesh_send() and esp_mesh_recv() */
/*******************************************************
} mesh_cfg_t;
/**
- * @brief vote
+ * @brief vote address configuration
*/
typedef union {
- int attempts; /**< max vote attempts */
- mesh_addr_t rc_addr; /**< root address specified by users for API esp_mesh_waive_root() */
+ int attempts; /**< max vote attempts before a new root is elected automatically by mesh network. (min:15, 15 by default) */
+ mesh_addr_t rc_addr; /**< a new root address specified by users for API esp_mesh_waive_root() */
+} mesh_rc_config_t;
+
+/**
+ * @brief vote
+ */
+typedef struct {
+ float percentage; /**< vote percentage threshold for approval of being a root */
+ bool is_rc_specified; /**< if true, rc_addr shall be specified(Unimplemented).
+ if false, attempts value shall be specified to make network start root election. */
+ mesh_rc_config_t config; /**< vote address configuration */
} mesh_vote_t;
/**
/**
* @brief set group ID addresses
*
- * @param addr pointer to new addresses
- * @param num number of addresses
+ * @param addr pointer to new group ID addresses
+ * @param num the number of group ID addresses
*
* @return
* - ESP_OK
/**
* @brief delete group ID addresses
*
- * @param addr pointer to deleted address
- * @param num number of addresses
+ * @param addr pointer to deleted group ID address
+ * @param num the number of group ID addresses
*
* @return
* - ESP_OK
/**
* @brief get group ID addresses
*
- * @param addr pointer to group address
- * @param num number of addresses
+ * @param addr pointer to group ID addresses
+ * @param num the number of group ID addresses
*
* @return
* - ESP_OK
/**
* @brief set mesh ie crypto key
*
- * @attention This API should be called before esp_mesh_start().
+ * @attention This API should be called after esp_mesh_set_config() and before esp_mesh_start().
*
- * @param key crypto key
- * @param len the present implementation only supports 32
+ * @param key ASCII crypto key
+ * @param len length in bytes, range:8~64
*
* @return
* - ESP_OK
* - ESP_ERR_MESH_NOT_ALLOWED
+ * - ESP_ERR_MESH_NOT_CONFIG
* - ESP_MESH_ERR_ARGUMENT
*/
-esp_err_t esp_mesh_set_ie_crypto_key(const uint8_t *key, int len);
+esp_err_t esp_mesh_set_ie_crypto_key(const char *key, int len);
/**
* @brief get mesh ie crypto key
*
- * @param key crypto key
- * @param len the present implementation only supports 32
+ * @param key ASCII crypto key
+ * @param len length in bytes, range:8~64
*
* @return
* - ESP_OK
* - ESP_MESH_ERR_ARGUMENT
*/
-esp_err_t esp_mesh_get_ie_crypto_key(uint8_t *key, int len);
+esp_err_t esp_mesh_get_ie_crypto_key(char *key, int len);
/**
* @brief set delay time before starting root healing
/**
* @brief set Root Fixed setting for nodes
* If Root Fixed setting of nodes is enabled, they won't compete to be a root.
- * If a scenario needs a fixed root, all nodes in this network must enable this setting.
+ * If a scenario needs a fixed root, all nodes in this network shall enable this setting.
*
* @param enable enable or not
*
is_running = true;
while (is_running) {
- /* normal nodes rather than root do nothing but print */
+ /* non-root do nothing but print */
if (!esp_mesh_is_root()) {
- ESP_LOGI(MESH_TAG, "layer:%d, rtableSize:%d, %s%s", mesh_layer,
+ ESP_LOGI(MESH_TAG, "layer:%d, rtableSize:%d, %s", mesh_layer,
esp_mesh_get_routing_table_size(),
- is_mesh_connected ? "CONNECT" : "DISCONNECT",
- esp_mesh_is_root() ? "<ROOT>" : "[NODE]");
+ (is_mesh_connected && esp_mesh_is_root()) ? "ROOT" : is_mesh_connected ? "NODE" : "DISCONNECT");
vTaskDelay(10 * 1000 / portTICK_RATE_MS);
continue;
}
mesh_addr_t group;
#endif
static uint8_t last_layer = 0;
- static int disconnect_count = 0;
ESP_LOGD(MESH_TAG, "esp_event_handler:%d", event.id);
switch (event.id) {
case MESH_EVENT_STARTED:
- ESP_LOGI(MESH_TAG, "<MESH_EVENT_STARTED>");
+ ESP_LOGI(MESH_TAG, "<MESH_EVENT_STARTED>heap:%d", esp_get_free_heap_size());
+ is_mesh_connected = false;
+ mesh_layer = esp_mesh_get_layer();
break;
case MESH_EVENT_STOPPED:
- ESP_LOGI(MESH_TAG, "<MESH_EVENT_STOPPED>");
+ ESP_LOGI(MESH_TAG, "<MESH_EVENT_STOPPED>heap:%d", esp_get_free_heap_size());
+ is_mesh_connected = false;
+ mesh_layer = esp_mesh_get_layer();
break;
case MESH_EVENT_CHILD_CONNECTED:
ESP_LOGI(MESH_TAG, "<MESH_EVENT_CHILD_CONNECTED>aid:%d, "MACSTR"",
event.info.routing_table.rt_size_change,
event.info.routing_table.rt_size_new);
break;
-
case MESH_EVENT_ROUTING_TABLE_REMOVE:
ESP_LOGW(MESH_TAG, "<MESH_EVENT_ROUTING_TABLE_REMOVE>remove %d, new:%d",
event.info.routing_table.rt_size_change,
event.info.routing_table.rt_size_new);
break;
-
case MESH_EVENT_NO_PARNET_FOUND:
ESP_LOGI(MESH_TAG, "<MESH_EVENT_NO_PARNET_FOUND>scan times:%d",
event.info.no_parent.scan_times);
/* TODO handler for the failure */
break;
-
case MESH_EVENT_PARENT_CONNECTED:
mesh_layer = event.info.connected.self_layer;
memcpy(&mesh_parent_addr.addr, event.info.connected.connected.bssid, 6);
ESP_LOGI(MESH_TAG,
- "<MESH_EVENT_PARENT_CONNECTED>layer:%d-->%d, parent:"MACSTR"%s, discnx:%d",
+ "<MESH_EVENT_PARENT_CONNECTED>layer:%d-->%d, parent:"MACSTR"%s",
last_layer, mesh_layer, MAC2STR(mesh_parent_addr.addr),
esp_mesh_is_root() ? "<ROOT>" :
- (mesh_layer == 2) ? "<layer2>" : "", disconnect_count);
- disconnect_count = 0;
+ (mesh_layer == 2) ? "<layer2>" : "");
last_layer = mesh_layer;
mesh_connected_indicator(mesh_layer);
is_mesh_connected = true;
#endif
esp_mesh_comm_p2p_start();
break;
-
case MESH_EVENT_PARENT_DISCONNECTED:
ESP_LOGI(MESH_TAG,
- "<MESH_EVENT_PARENT_DISCONNECTED>reason:%d, count:%d",
- event.info.disconnected.reason, disconnect_count);
- if (event.info.disconnected.reason == 201) {
- disconnect_count++;
- }
+ "<MESH_EVENT_PARENT_DISCONNECTED>reason:%d",
+ event.info.disconnected.reason);
is_mesh_connected = false;
mesh_disconnected_indicator();
break;
-
case MESH_EVENT_LAYER_CHANGE:
mesh_layer = event.info.layer_change.new_layer;
ESP_LOGI(MESH_TAG, "<MESH_EVENT_LAYER_CHANGE>layer:%d-->%d%s",
last_layer = mesh_layer;
mesh_connected_indicator(mesh_layer);
break;
-
case MESH_EVENT_ROOT_ADDRESS:
- ESP_LOGI(MESH_TAG, "<MESH_EVENT_ROOT_ADDRESS>rc_addr:"MACSTR"",
+ ESP_LOGI(MESH_TAG, "<MESH_EVENT_ROOT_ADDRESS>root address:"MACSTR"",
MAC2STR(event.info.root_addr.addr));
break;
-
case MESH_EVENT_ROOT_GOT_IP:
/* root starts to connect to server */
ESP_LOGI(MESH_TAG,
IP2STR(&event.info.got_ip.ip_info.netmask),
IP2STR(&event.info.got_ip.ip_info.gw));
break;
-
case MESH_EVENT_ROOT_LOST_IP:
ESP_LOGI(MESH_TAG, "<MESH_EVENT_ROOT_LOST_IP>");
break;
-
case MESH_EVENT_VOTE_STARTED:
ESP_LOGI(MESH_TAG,
"<MESH_EVENT_VOTE_STARTED>attempts:%d, reason:%d, rc_addr:"MACSTR"",
event.info.vote_started.reason,
MAC2STR(event.info.vote_started.rc_addr.addr));
break;
-
case MESH_EVENT_VOTE_STOPPED:
- ESP_LOGI(MESH_TAG, "<MESH_EVENT_VOTE_DONE>");
+ ESP_LOGI(MESH_TAG, "<MESH_EVENT_VOTE_STOPPED>");
break;
-
case MESH_EVENT_ROOT_SWITCH_REQ:
ESP_LOGI(MESH_TAG,
"<MESH_EVENT_ROOT_SWITCH_REQ>reason:%d, rc_addr:"MACSTR"",
event.info.switch_req.reason,
MAC2STR( event.info.switch_req.rc_addr.addr));
break;
-
case MESH_EVENT_ROOT_SWITCH_ACK:
- ESP_LOGI(MESH_TAG, "<MESH_EVENT_ROOT_SWITCH_ACK>");
+ /* new root */
+ mesh_layer = esp_mesh_get_layer();
+ 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));
break;
case MESH_EVENT_TODS_STATE:
ESP_LOGI(MESH_TAG, "<MESH_EVENT_TODS_REACHABLE>state:%d",
event.info.toDS_state);
break;
-
case MESH_EVENT_ROOT_FIXED:
ESP_LOGI(MESH_TAG, "<MESH_EVENT_ROOT_FIXED>%s",
event.info.root_fixed.is_fixed ? "fixed" : "not fixed");
break;
-
default:
- ESP_LOGI(MESH_TAG, "unknown");
+ ESP_LOGI(MESH_TAG, "unknown id:%d", event.id);
break;
}
}