]> granicus.if.org Git - esp-idf/commitdiff
mesh: update mesh events demonstration
authorqiyuexia <qiyuexia@espressif.com>
Thu, 18 Apr 2019 14:38:43 +0000 (22:38 +0800)
committerchenyudong <chenyudong@espressif.com>
Fri, 5 Jul 2019 13:14:33 +0000 (21:14 +0800)
docs/_static/mesh-events-delivery.png
docs/en/api-reference/network/esp_mesh.rst
examples/mesh/manual_networking/main/mesh_main.c

index 40341bb1dd687eb0775a371a0cde9bf29cc4b3ef..ceedadf829f30ab0f66ade7a30c71d3d4cf7a352 100644 (file)
Binary files a/docs/_static/mesh-events-delivery.png and b/docs/_static/mesh-events-delivery.png differ
index 299a8b95297a213c21f29e01f715204815178345..b5ae9efdf3c7d808a0872bbc68bcbe17489053f9 100644 (file)
@@ -51,9 +51,9 @@ An application interfaces with ESP-MESH via **ESP-MESH Events**. Since ESP-MESH
 
     ESP-MESH System Events Delivery
 
-The :cpp:type:`mesh_event_id_t` defines all possible ESP-MESH system events and can indicate events such as the connection/disconnection of parent/child. Before ESP-MESH system events can be used, the application must register a **Mesh Event Callback** via :cpp:func:`esp_mesh_set_config`. The callback is used to receive events from the ESP-MESH stack as well as the LwIP Stack and should contain handlers for each event relevant to the application.
+The :cpp:type:`mesh_event_id_t` defines all possible ESP-MESH events and can indicate events such as the connection/disconnection of parent/child. Before ESP-MESH events can be used, the application must register a **Mesh Events handler** via :cpp:func:`esp_event_handler_register` to the default event task. Should contain handlers for each event relevant to the application.
 
-Typical use cases of system events include using events such as :cpp:enumerator:`MESH_EVENT_PARENT_CONNECTED` and :cpp:enumerator:`MESH_EVENT_CHILD_CONNECTED` to indicate when a node can begin transmitting data upstream and downstream respectively. Likewise, :cpp:enumerator:`MESH_EVENT_ROOT_GOT_IP` and :cpp:enumerator:`MESH_EVENT_ROOT_LOST_IP` can be used to indicate when the root node can and cannot transmit data to the external IP network.
+Typical use cases of mesh events include using events such as :cpp:enumerator:`MESH_EVENT_PARENT_CONNECTED` and :cpp:enumerator:`MESH_EVENT_CHILD_CONNECTED` to indicate when a node can begin transmitting data upstream and downstream respectively. Likewise, :cpp:enumerator:`IP_EVENT_STA_GOT_IP` and :cpp:enumerator:`IP_EVENT_STA_LOST_IP` can be used to indicate when the root node can and cannot transmit data to the external IP network.
 
 .. warning::
     When using ESP-MESH under self-organized mode, users must ensure that no calls to Wi-Fi API are made. This is due to the fact that the self-organizing mode will internally make Wi-Fi API calls to connect/disconnect/scan etc. **Any Wi-Fi calls from the application (including calls from callbacks and handlers of Wi-Fi events) may interfere with ESP-MESH's self-organizing behavior**. Therefore, user's should not call Wi-Fi APIs after :cpp:func:`esp_mesh_start` is called, and before :cpp:func:`esp_mesh_stop` is called.
@@ -81,8 +81,6 @@ The following code snippet demonstrates how to initialize LwIP for ESP-MESH appl
      */
     ESP_ERROR_CHECK(tcpip_adapter_dhcps_stop(TCPIP_ADAPTER_IF_AP));
     ESP_ERROR_CHECK(tcpip_adapter_dhcpc_stop(TCPIP_ADAPTER_IF_STA));
-    /* do not specify system event callback, use NULL instead. */
-    ESP_ERROR_CHECK(esp_event_loop_init(NULL, NULL));
 
 .. note::
 
@@ -108,12 +106,15 @@ The prerequisites for starting ESP-MESH is to initialize LwIP and Wi-Fi, The fol
      */
     ESP_ERROR_CHECK(tcpip_adapter_dhcps_stop(TCPIP_ADAPTER_IF_AP));
     ESP_ERROR_CHECK(tcpip_adapter_dhcpc_stop(TCPIP_ADAPTER_IF_STA));
-    /* do not specify system event callback, use NULL instead. */
-    ESP_ERROR_CHECK(esp_event_loop_init(NULL, NULL));
+
+    /*  event initialization */
+    ESP_ERROR_CHECK(esp_event_loop_create_default());
 
     /*  Wi-Fi initialization */
     wifi_init_config_t config = WIFI_INIT_CONFIG_DEFAULT();
     ESP_ERROR_CHECK(esp_wifi_init(&config));
+    /*  register IP events handler */
+    ESP_ERROR_CHECK(esp_event_handler_register(IP_EVENT, IP_EVENT_STA_GOT_IP, &ip_event_handler, NULL));
     ESP_ERROR_CHECK(esp_wifi_set_storage(WIFI_STORAGE_FLASH));
     ESP_ERROR_CHECK(esp_wifi_start());
 
@@ -134,6 +135,8 @@ The following code snippet demonstrates how to initialize ESP-MESH
 
     /*  mesh initialization */
     ESP_ERROR_CHECK(esp_mesh_init());
+    /*  register mesh events handler */
+    ESP_ERROR_CHECK(esp_event_handler_register(MESH_EVENT, ESP_EVENT_ANY_ID, &mesh_event_handler, NULL));
 
 .. _mesh-configuring-mesh:
 
@@ -149,9 +152,6 @@ ESP-MESH is configured via :cpp:func:`esp_mesh_set_config` which receives its ar
 +==================+=====================================+
 | Channel          | Range from 1 to 14                  |
 +------------------+-------------------------------------+
-| Event Callback   | Callback for Mesh Events,           |
-|                  | see :cpp:type:`mesh_event_cb_t`     |
-+------------------+-------------------------------------+
 | Mesh ID          | ID of ESP-MESH Network,             |
 |                  | see :cpp:type:`mesh_addr_t`         |
 +------------------+-------------------------------------+
@@ -173,8 +173,6 @@ The following code snippet demonstrates how to configure ESP-MESH.
     mesh_cfg_t cfg = MESH_INIT_CONFIG_DEFAULT();
     /* mesh ID */
     memcpy((uint8_t *) &cfg.mesh_id, MESH_ID, 6);
-    /* mesh event callback */
-    cfg.event_cb = &mesh_event_handler;
     /* channel (must match the router's channel) */
     cfg.channel = CONFIG_MESH_CHANNEL;
     /* router */
index 57629abe8bfd60d835b1b6836c46f66819b1fa7a..99ccfbe7f15a4bc0524ba8e6c3834345c8207278 100644 (file)
@@ -193,6 +193,7 @@ void mesh_event_handler(void *arg, esp_event_base_t event_base,
                  child_disconnected->aid,
                  MAC2STR(child_disconnected->mac));
     }
+    break;
     case MESH_EVENT_ROUTING_TABLE_ADD: {
         mesh_event_routing_table_change_t *routing_table = (mesh_event_routing_table_change_t *)event_data;
         ESP_LOGW(MESH_TAG, "<MESH_EVENT_ROUTING_TABLE_ADD>add %d, new:%d",