Skip to content

Commit 09d4767

Browse files
committed
Merge branch 'mesh/power_save_function' into 'master'
mesh/ps: add duty control and support only transmit/receive on active duty See merge request espressif/esp-idf!8152
2 parents a97cd64 + bdb6565 commit 09d4767

File tree

10 files changed

+267
-59
lines changed

10 files changed

+267
-59
lines changed

components/esp_common/src/esp_err_to_name.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -470,8 +470,8 @@ static const esp_err_msg_t esp_err_msg_table[] = {
470470
# ifdef ESP_ERR_MESH_QUEUE_READ
471471
ERR_TBL_IT(ESP_ERR_MESH_QUEUE_READ), /* 16408 0x4018 */
472472
# endif
473-
# ifdef ESP_ERR_MESH_INACTIVE
474-
ERR_TBL_IT(ESP_ERR_MESH_INACTIVE), /* 16409 0x4019 */
473+
# ifdef ESP_ERR_MESH_PS
474+
ERR_TBL_IT(ESP_ERR_MESH_PS), /* 16409 0x4019 */
475475
# endif
476476
// components/esp_netif/include/esp_netif_types.h
477477
# ifdef ESP_ERR_ESP_NETIF_BASE

components/esp_wifi/include/esp_mesh.h

Lines changed: 128 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ extern "C" {
127127
#define ESP_ERR_MESH_VOTING (ESP_ERR_MESH_BASE + 22) /**< vote in progress */
128128
#define ESP_ERR_MESH_XMIT (ESP_ERR_MESH_BASE + 23) /**< XMIT */
129129
#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 */
131131

132132
/**
133133
* @brief Flags bitmap for esp_mesh_send() and esp_mesh_recv()
@@ -158,7 +158,16 @@ extern "C" {
158158
/**
159159
* @brief Mesh PS (Power Save) duty cycle type
160160
*/
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 <*/
162171

163172
/*******************************************************
164173
* Enumerations
@@ -200,6 +209,8 @@ typedef enum {
200209
after finding it. */
201210
MESH_EVENT_ROUTER_SWITCH, /**< if users specify BSSID of the router in mesh configuration, when the root connects to another
202211
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 */
203214
MESH_EVENT_MAX,
204215
} mesh_event_id_t;
205216

@@ -302,7 +313,8 @@ typedef struct {
302313
*/
303314
typedef struct {
304315
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 */
306318
} mesh_event_connected_t;
307319

308320
/**
@@ -316,7 +328,7 @@ typedef struct {
316328
* @brief Layer change information
317329
*/
318330
typedef struct {
319-
uint8_t new_layer; /**< new layer */
331+
uint16_t new_layer; /**< new layer */
320332
} mesh_event_layer_change_t;
321333

322334
/**
@@ -415,6 +427,14 @@ typedef struct {
415427
*/
416428
typedef wifi_event_sta_connected_t mesh_event_router_switch_t;
417429

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+
418438
/**
419439
* @brief Mesh event information
420440
*/
@@ -440,6 +460,7 @@ typedef union {
440460
mesh_event_network_state_t network_state; /**< network state, such as whether current mesh network has a root. */
441461
mesh_event_find_network_t find_network; /**< network found that can join */
442462
mesh_event_router_switch_t router_switch; /**< new router information */
463+
mesh_event_ps_duty_t ps_duty; /**< PS duty information */
443464
} mesh_event_info_t;
444465

445466
/**
@@ -601,7 +622,7 @@ esp_err_t esp_mesh_start(void);
601622
* - Delete TX and RX queues.
602623
* - Release resources.
603624
* - 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.
605626
*
606627
* @return
607628
* - ESP_OK
@@ -849,7 +870,9 @@ esp_err_t esp_mesh_set_type(mesh_type_t type);
849870
mesh_type_t esp_mesh_get_type(void);
850871

851872
/**
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.
853876
* - Network max layer limits the max hop count.
854877
*
855878
* @attention This API shall be called before mesh is started.
@@ -1477,7 +1500,7 @@ int64_t esp_mesh_get_tsf_time(void);
14771500
* @brief Set mesh topology. The default value is MESH_TOPO_TREE
14781501
* - MESH_TOPO_CHAIN supports up to 1000 layers
14791502
*
1480-
* @attention This API shall be called before mesh is started
1503+
* @attention This API shall be called before mesh is started.
14811504
*
14821505
* @param[in] topo MESH_TOPO_TREE or MESH_TOPO_CHAIN
14831506
*
@@ -1496,23 +1519,57 @@ esp_err_t esp_mesh_set_topology(esp_mesh_topology_t topo);
14961519
esp_mesh_topology_t esp_mesh_get_topology(void);
14971520

14981521
/**
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
15041547
*
15051548
* @return true/false
15061549
*/
1507-
bool esp_mesh_is_network_active(void);
1550+
bool esp_mesh_is_ps_enabled(void);
15081551

15091552
/**
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.
15111555
*
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.
15131570
*
15141571
* @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
15161573
*
15171574
* @return
15181575
* - ESP_OK
@@ -1531,8 +1588,63 @@ esp_err_t esp_mesh_set_active_duty_cycle(int dev_duty, int dev_duty_type);
15311588
*/
15321589
esp_err_t esp_mesh_get_active_duty_cycle(int* dev_duty, int* dev_duty_type);
15331590

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+
15341638
/**
15351639
* @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.
15361648
*
15371649
* @return the running active duty cycle
15381650
*/

components/esp_wifi/include/esp_mesh_internal.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#define __ESP_MESH_INTERNAL_H__
1717

1818
#include "esp_err.h"
19+
#include "esp_mesh.h"
1920
#include "esp_wifi.h"
2021
#include "esp_wifi_types.h"
2122
#include "esp_private/wifi.h"
@@ -96,6 +97,19 @@ typedef struct {
9697
uint8_t toDS; /**< toDS state */
9798
} __attribute__((packed)) mesh_assoc_t;
9899

100+
/**
101+
* @brief Mesh PS duties
102+
*/
103+
typedef struct {
104+
uint8_t device;
105+
uint8_t parent;
106+
struct {
107+
bool used;
108+
uint8_t duty;
109+
uint8_t mac[6];
110+
} child[ESP_WIFI_MAX_CONN_NUM];
111+
} esp_mesh_ps_duties_t;
112+
99113
/*******************************************************
100114
* Function Definitions
101115
*******************************************************/
@@ -263,6 +277,14 @@ esp_err_t esp_mesh_set_announce_interval(int short_ms, int long_ms);
263277
*/
264278
esp_err_t esp_mesh_get_announce_interval(int *short_ms, int *long_ms);
265279

280+
/**
281+
* @brief Get the running duties of device, parent and children
282+
*
283+
* @return
284+
* - ESP_OK
285+
*/
286+
esp_err_t esp_mesh_ps_get_duties(esp_mesh_ps_duties_t* ps_duties);
287+
266288
#ifdef __cplusplus
267289
}
268290
#endif

components/idf_test/integration_test/INIT_COND_MESH.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,6 @@ initial condition:
9595
- - MSSC SSC[1-<node_num>] mesh -Q -o 3
9696
- - P SSC[1-<node_num>] RE "MID,%%s"%%(<mesh_id>)
9797
- P SSC[1-<node_num>] RE "MROUTER,%%s"%%(<router_ssid>)
98-
- P SSC[1-<node_num>] RE "SWITCH_PARENT,%%s"%%(<duration_ms>)
9998
- P SSC[1-<node_num>] C NO_SPECIFIC_SETTINGS
10099
restore cmd set:
101100
- ''

components/idf_test/integration_test/TC_IT_MESH_COMM.yml

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -402,22 +402,23 @@ test cases:
402402
cmd set:
403403
- ''
404404
- - SSC MNODE(0) meshsend -S -d <MNODE(0,0)_mac> -l 1460 -c 20 -b 20 -f 2 -t 0
405-
- - P MNODE(0) C +MESHTXPKT,OK
405+
- - P MNODE(0) C +MESHTXPKT,OK C +MESHSEND,OK
406406
- P MNODE(0,0) C +MESHRXPKT,OK
407407
- - SSC MNODE(0) meshsend -S -d <MNODE(0,0)_mac> -l 1460 -c 20 -b 20 -f 2 -t 1
408-
- - P MNODE(0) C +MESHTXPKT,OK
408+
- - P MNODE(0) C +MESHTXPKT,FAIL C +MESHSEND,OK
409409
- - SSC MNODE(0) meshsend -S -d <MNODE(0,0)_mac> -l 1460 -c 20 -b 20 -f 2 -t 2
410-
- - P MNODE(0) C +MESHTXPKT,OK
410+
- - P MNODE(0) C +MESHTXPKT,OK C +MESHSEND,OK
411411
- P MNODE(0,0) C +MESHRXPKT,OK
412412
- - SSC MNODE(0,0) meshsend -S -d <MNODE(0)_mac> -l 1460 -c 20 -b 20 -f 2 -t 2
413-
- - P MNODE(0,0) C +MESHTXPKT,FAIL
413+
- - P MNODE(0,0) C +MESHTXPKT,FAIL C +MESHSEND,OK
414414
- - SSC MNODE(0,0) meshsend -S -d <MNODE(0)_mac> -l 1460 -c 20 -b 20 -f 2 -t 0
415-
- - P MNODE(0,0) C +MESHTXPKT,FAIL
415+
- - P MNODE(0,0) C +MESHTXPKT,OK C +MESHSEND,OK
416+
- P MNODE(0) C +MESHRXPKT,OK
416417
expected result: |-
417418
1. succeed
418-
2. succeed
419+
2. failed
419420
3. succeed
420-
4. succeed
421+
4. failed
421422
5. succeed
422423
steps: |-
423424
1. root send unicast to L2 with tos = P2P

components/idf_test/integration_test/TC_IT_MESH_EST.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1043,7 +1043,7 @@ test cases:
10431043
- - P SSC[1-<node_num>] C +MESHSET:MLAYER,OK
10441044
- - MSSC SSC[1-<node_num>] mesh -T
10451045
- - P SSC[1-<node_num>] C +MESH:START,OK
1046-
- - DELAY 60
1046+
- - DELAY <delay_time>
10471047
- - ''
10481048
- - VALUE <tree_node_num> <node_num>
10491049
- - R PC_COM L OK

0 commit comments

Comments
 (0)