MeterLogger
Data Structures | Enumerations | Functions
Mesh APIs

Mesh APIs. More...

Data Structures

struct  mesh_scan_para_type
 

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_router (struct station_config *router)
 Get the information of router used by mesh network. More...
 
bool espconn_mesh_set_router (struct station_config *router)
 Set the information of router used by mesh network. More...
 
bool espconn_mesh_server_init (struct ip_addr *ip, uint16_t port)
 Set server setup by user. 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...
 
uint8_t espconn_mesh_get_dev_type ()
 Get the curent device type. More...
 
int8_t espconn_mesh_connect (struct espconn *usr_esp)
 Try to establish mesh connection to server. More...
 
int8_t espconn_mesh_disconnect (struct espconn *usr_esp)
 Disconnect a mesh connection. More...
 
int8_t espconn_mesh_get_status ()
 Get current mesh status. More...
 
int8_t espconn_mesh_sent (struct espconn *usr_esp, uint8 *pdata, uint16 len)
 Send data through mesh network. More...
 
uint8_t 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_print_ver ()
 To print version of mesh. More...
 
void espconn_mesh_scan (struct mesh_scan_para_type *para)
 To get AP around node. More...
 

Detailed Description

Mesh APIs.

Enumeration Type Documentation

◆ mesh_node_type

Enumerator
MESH_NODE_PARENT 
MESH_NODE_CHILD 
MESH_NODE_ALL 

Definition at line 64 of file mesh.h.

64  {
65  MESH_NODE_PARENT = 0,
68 };

◆ mesh_status

Enumerator
MESH_DISABLE 
MESH_WIFI_CONN 
MESH_NET_CONN 
MESH_LOCAL_AVAIL 
MESH_ONLINE_AVAIL 

Definition at line 56 of file mesh.h.

Function Documentation

◆ espconn_mesh_connect()

int8_t 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

◆ espconn_mesh_disable()

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

◆ espconn_mesh_disconnect()

int8_t 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

◆ espconn_mesh_enable()

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

◆ espconn_mesh_encrypt_init()

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

◆ espconn_mesh_get_dev_type()

uint8_t espconn_mesh_get_dev_type ( )

Get the curent device type.

Parameters
none
Returns
device type

◆ espconn_mesh_get_max_hops()

uint8_t espconn_mesh_get_max_hops ( )

Get max hop of mesh network.

Parameters
null.
Returns
the current max hop of mesh

◆ espconn_mesh_get_node_info()

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

◆ espconn_mesh_get_router()

bool espconn_mesh_get_router ( struct station_config router)

Get the information of router used by mesh network.

Attention
1. The function should be called after mesh_enable_done
Parameters
structstation_config *router: router inforamtion
Returns
true : succeed
false : fail

◆ espconn_mesh_get_status()

int8_t espconn_mesh_get_status ( )

Get current mesh status.

Parameters
null
Returns
the current mesh status, please refer to enum mesh_status.

◆ espconn_mesh_group_id_init()

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

◆ espconn_mesh_local_addr()

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

◆ espconn_mesh_print_ver()

void espconn_mesh_print_ver ( )

To print version of mesh.

Parameters
null
Returns
null

◆ espconn_mesh_scan()

void espconn_mesh_scan ( struct mesh_scan_para_type para)

To get AP around node.

Attention
User can get normal AP or mesh AP using the function. If user plans to get normal AP, he/she needs to clear grp_set flag in para. If user plans to get mesh AP, he/she needs to set grp_set and grp_id;
Parameters
structmesh_scan_para_type *para : callback function of mesh-disable
Returns
null

◆ espconn_mesh_sent()

int8_t 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

◆ espconn_mesh_server_init()

bool espconn_mesh_server_init ( struct ip_addr ip,
uint16_t  port 
)

Set server setup by user.

Attention
If users wants to use themself server, they use the function. but the function must be called before espconn_mesh_enable. at the same time, users need to implement the server.
Parameters
structip_addr *ip : ip address of server.
uint16_tport : port used by server.
Returns
true : succeed
false : fail

◆ espconn_mesh_set_dev_type()

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

◆ espconn_mesh_set_max_hops()

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

◆ espconn_mesh_set_router()

bool espconn_mesh_set_router ( struct station_config router)

Set the information of router used by mesh network.

Attention
The function must be called before espconn_mesh_enable.
Parameters
structstation_config *router: router information. user should initialize the ssid and password.
Returns
true : succeed
false : fail

◆ espconn_mesh_set_ssid_prefix()

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