and this device is specified to be a root by users, users should set a new parent
for this device. if self organized is enabled, this device will find a new parent
by itself, users could ignore this event. */
+ MESH_EVENT_ROOT_FIXED, /**< When nodes join a network, if the setting of Root Fixed for one node is different
+ from that of its parent, the node will update the setting the same as its parent's.
+ Root Fixed setting of each node is variable as that setting changes of root. */
MESH_EVENT_MAX,
} mesh_event_id_t;
uint16_t rt_size_change; /**< the changed value */
} mesh_event_routing_table_change_t;
+/**
+ * @brief root fixed
+ */
+typedef struct {
+ bool is_fixed; /**< status */
+} mesh_event_root_fixed_t;
+
/**
* @brief mesh event information
*/
mesh_event_root_address_t root_addr; /**< root address */
mesh_event_root_switch_req_t switch_req; /**< root switch request */
mesh_event_root_conflict_t root_conflict; /**< other powerful root */
+ mesh_event_root_fixed_t root_fixed; /**< root fixed */
} mesh_event_info_t;
/**
/**
* @brief enable/disable mesh networking self-organized, self-organized by default
* if self-organized is disabled, users should set a parent for this node via
- * esp_mesh_set_parent()(Unimplemented);
+ * esp_mesh_set_parent();
*
* @param enable
*
*/
esp_err_t esp_mesh_allow_root_conflicts(const bool allowed);
+/**
+ * @brief check if allow more than one root to exist in one network
+ *
+ * @return true/false
+ */
+bool esp_mesh_is_root_conflicts_allowed(void);
+
/**
* @brief set group ID addresses
*
*/
esp_err_t esp_mesh_set_event_cb(const mesh_event_cb_t event_cb);
+/**
+ * @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.
+ *
+ * @param enable enable or not
+ *
+ * @return
+ * - ESP_OK
+ */
+esp_err_t esp_mesh_fix_root(const bool enable);
+
+/**
+ * @brief check if Root Fixed setting is enabled
+ * Root Fixed setting can be changed by API esp_mesh_fix_root().
+ * Root Fixed setting can also be changed by event MESH_EVENT_ROOT_FIXED.
+ *
+ * @return true/false
+ */
+bool esp_mesh_is_root_fixed(void);
+
+/**
+ * @brief set a specified parent
+ * self-organized networking will be disabled.
+ *
+ * @param parent parent configuration
+ * @param my_type my mesh type
+ * @param my_layer my mesh layer
+ *
+ * @return
+ * - ESP_OK
+ * - ESP_ERR_ARGUMENT
+ * - ESP_ERR_MESH_NOT_CONFIG
+ */
+esp_err_t esp_mesh_set_parent(wifi_config_t *parent, mesh_type_t my_type, int my_layer);
+
#ifdef __cplusplus
}
err, data.proto, data.tos);
}
}
+ /* if route_table_size is less than 10, add delay to avoid watchdog in this task. */
if (route_table_size < 10) {
vTaskDelay(1 * 1000 / portTICK_RATE_MS);
}
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>");
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");
break;
ESP_ERROR_CHECK(esp_mesh_set_ap_authmode(CONFIG_MESH_AP_AUTHMODE));
ESP_ERROR_CHECK(esp_mesh_set_vote_percentage(1));
ESP_ERROR_CHECK(esp_mesh_set_ap_assoc_expire(10));
+#ifdef MESH_FIX_ROOT
+ ESP_ERROR_CHECK(esp_mesh_fix_root(1));
+#endif
mesh_cfg_t cfg = MESH_INIT_CONFIG_DEFAULT();
/* mesh ID */
memcpy((uint8_t *) &cfg.mesh_id, MESH_ID, 6);
ESP_ERROR_CHECK(esp_mesh_get_switch_parent_paras(&switch_paras));
switch_paras.backoff_rssi = -45;
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 */
ESP_ERROR_CHECK(esp_mesh_start());
- ESP_LOGI(MESH_TAG, "mesh starts successfully, heap:%d\n", esp_get_free_heap_size());
+ ESP_LOGI(MESH_TAG, "mesh starts successfully, heap:%d, %s\n", esp_get_free_heap_size(),
+ esp_mesh_is_root_fixed() ? "root fixed" : "root not fixed");
}