MeterLogger
mesh.h
Go to the documentation of this file.
1 /*
2  * ESPRSSIF MIT License
3  *
4  * Copyright (c) 2015 <ESPRESSIF SYSTEMS (SHANGHAI) PTE LTD>
5  *
6  * Permission is hereby granted for use on ESPRESSIF SYSTEMS ESP8266 only, in which case,
7  * it is free of charge, to any person obtaining a copy of this software and associated
8  * documentation files (the "Software"), to deal in the Software without restriction, including
9  * without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
10  * and/or sell copies of the Software, and to permit persons to whom the Software is furnished
11  * to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in all copies or
14  * substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
18  * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
19  * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
20  * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22  *
23  */
24 #ifndef __LWIP_API_MESH_H__
25 #define __LWIP_API_MESH_H__
26 
27 #include "ip_addr.h"
28 #include "user_interface.h"
29 #include "espconn.h"
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
33 
34 #define ESP_MESH_GROUP_ID_LEN (6)
35 
36 typedef void (* espconn_mesh_callback)();
37 typedef void (* espconn_mesh_scan_callback)(void *arg, int8_t status);
38 
39 enum mesh_type {
43  MESH_NONE = 0xFF
44 };
45 /** \defgroup Mesh_APIs Mesh APIs
46  * @brief Mesh APIs
47  *
48  *
49  *
50  */
51 
52 /** @addtogroup Mesh_APIs
53  * @{
54  */
55 
62 };
63 
68 };
69 
71  espconn_mesh_scan_callback usr_scan_cb; // scan done callback
72  uint8_t grp_id[ESP_MESH_GROUP_ID_LEN]; // group id
73  bool grp_set; // group set
74 };
75 
76 
77 /**
78  * @brief Check whether the IP address is mesh local IP address or not.
79  *
80  * @attention 1. The range of mesh local IP address is 2.255.255.* ~ max_hop.255.255.*.
81  * @attention 2. IP pointer should not be NULL. If the IP pointer is NULL, it will return false.
82  *
83  * @param struct ip_addr *ip : IP address
84  *
85  * @return true : the IP address is mesh local IP address
86  * @return false : the IP address is not mesh local IP address
87  */
88 bool espconn_mesh_local_addr(struct ip_addr *ip);
89 
90 /**
91  * @brief Get the information of router used by mesh network.
92  *
93  * @attention 1. The function should be called after mesh_enable_done
94  *
95  * @param struct station_config *router: router inforamtion
96  *
97  * @return true : succeed
98  * @return false : fail
99  */
100 bool espconn_mesh_get_router(struct station_config *router);
101 
102 /**
103  * @brief Set the information of router used by mesh network.
104  *
105  * @attention The function must be called before espconn_mesh_enable.
106  *
107  * @param struct station_config *router: router information.
108  * user should initialize the ssid and password.
109  *
110  * @return true : succeed
111  * @return false : fail
112  */
113 bool espconn_mesh_set_router(struct station_config *router);
114 
115 /**
116  * @brief Set server setup by user.
117  *
118  * @attention If users wants to use themself server, they use the function.
119  * but the function must be called before espconn_mesh_enable.
120  * at the same time, users need to implement the server.
121  *
122  * @param struct ip_addr *ip : ip address of server.
123  * @param uint16_t port : port used by server.
124  *
125  * @return true : succeed
126  * @return false : fail
127  */
128 bool espconn_mesh_server_init(struct ip_addr *ip, uint16_t port);
129 
130 /**
131  * @brief Get the information of mesh node.
132  *
133  * @param enum mesh_node_type typ : mesh node type.
134  * @param uint8_t **info : the information will be saved in *info.
135  * @param uint8_t *count : the node count in *info.
136  *
137  * @return true : succeed
138  * @return false : fail
139  */
141  uint8_t **info, uint8_t *count);
142 
143 /**
144  * @brief Set WiFi cryption algrithm and password for mesh node.
145  *
146  * @attention The function must be called before espconn_mesh_enable.
147  *
148  * @param AUTH_MODE mode : cryption algrithm (WPA/WAP2/WPA_WPA2).
149  * @param uint8_t *passwd : password of WiFi.
150  * @param uint8_t passwd_len : length of password (8 <= passwd_len <= 64).
151  *
152  * @return true : succeed
153  * @return false : fail
154  */
155 bool espconn_mesh_encrypt_init(AUTH_MODE mode, uint8_t *passwd, uint8_t passwd_len);
156 /**
157  * @brief Set prefix of SSID for mesh node.
158  *
159  * @attention The function must be called before espconn_mesh_enable.
160  *
161  * @param uint8_t *prefix : prefix of SSID.
162  * @param uint8_t prefix_len : length of prefix (0 < passwd_len <= 22).
163  *
164  * @return true : succeed
165  * @return false : fail
166  */
167 bool espconn_mesh_set_ssid_prefix(uint8_t *prefix, uint8_t prefix_len);
168 
169 /**
170  * @brief Set max hop for mesh network.
171  *
172  * @attention The function must be called before espconn_mesh_enable.
173  *
174  * @param uint8_t max_hops : max hop of mesh network (1 <= max_hops < 10, 4 is recommended).
175  *
176  * @return true : succeed
177  * @return false : fail
178  */
179 bool espconn_mesh_set_max_hops(uint8_t max_hops);
180 
181 /**
182  * @brief Set group ID of mesh node.
183  *
184  * @attention The function must be called before espconn_mesh_enable.
185  *
186  * @param uint8_t *grp_id : group ID.
187  * @param uint16_t gid_len: length of group ID, now gid_len = 6.
188  *
189  * @return true : succeed
190  * @return false : fail
191  */
192 bool espconn_mesh_group_id_init(uint8_t *grp_id, uint16_t gid_len);
193 
194 /**
195  * @brief Set the curent device type.
196  *
197  * @param uint8_t dev_type : device type of mesh node
198  *
199  * @return true : succeed
200  * @return false : fail
201  */
202 bool espconn_mesh_set_dev_type(uint8_t dev_type);
203 /**
204  * @brief Get the curent device type.
205  *
206  * @param none
207  *
208  * @return device type
209  */
210 uint8_t espconn_mesh_get_dev_type();
211 
212 /**
213  * @brief Try to establish mesh connection to server.
214  *
215  * @attention If espconn_mesh_connect fail, returns non-0 value, there is no connection, so it
216  * won't enter any espconn callback.
217  *
218  * @param struct espconn *usr_esp : the network connection structure, the usr_esp to
219  * listen to the connection
220  *
221  * @return 0 : succeed
222  * @return Non-0 : error code
223  * - ESPCONN_RTE - Routing Problem
224  * - ESPCONN_MEM - Out of memory
225  * - ESPCONN_ISCONN - Already connected
226  * - ESPCONN_ARG - Illegal argument, can't find the corresponding connection
227  * according to structure espconn
228  */
229 int8_t espconn_mesh_connect(struct espconn *usr_esp);
230 
231 /**
232  * @brief Disconnect a mesh connection.
233  *
234  * @attention Do not call this API in any espconn callback. If needed, please use system
235  * task to trigger espconn_mesh_disconnect.
236  *
237  * @param struct espconn *usr_esp : the network connection structure
238  *
239  * @return 0 : succeed
240  * @return Non-0 : error code
241  * - ESPCONN_ARG - illegal argument, can't find the corresponding TCP connection
242  * according to structure espconn
243  */
244 
245 int8_t espconn_mesh_disconnect(struct espconn *usr_esp);
246 
247 /**
248  * @brief Get current mesh status.
249  *
250  * @param null
251  *
252  * @return the current mesh status, please refer to enum mesh_status.
253  */
254 int8_t espconn_mesh_get_status();
255 
256 /**
257  * @brief Send data through mesh network.
258  *
259  * @attention Please call espconn_mesh_sent after espconn_sent_callback of the pre-packet.
260  *
261  * @param struct espconn *usr_esp : the network connection structure
262  * @param uint8 *pdata : pointer of data
263  * @param uint16 len : data length
264  *
265  * @return 0 : succeed
266  * @return Non-0 : error code
267  * - ESPCONN_MEM - out of memory
268  * - ESPCONN_ARG - illegal argument, can't find the corresponding network transmission
269  * according to structure espconn
270  * - ESPCONN_MAXNUM - buffer of sending data is full
271  * - ESPCONN_IF - send UDP data fail
272  */
273 int8_t espconn_mesh_sent(struct espconn *usr_esp, uint8 *pdata, uint16 len);
274 
275 /**
276  * @brief Get max hop of mesh network.
277  *
278  * @param null.
279  *
280  * @return the current max hop of mesh
281  */
282 uint8_t espconn_mesh_get_max_hops();
283 
284 /**
285  * @brief To enable mesh network.
286  *
287  * @attention 1. the function should be called in user_init.
288  * @attention 2. if mesh node can not scan the mesh AP, it will be isolate node without trigger enable_cb.
289  * user can use espconn_mesh_get_status to get current status of node.
290  * @attention 3. if user try to enable online mesh, but node fails to establish mesh connection
291  * the node will work with local mesh.
292  *
293  * @param espconn_mesh_callback enable_cb : callback function of mesh-enable
294  * @param enum mesh_type type : type of mesh, local or online.
295  *
296  * @return null
297  */
298 void espconn_mesh_enable(espconn_mesh_callback enable_cb, enum mesh_type type);
299 
300 /**
301  * @brief To disable mesh network.
302  *
303  * @attention When mesh network is disabed, the system will trigger disable_cb.
304  *
305  * @param espconn_mesh_callback disable_cb : callback function of mesh-disable
306  * @param enum mesh_type type : type of mesh, local or online.
307  *
308  * @return null
309  */
311 
312 /**
313  * @brief To print version of mesh.
314  *
315  * @param null
316  *
317  * @return null
318  */
320 
321 /**
322  * @brief To get AP around node.
323  *
324  * @attention User can get normal AP or mesh AP using the function.
325  * If user plans to get normal AP, he/she needs to clear grp_set flag in para.
326  * If user plans to get mesh AP, he/she needs to set grp_set and grp_id;
327  *
328  * @param struct mesh_scan_para_type *para : callback function of mesh-disable
329  *
330  * @return null
331  */
332 void espconn_mesh_scan(struct mesh_scan_para_type *para);
333 /**
334  * @}
335  */
336 
337 #ifdef __cplusplus
338 }
339 #endif
340 
341 #endif
void espconn_mesh_print_ver()
To print version of mesh.
uint8_t grp_id[ESP_MESH_GROUP_ID_LEN]
Definition: mesh.h:72
mesh_node_type
Definition: mesh.h:64
Definition: mesh.h:43
#define ESP_MESH_GROUP_ID_LEN
Definition: mesh.h:34
bool espconn_mesh_get_router(struct station_config *router)
Get the information of router used by mesh network.
unsigned short uint16
Definition: c_types.h:50
int8_t espconn_mesh_get_status()
Get current mesh status.
bool espconn_mesh_group_id_init(uint8_t *grp_id, uint16_t gid_len)
Set group ID of mesh node.
void espconn_mesh_enable(espconn_mesh_callback enable_cb, enum mesh_type type)
To enable mesh network.
bool espconn_mesh_encrypt_init(AUTH_MODE mode, uint8_t *passwd, uint8_t passwd_len)
Set WiFi cryption algrithm and password for mesh node.
void(* espconn_mesh_callback)()
Definition: mesh.h:36
bool espconn_mesh_local_addr(struct ip_addr *ip)
Check whether the IP address is mesh local IP address or not.
espconn_mesh_scan_callback usr_scan_cb
Definition: mesh.h:71
void(* espconn_mesh_scan_callback)(void *arg, int8_t status)
Definition: mesh.h:37
mesh_type
Definition: mesh.h:39
unsigned char uint8
Definition: c_types.h:45
void espconn_mesh_disable(espconn_mesh_callback disable_cb)
To disable mesh network.
int8_t espconn_mesh_disconnect(struct espconn *usr_esp)
Disconnect a mesh connection.
uint8_t espconn_mesh_get_max_hops()
Get max hop of mesh network.
void espconn_mesh_scan(struct mesh_scan_para_type *para)
To get AP around node.
bool espconn_mesh_server_init(struct ip_addr *ip, uint16_t port)
Set server setup by user.
uint8_t espconn_mesh_get_dev_type()
Get the curent device type.
bool espconn_mesh_set_ssid_prefix(uint8_t *prefix, uint8_t prefix_len)
Set prefix of SSID for mesh node.
mesh_status
Definition: mesh.h:56
int8_t espconn_mesh_connect(struct espconn *usr_esp)
Try to establish mesh connection to server.
bool espconn_mesh_get_node_info(enum mesh_node_type type, uint8_t **info, uint8_t *count)
Get the information of mesh node.
int8_t espconn_mesh_sent(struct espconn *usr_esp, uint8 *pdata, uint16 len)
Send data through mesh network.
bool espconn_mesh_set_max_hops(uint8_t max_hops)
Set max hop for mesh network.
bool espconn_mesh_set_router(struct station_config *router)
Set the information of router used by mesh network.
enum _auth_mode AUTH_MODE
bool espconn_mesh_set_dev_type(uint8_t dev_type)
Set the curent device type.