ESP8266_RTOS_SDK  v1.4.0
Enumerations | Functions
Mesh APIs

Mesh APIs. More...

Enumerations

enum  mesh_status {
  MESH_DISABLE = 0, MESH_WIFI_CONN, MESH_NET_CONN, MESH_LOCAL_AVAIL,
  MESH_ONLINE_AVAIL
}
 
enum  mesh_node_type { MESH_NODE_PARENT = 0, MESH_NODE_CHILD, MESH_NODE_ALL }
 

Functions

bool espconn_mesh_local_addr (struct ip_addr *ip)
 Check whether the IP address is mesh local IP address or not. More...
 
bool espconn_mesh_get_node_info (enum mesh_node_type type, uint8_t **info, uint8_t *count)
 Get the information of mesh node. More...
 
bool espconn_mesh_encrypt_init (AUTH_MODE mode, uint8_t *passwd, uint8_t passwd_len)
 Set WiFi cryption algrithm and password for mesh node. More...
 
bool espconn_mesh_set_ssid_prefix (uint8_t *prefix, uint8_t prefix_len)
 Set prefix of SSID for mesh node. More...
 
bool espconn_mesh_set_max_hops (uint8_t max_hops)
 Set max hop for mesh network. More...
 
bool espconn_mesh_group_id_init (uint8_t *grp_id, uint16_t gid_len)
 Set group ID of mesh node. More...
 
bool espconn_mesh_set_dev_type (uint8_t dev_type)
 Set the curent device type. More...
 
sint8 espconn_mesh_connect (struct espconn *usr_esp)
 Try to establish mesh connection to server. More...
 
sint8 espconn_mesh_disconnect (struct espconn *usr_esp)
 Disconnect a mesh connection. More...
 
sint8 espconn_mesh_get_status ()
 Get current mesh status. More...
 
sint8 espconn_mesh_sent (struct espconn *usr_esp, uint8 *pdata, uint16 len)
 Send data through mesh network. More...
 
uint8 espconn_mesh_get_max_hops ()
 Get max hop of mesh network. More...
 
void espconn_mesh_enable (espconn_mesh_callback enable_cb, enum mesh_type type)
 To enable mesh network. More...
 
void espconn_mesh_disable (espconn_mesh_callback disable_cb)
 To disable mesh network. More...
 
void espconn_mesh_init ()
 To print version of mesh. More...
 

Detailed Description

Mesh APIs.

Enumeration Type Documentation

Enumerator
MESH_NODE_PARENT 

get information of parent node

MESH_NODE_CHILD 

get information of child node(s)

MESH_NODE_ALL 

get information of all nodes

Enumerator
MESH_DISABLE 

mesh disabled

MESH_WIFI_CONN 

WiFi connected

MESH_NET_CONN 

TCP connection OK

MESH_LOCAL_AVAIL 

local mesh is avaliable

MESH_ONLINE_AVAIL 

online mesh is avaliable

Function Documentation

sint8 espconn_mesh_connect ( struct espconn usr_esp)

Try to establish mesh connection to server.

Attention
If espconn_mesh_connect fail, returns non-0 value, there is no connection, so it won't enter any espconn callback.
Parameters
structespconn *usr_esp : the network connection structure, the usr_esp to listen to the connection
Returns
0 : succeed
Non-0 : error code
  • ESPCONN_RTE - Routing Problem
  • ESPCONN_MEM - Out of memory
  • ESPCONN_ISCONN - Already connected
  • ESPCONN_ARG - Illegal argument, can't find the corresponding connection according to structure espconn
void espconn_mesh_disable ( espconn_mesh_callback  disable_cb)

To disable mesh network.

Attention
When mesh network is disabed, the system will trigger disable_cb.
Parameters
espconn_mesh_callbackdisable_cb : callback function of mesh-disable
enummesh_type type : type of mesh, local or online.
Returns
null
sint8 espconn_mesh_disconnect ( struct espconn usr_esp)

Disconnect a mesh connection.

Attention
Do not call this API in any espconn callback. If needed, please use system task to trigger espconn_mesh_disconnect.
Parameters
structespconn *usr_esp : the network connection structure
Returns
0 : succeed
Non-0 : error code
  • ESPCONN_ARG - illegal argument, can't find the corresponding TCP connection according to structure espconn
void espconn_mesh_enable ( espconn_mesh_callback  enable_cb,
enum mesh_type  type 
)

To enable mesh network.

Attention
1. the function should be called in user_init.
2. if mesh node can not scan the mesh AP, it will be isolate node without trigger enable_cb. user can use espconn_mesh_get_status to get current status of node.
3. if user try to enable online mesh, but node fails to establish mesh connection the node will work with local mesh.
Parameters
espconn_mesh_callbackenable_cb : callback function of mesh-enable
enummesh_type type : type of mesh, local or online.
Returns
null
bool espconn_mesh_encrypt_init ( AUTH_MODE  mode,
uint8_t *  passwd,
uint8_t  passwd_len 
)

Set WiFi cryption algrithm and password for mesh node.

Attention
The function must be called before espconn_mesh_enable.
Parameters
AUTH_MODEmode : cryption algrithm (WPA/WAP2/WPA_WPA2).
uint8_t*passwd : password of WiFi.
uint8_tpasswd_len : length of password (8 <= passwd_len <= 64).
Returns
true : succeed
false : fail
uint8 espconn_mesh_get_max_hops ( )

Get max hop of mesh network.

Parameters
null.
Returns
the current max hop of mesh
bool espconn_mesh_get_node_info ( enum mesh_node_type  type,
uint8_t **  info,
uint8_t *  count 
)

Get the information of mesh node.

Parameters
enummesh_node_type typ : mesh node type.
uint8_t**info : the information will be saved in *info.
uint8_t*count : the node count in *info.
Returns
true : succeed
false : fail
sint8 espconn_mesh_get_status ( )

Get current mesh status.

Parameters
null
Returns
the current mesh status, please refer to enum mesh_status.
bool espconn_mesh_group_id_init ( uint8_t *  grp_id,
uint16_t  gid_len 
)

Set group ID of mesh node.

Attention
The function must be called before espconn_mesh_enable.
Parameters
uint8_t*grp_id : group ID.
uint16_tgid_len: length of group ID, now gid_len = 6.
Returns
true : succeed
false : fail
void espconn_mesh_init ( )

To print version of mesh.

Parameters
null
Returns
null
bool espconn_mesh_local_addr ( struct ip_addr *  ip)

Check whether the IP address is mesh local IP address or not.

Attention
1. The range of mesh local IP address is 2.255.255.* ~ max_hop.255.255.*.
2. IP pointer should not be NULL. If the IP pointer is NULL, it will return false.
Parameters
structip_addr *ip : IP address
Returns
true : the IP address is mesh local IP address
false : the IP address is not mesh local IP address
sint8 espconn_mesh_sent ( struct espconn usr_esp,
uint8 *  pdata,
uint16  len 
)

Send data through mesh network.

Attention
Please call espconn_mesh_sent after espconn_sent_callback of the pre-packet.
Parameters
structespconn *usr_esp : the network connection structure
uint8*pdata : pointer of data
uint16len : data length
Returns
0 : succeed
Non-0 : error code
  • ESPCONN_MEM - out of memory
  • ESPCONN_ARG - illegal argument, can't find the corresponding network transmission according to structure espconn
  • ESPCONN_MAXNUM - buffer of sending data is full
  • ESPCONN_IF - send UDP data fail
bool espconn_mesh_set_dev_type ( uint8_t  dev_type)

Set the curent device type.

Parameters
uint8_tdev_type : device type of mesh node
Returns
true : succeed
false : fail
bool espconn_mesh_set_max_hops ( uint8_t  max_hops)

Set max hop for mesh network.

Attention
The function must be called before espconn_mesh_enable.
Parameters
uint8_tmax_hops : max hop of mesh network (1 <= max_hops < 10, 4 is recommended).
Returns
true : succeed
false : fail
bool espconn_mesh_set_ssid_prefix ( uint8_t *  prefix,
uint8_t  prefix_len 
)

Set prefix of SSID for mesh node.

Attention
The function must be called before espconn_mesh_enable.
Parameters
uint8_t*prefix : prefix of SSID.
uint8_tprefix_len : length of prefix (0 < passwd_len <= 22).
Returns
true : succeed
false : fail