]> granicus.if.org Git - esp-idf/commitdiff
mesh: add fix root function
authorqiyueixa <qiyuexia@espressif.com>
Wed, 25 Apr 2018 16:13:53 +0000 (00:13 +0800)
committerqiyueixa <qiyuexia@espressif.com>
Thu, 26 Apr 2018 13:15:35 +0000 (21:15 +0800)
components/esp32/include/esp_mesh.h
components/esp32/lib
examples/mesh/internal_transceiver/main/Kconfig.projbuild
examples/mesh/internal_transceiver/main/mesh_main.c

index 12e2d55d8f342d6b51a12b28ed2108756ad9b71b..7c1c166acb8273dc3e9ab8139e7474fd4cbcfff0 100644 (file)
@@ -171,6 +171,9 @@ typedef enum {
                                              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;
 
@@ -339,6 +342,13 @@ typedef struct {
     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
  */
@@ -360,6 +370,7 @@ typedef union {
     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;
 
 /**
@@ -864,7 +875,7 @@ bool esp_mesh_is_root(void);
 /**
  * @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
  *
@@ -1059,6 +1070,13 @@ int esp_mesh_get_xon_qsize(void);
  */
 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
  *
@@ -1194,6 +1212,42 @@ int esp_mesh_get_root_healing_delay(void);
  */
 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
 }
index 3ca7b8a9afdc01a1f0714072cc59c8509481e395..e9e4579336a539590a88ccac05ab9d0422506c3d 160000 (submodule)
@@ -1 +1 @@
-Subproject commit 3ca7b8a9afdc01a1f0714072cc59c8509481e395
+Subproject commit e9e4579336a539590a88ccac05ab9d0422506c3d
index 74dee1a2848b37f78265d8b87e408b8fc8141002..a3bad4bfd08fa6d1c324c04c00b2340140a0c9e6 100644 (file)
@@ -70,5 +70,11 @@ config MESH_ROUTE_TABLE_SIZE
         default 50
         help
             The number of devices over the network(max: 300).
+
+config MESH_PARENT_SSID
+    string "Parent SSID"
+        default "PARENT_SSID"
+        help
+            Parent SSID.
 endmenu
 
index 6e6bebf1284735d77093eccb5f9ace3dcd43b72b..bfdfa6f63b376797296d72e6f2f93d192c92f6e3 100644 (file)
@@ -149,6 +149,7 @@ void esp_mesh_p2p_tx_main(void *arg)
                          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);
         }
@@ -334,14 +335,21 @@ void esp_mesh_event_handler(mesh_event_t event)
                  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;
@@ -380,6 +388,9 @@ void app_main(void)
     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);
@@ -401,7 +412,19 @@ void app_main(void)
     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");
 }