@@ -127,7 +127,7 @@ extern "C" {
127
127
#define ESP_ERR_MESH_VOTING (ESP_ERR_MESH_BASE + 22) /**< vote in progress */
128
128
#define ESP_ERR_MESH_XMIT (ESP_ERR_MESH_BASE + 23) /**< XMIT */
129
129
#define ESP_ERR_MESH_QUEUE_READ (ESP_ERR_MESH_BASE + 24) /**< error in reading queue */
130
- #define ESP_ERR_MESH_INACTIVE (ESP_ERR_MESH_BASE + 25) /**< mesh network is not active */
130
+ #define ESP_ERR_MESH_PS (ESP_ERR_MESH_BASE + 25) /**< mesh PS is not specified as enable or disable */
131
131
132
132
/**
133
133
* @brief Flags bitmap for esp_mesh_send() and esp_mesh_recv()
@@ -158,7 +158,16 @@ extern "C" {
158
158
/**
159
159
* @brief Mesh PS (Power Save) duty cycle type
160
160
*/
161
- #define MESH_PS_DEVICE_DUTY_REQUEST (0x01) /**< requests to join a network PS without specifying a duty cycle */
161
+ #define MESH_PS_DEVICE_DUTY_REQUEST (0x01) /**< requests to join a network PS without specifying a device duty cycle. After the
162
+ device joins the network, a network duty cycle will be provided by the network */
163
+ #define MESH_PS_DEVICE_DUTY_DEMAND (0x04) /**< requests to join a network PS and specifies a demanded device duty cycle */
164
+ #define MESH_PS_NETWORK_DUTY_MASTER (0x80) /**< indicates the device is the NWK-DUTY-MASTER (network duty cycle master) */
165
+
166
+ /**
167
+ * @brief Mesh PS (Power Save) duty cycle applied rule
168
+ */
169
+ #define MESH_PS_NETWORK_DUTY_APPLIED_ENTIRE (0) /** the specified network duty is applied to the entire network <*/
170
+ #define MESH_PS_NETWORK_DUTY_APPLIED_UPLINK (1) /** the specified network duty is applied to only the up-link path <*/
162
171
163
172
/*******************************************************
164
173
* Enumerations
@@ -200,6 +209,8 @@ typedef enum {
200
209
after finding it. */
201
210
MESH_EVENT_ROUTER_SWITCH , /**< if users specify BSSID of the router in mesh configuration, when the root connects to another
202
211
router with the same SSID, this event will be posted and the new router information is attached. */
212
+ MESH_EVENT_PS_PARENT_DUTY , /**< parent duty */
213
+ MESH_EVENT_PS_CHILD_DUTY , /**< child duty */
203
214
MESH_EVENT_MAX ,
204
215
} mesh_event_id_t ;
205
216
@@ -302,7 +313,8 @@ typedef struct {
302
313
*/
303
314
typedef struct {
304
315
wifi_event_sta_connected_t connected ; /**< parent information, same as Wi-Fi event SYSTEM_EVENT_STA_CONNECTED does */
305
- uint8_t self_layer ; /**< layer */
316
+ uint16_t self_layer ; /**< layer */
317
+ uint8_t duty ; /**< parent duty */
306
318
} mesh_event_connected_t ;
307
319
308
320
/**
@@ -316,7 +328,7 @@ typedef struct {
316
328
* @brief Layer change information
317
329
*/
318
330
typedef struct {
319
- uint8_t new_layer ; /**< new layer */
331
+ uint16_t new_layer ; /**< new layer */
320
332
} mesh_event_layer_change_t ;
321
333
322
334
/**
@@ -415,6 +427,14 @@ typedef struct {
415
427
*/
416
428
typedef wifi_event_sta_connected_t mesh_event_router_switch_t ;
417
429
430
+ /**
431
+ * @brief PS duty information
432
+ */
433
+ typedef struct {
434
+ uint8_t duty ; /**< parent or child duty */
435
+ mesh_event_child_connected_t child_connected ; /**< child info */
436
+ } mesh_event_ps_duty_t ;
437
+
418
438
/**
419
439
* @brief Mesh event information
420
440
*/
@@ -440,6 +460,7 @@ typedef union {
440
460
mesh_event_network_state_t network_state ; /**< network state, such as whether current mesh network has a root. */
441
461
mesh_event_find_network_t find_network ; /**< network found that can join */
442
462
mesh_event_router_switch_t router_switch ; /**< new router information */
463
+ mesh_event_ps_duty_t ps_duty ; /**< PS duty information */
443
464
} mesh_event_info_t ;
444
465
445
466
/**
@@ -601,7 +622,7 @@ esp_err_t esp_mesh_start(void);
601
622
* - Delete TX and RX queues.
602
623
* - Release resources.
603
624
* - Restore Wi-Fi softAP to default settings if Wi-Fi dual mode is enabled.
604
- * - Set Wi-Fi power save type to WIFI_PS_NONE.
625
+ * - Set Wi-Fi Power Save type to WIFI_PS_NONE.
605
626
*
606
627
* @return
607
628
* - ESP_OK
@@ -849,7 +870,9 @@ esp_err_t esp_mesh_set_type(mesh_type_t type);
849
870
mesh_type_t esp_mesh_get_type (void );
850
871
851
872
/**
852
- * @brief Set network max layer value (max:25, default:25)
873
+ * @brief Set network max layer value
874
+ * - for tree topology, the max is 25.
875
+ * - for chain topology, the max is 1000.
853
876
* - Network max layer limits the max hop count.
854
877
*
855
878
* @attention This API shall be called before mesh is started.
@@ -1477,7 +1500,7 @@ int64_t esp_mesh_get_tsf_time(void);
1477
1500
* @brief Set mesh topology. The default value is MESH_TOPO_TREE
1478
1501
* - MESH_TOPO_CHAIN supports up to 1000 layers
1479
1502
*
1480
- * @attention This API shall be called before mesh is started
1503
+ * @attention This API shall be called before mesh is started.
1481
1504
*
1482
1505
* @param[in] topo MESH_TOPO_TREE or MESH_TOPO_CHAIN
1483
1506
*
@@ -1496,23 +1519,57 @@ esp_err_t esp_mesh_set_topology(esp_mesh_topology_t topo);
1496
1519
esp_mesh_topology_t esp_mesh_get_topology (void );
1497
1520
1498
1521
/**
1499
- * @brief Check whether the mesh network is in active state
1500
- * - If the mesh network is not in active state, mesh devices will neither transmit nor receive frames.
1501
- * - If power save mode of the mesh network is enabled, devices should check whether the network is active before
1502
- * sending any packets. (i.e. before calling esp_mesh_send()).
1503
- * - Power save mode is enabled by setting the PS type to WIFI_PS_MIN_MODEM for all devices before mesh is started.
1522
+ * @brief Enable mesh Power Save function
1523
+ *
1524
+ * @attention This API shall be called before mesh is started.
1525
+ *
1526
+ * @return
1527
+ * - ESP_OK
1528
+ * - ESP_ERR_WIFI_NOT_INIT
1529
+ * - ESP_ERR_MESH_NOT_ALLOWED
1530
+ */
1531
+ esp_err_t esp_mesh_enable_ps (void );
1532
+
1533
+ /**
1534
+ * @brief Disable mesh Power Save function
1535
+ *
1536
+ * @attention This API shall be called before mesh is started.
1537
+ *
1538
+ * @return
1539
+ * - ESP_OK
1540
+ * - ESP_ERR_WIFI_NOT_INIT
1541
+ * - ESP_ERR_MESH_NOT_ALLOWED
1542
+ */
1543
+ esp_err_t esp_mesh_disable_ps (void );
1544
+
1545
+ /**
1546
+ * @brief Check whether the mesh Power Save function is enabled
1504
1547
*
1505
1548
* @return true/false
1506
1549
*/
1507
- bool esp_mesh_is_network_active (void );
1550
+ bool esp_mesh_is_ps_enabled (void );
1508
1551
1509
1552
/**
1510
- * @brief Set device duty cycle and type
1553
+ * @brief Check whether the device is in active state
1554
+ * - If the device is not in active state, it will neither transmit nor receive frames.
1511
1555
*
1512
- * @attention This API can be called at any time after mesh is initialized.
1556
+ * @return true/false
1557
+ */
1558
+ bool esp_mesh_is_device_active (void );
1559
+
1560
+ /**
1561
+ * @brief Set the device duty cycle and type
1562
+ * - The range of dev_duty values is 1 to 100. The default value is 12.
1563
+ * - dev_duty = 100, the PS will be stopped.
1564
+ * - dev_duty is better to not less than 5.
1565
+ * - dev_duty_type could be MESH_PS_DEVICE_DUTY_REQUEST or MESH_PS_DEVICE_DUTY_DEMAND.
1566
+ * - If dev_duty_type is set to MESH_PS_DEVICE_DUTY_REQUEST, the device will use a nwk_duty provided by the network.
1567
+ * - If dev_duty_type is set to MESH_PS_DEVICE_DUTY_DEMAND, the device will use the specified dev_duty.
1568
+ *
1569
+ * @attention This API can be called at any time after mesh is started.
1513
1570
*
1514
1571
* @param[in] dev_duty device duty cycle
1515
- * @param[in] dev_duty_type device PS duty cycle type
1572
+ * @param[in] dev_duty_type device PS duty cycle type, not accept MESH_PS_NETWORK_DUTY_MASTER
1516
1573
*
1517
1574
* @return
1518
1575
* - ESP_OK
@@ -1531,8 +1588,63 @@ esp_err_t esp_mesh_set_active_duty_cycle(int dev_duty, int dev_duty_type);
1531
1588
*/
1532
1589
esp_err_t esp_mesh_get_active_duty_cycle (int * dev_duty , int * dev_duty_type );
1533
1590
1591
+ /**
1592
+ * @brief Set the network duty cycle, duration and rule
1593
+ * - The range of nwk_duty values is 1 to 100. The default value is 12.
1594
+ * - nwk_duty is the network duty cycle the entire network or the up-link path will use. A device that successfully
1595
+ * sets the nwk_duty is known as a NWK-DUTY-MASTER.
1596
+ * - duration_mins specifies how long the specified nwk_duty will be used. Once duration_mins expires, the root will take
1597
+ * over as the NWK-DUTY-MASTER. If an existing NWK-DUTY-MASTER leaves the network, the root will take over as the
1598
+ * NWK-DUTY-MASTER again.
1599
+ * - duration_mins = (-1) represents nwk_duty will be used until a new NWK-DUTY-MASTER with a different nwk_duty appears.
1600
+ * - Only the root can set duration_mins to (-1).
1601
+ * - applied_rule could be MESH_PS_NETWORK_DUTY_APPLIED_ENTIRE or MESH_PS_NETWORK_DUTY_APPLIED_UPLINK.
1602
+ * - If applied_rule is set to MESH_PS_NETWORK_DUTY_APPLIED_ENTIRE, the nwk_duty will be used by the entire network.
1603
+ * - If applied_rule is set to MESH_PS_NETWORK_DUTY_APPLIED_UPLINK, the nwk_duty will only be used by the up-link path nodes.
1604
+ * - The root does not accept MESH_PS_NETWORK_DUTY_APPLIED_UPLINK.
1605
+ * - A nwk_duty with duration_mins(-1) set by the root is the default network duty cycle used by the entire network.
1606
+ *
1607
+ * @attention This API can be called at any time after mesh is started.
1608
+ * - In self-organized network, if this API is called before mesh is started in all devices, (1)nwk_duty shall be set to the
1609
+ * same value for all devices; (2)duration_mins shall be set to (-1); (3)applied_rule shall be set to
1610
+ * MESH_PS_NETWORK_DUTY_APPLIED_ENTIRE; after the voted root appears, the root will become the NWK-DUTY-MASTER and broadcast
1611
+ * the nwk_duty and its identity of NWK-DUTY-MASTER.
1612
+ * - If the root is specified (FIXED-ROOT), call this API in the root to provide a default nwk_duty for the entire network.
1613
+ * - After joins the network, any device can call this API to change the nwk_duty, duration_mins or applied_rule.
1614
+ *
1615
+ * @param[in] nwk_duty network duty cycle
1616
+ * @param[in] duration_mins duration (unit: minutes)
1617
+ * @param[in] applied_rule MESH_PS_NETWORK_DUTY_APPLIED_ENTIRE or MESH_PS_NETWORK_DUTY_APPLIED_UPLINK
1618
+ *
1619
+ * @return
1620
+ * - ESP_OK
1621
+ * - ESP_FAIL
1622
+ */
1623
+ esp_err_t esp_mesh_set_network_duty_cycle (int nwk_duty , int duration_mins , int applied_rule );
1624
+
1625
+ /**
1626
+ * @brief Get the network duty cycle, duration, type and rule
1627
+ *
1628
+ * @param[out] nwk_duty current network duty cycle
1629
+ * @param[out] duration_mins the duration of current nwk_duty
1630
+ * @param[out] dev_duty_type if it includes MESH_PS_DEVICE_DUTY_MASTER, this device is the current NWK-DUTY-MASTER.
1631
+ * @param[out] applied_rule MESH_PS_NETWORK_DUTY_APPLIED_ENTIRE or MESH_PS_NETWORK_DUTY_APPLIED_UPLINK
1632
+ *
1633
+ * @return
1634
+ * - ESP_OK
1635
+ */
1636
+ esp_err_t esp_mesh_get_network_duty_cycle (int * nwk_duty , int * duration_mins , int * dev_duty_type , int * applied_rule );
1637
+
1534
1638
/**
1535
1639
* @brief Get the running active duty cycle
1640
+ * - The running active duty cycle of the root is 100.
1641
+ * - If duty type is set to MESH_PS_DEVICE_DUTY_REQUEST, the running active duty cycle is nwk_duty provided by the network.
1642
+ * - If duty type is set to MESH_PS_DEVICE_DUTY_DEMAND, the running active duty cycle is dev_duty specified by the users.
1643
+ * - In a mesh network, devices are typically working with a certain duty-cycle (transmitting, receiving and sleep) to
1644
+ * reduce the power consumption. The running active duty cycle decides the amount of awake time within a beacon interval.
1645
+ * At each start of beacon interval, all devices wake up, broadcast beacons, and transmit packets if they do have pending
1646
+ * packets for their parents or for their children. Note that Low-duty-cycle means devices may not be active in most of
1647
+ * the time, the latency of data transmission might be greater.
1536
1648
*
1537
1649
* @return the running active duty cycle
1538
1650
*/
0 commit comments