30a Esp8266 Mesh User Guide Cn

User Manual:

Open the PDF directly: View PDF PDF.
Page Count: 19

!
ESP8266!
Mesh !
 1.2!
 © 2016

 ESP8266 Mesh 
󰃕
󰓍

1
󰉀
󰉀 ESP-Mesh
2
Mesh 
 Mesh 
3
API 
 API
4

Mesh 


2015.07
V1.0
2015.09
V1.1
2016.01
V1.2
📖 󰃕
󰀉󰀉󰉘

1. 󰉀"1!..................................................................................................................................
1.1. "1!..............................................................................................................................
1.2. "3!..............................................................................................................................
1.2.1. !3 .................................................................................................................
1.2.2. !3 ..............................................................................................................
1.2.3. !4 .................................................................................................................
2. Mesh "5!.....................................................................................................................
2.1. Mesh "5!................................................................................................................
2.2. Mesh 󰉍󰒲"7!...........................................................................................................................
2.2.1. !7 .................................................................................................................
2.2.2. !8 ........................................................................................................................
3. API "10!.........................................................................................................................
3.1. "10!............................................................................................................................
3.1.1. Mesh !10 ..................................................................................................
3.1.2. Mesh 󰉍󰒲!10 ...........................................................................................
3.1.3. Mesh 󰉍󰒲!11 ......................................................................................................
3.1.4. Mesh 󰉍󰒲!11 ..............................................................................................
3.1.5. Mesh 󰃤!11 ......................................................................................................
3.1.6. Mesh 󰃤!11 ..............................................................................................
3.1.7. Mesh 󰃤!11 .......................................................................................
3.2.  API"11!.........................................................................................................................
4. "12!.........................................................................................................................
4.1. 󰂢"12!...................................................................................................................................
4.2. "12!....................................................................................................................
4.3. "13!....................................................................................................................
4.4. 󰁵"14!....................................................................................................................
4.5. Dev-App"15............................................................................................................................
1. 󰉀
1. 󰉀
󰑌󰁣󰈦󰉜󰆡󰐵󰉘
 32 󰁣󰊸󰆡
󰌓󰏰󰓍󰁵
󰅼󰆡󰆡
Mesh 󰏶󰇩
ESP8266  Mesh  1-1 󰈰󰑲󰁞󰆡󰌂
󰈴
"
1-1. ESP-Mesh 
1.1. 
IOT Espressif App
IOT Espressif App IOT App󰌏 App Wi-Fi
󰂢󰉹󰈰 Wi-Fi 󰂢
ESP-Touch
ESP-Touch 󰌏 Wi-Fi 󰂢󰈴󰆡
ESP-Touch Smart Config 
󰂢 Smart Config  ESP-Touch 󰋉󰈰 ESP-Touch
󰋉󰃘“1.2 
Up to 87 Wi-Fi devices.
Up to 5-level mesh network.
Up to 100 m for a single hop.
Espressif!/!2016.04
116
1. 󰉀
󰂢
 1-2 󰂢󰉘󰈧 ESP-Touch 󰋉󰆡
󰃇󰂢󰂢
"
1-2. 
󰂢
 1-3 󰂢󰉘󰈧 ESP-Touch 󰋉󰆡󰃇󰂢
󰂢
"
1-3. 
 IOT App 
󰂢󰂢󰂢 IOT App 󰈴󰆡
Device
Mobile App
Router
Local Network
Room
Device
Phone
Office
Server
Mobile App
Router B
Cloud Network
Router A
Espressif!/!2016.04
216
1. 󰉀
󰂢󰂢󰂢󰂢 IOT App 󰈴󰆡
󰂢󰂢󰆡
󰂢
1.2. 
1.2.1. 
Mesh  ESP-Touch 󰋉 Mesh 󰂢
 Wi-Fi AP
1.2.2. 
Mesh  1-4 
"
1-4. Mesh 
󰆡󰒌󰃈󰃘“1.2.3 
󰂢



󰂢
󰂢
Internet
Dev2-1
Dev-3-1
Dev-m-1
Dev 2-2
Dev-3-2
Dev-m-2
Dev 2-n
Dev-3-n
Dev-m-n
……
……
……
Dev1-1
Router
Online-Mesh Local-Mesh
Root node
Non-root nodes
Espressif!/!2016.04
316
1. 󰉀
Online-Mesh󰆡󰈴󰉘󰈧󰂢
Local-Mesh󰉘󰈧󰆡󰂢
1.2.3. 
 Mesh 

󰉇
󰇩
󰒌
󰒌󰉇󰇩
󰉇󰇩!
Espressif!/!2016.04
416
2. Mesh 
2. Mesh 
2.1. Mesh 
Mesh  2-1 
"
2-1. Mesh 
Mesh 󰀓 2-1 
ver oflags proto len
ot_len
option_list
src_addr
dst_addr
0 1 2 3
Packet Body
󰀓 2-1. Mesh 

󰏪
󰃕
ver
2 
Mesh 
o
1 
󰉍󰒲
flags
5 
FP
󰌂
FR
󰌂󰃘
CP CR resv
0 1 2 3 4bit
Espressif!/!2016.04
516
2. Mesh 
resv

proto
8 
D
!
0!
1
P2P

󰂔
󰂔
mesh_usr_proto_type 的定如下:!
enum mesh_usr_proto_type {!
M_PROTO_NONE = 0, // 󰉇 Mesh !
M_PROTO_HTTP, // HTTP !
M_PROTO_JSON, // JSON !
M_PROTO_MQTT, // MQTT !
M_PROTO_BIN, // 󰈱!
};
len
2 
Mesh 󰏪 Mesh 
dst_addr
6 
!
proto.D = 0 proto.P2P = 1dst_addr 󰀓󰂢 MAC
!
Bcast mcast packetdst_addr 󰀓 bcast  mcast MAC
!
proto.D = 1 proto.P2P = 0dst_addr 󰀓
IP 
src_addr
6 
!
proto.P2P = 1src_addr 󰀓󰂢 MAC !
Bcast mcast packetsrc_addr 󰀓󰂢 MAC !
proto.D = 1src_addr 󰀓󰂢 MAC !
proto.D = 0 且 forward packet into meshsrc_addr 󰀓
 IP 
ot_len
󰉍󰒲󰏪󰇞

󰏪
󰃕
DP2P protocol
01234567bit
Espressif!/!2016.04
616
2. Mesh 
2.2. Mesh 󰉍󰒲
2.2.1. 
Mesh 󰉍󰒲 mesh_option_type 
enum mesh_option_type {
M_O_FLOW_REQ = 0,// 󰌂󰃘󰉍󰒲
M_O_FLOW_RESP, // 󰌂󰉍󰒲
M_O_ROUTER_SPREAD, // 󰆡󰉍󰒲
M_O_ROUTE_ADD, // 󰆡󰀓󰈴 Mesh󰉍󰒲
M_O_ROUTE_DEL, // 󰆡󰀓󰉆 Mesh󰉍󰒲
M_O_TOPO_REQ, // 󰃘󰉍󰒲
M_O_TOPO_RESP, // 󰉍󰒲
M_O_MCAST_GRP, // 󰀓
M_O_MESH_FRAG, // Mesh 󰉍󰒲
M_O_USR_FRAG, // 
M_O_USR_OPTION, // 󰉍󰒲
};
option_list
otype
1 
󰉍󰒲
olen
1 
󰉍󰒲󰏪
ovlaue

󰉍󰒲

󰏪
󰃕
󰉍󰒲󰀓!
option-1 option-2 option-n……
otype olen ovalue
Espressif!/!2016.04
716
2. Mesh 
2.2.2. 
󰌂󰃘
"
󰀓 2-2. Mesh 

󰉍󰒲󰏪
󰃕

M_O_FLOW_REQ
2 
󰌂󰃘
M_O_FLOW_RESP
6 
󰌂
M_O_ROUTER_SPRE
AD
106 
󰆡
M_O_ROUTE_ADD
6*n+2 
󰈴 Mesh
󰆡󰀓
M_O_ROUTE_DEL
6*n+2 
󰉆 Mesh 
󰆡󰀓
M_O_TOPO_REQ
8 
 Mesh 

M_O_TOPO_RESP
6*n+2 
 Mesh 

0x01
otype
0x06
olen ovalue
congest capacity
0x04
otype
length
olen ovalue
MAC address list
0x00
otype
0x02
olen ovalue
0x03
otype
length
olen ovalue
MAC address list
0x06
otype
length
olen ovalue
MAC address list
0x02
otype
0x6A
olen ovalue
Router information
0x05
otype
0x06
olen ovalue
MAC address of the device searched
󰀓 2-3. 󰌂󰃘

󰃕
head.ver
00
Mesh  00
head.O
1
󰉍󰒲
head.flags.FP
0
󰌂
head.flags.FR
0
󰌂󰃘
head.flags.resv
000

head.proto.D
1

head.proto.P2P
0

head.proto.protocol
000000
Mesh 
Espressif!/!2016.04
816
2. Mesh 
󰌂
"
head.len
0x0014
󰏪 20 
head.dst_addr
18 FE 34 A5 3B AD
󰂢 MAC 
head.src_addr
18 FE 34 A2 C7 76
󰂢 MAC 
head.ot_len
0x0004
󰉍󰒲󰏪 0x0004
head.option_list[0].otype
0x00
M_FLOW_REQ
head.option_list[0].olen
0x02
󰉍󰒲󰏪 0x02

󰃕
󰀓 2-4. 󰌂

󰃕
head.ver
00
Mesh  00
head.O
1
󰉍󰒲
head.flags.FP
0
󰌂
head.flags.FR
0
󰌂󰃘
head.flags.resv
000

head.proto.D
0

head.proto.P2P
0

head.proto.protocol
000000
Mesh 
head.len
0x0015
󰏪 21 
head.dst_addr
18 FE 34 A2 C7 76
󰂢 MAC 
head.src_addr
18 FE 34 A5 3B AD
󰂢 MAC 
head.ot_len
0x0008
󰉍󰒲󰏪 0x0008
head.option_list[0].otype
0x01
M_FLOW_RESP
head.option_list[0].olen
0x06
󰉍󰒲󰏪 0x06
head.option_list[0].ovalue
0x01
󰉍󰒲 0x00000001󰌂󰌂
0x00000001
Espressif!/!2016.04
916
3. API 
3. API 
3.1. 
3.1.1. Mesh 
struct mesh_header_format {
uint8_t ver:2; // Mesh 
uint8_t oe: 1; // 󰉍󰒲
uint8_t fp: 1; // 󰌂
uint8_t fr: 1; // 󰌂󰃘
uint8_t rsv:3; // 
struct {
uint8_t d: 1; // 12
uint8_t p2p:1; // 
uint8_t protocol:6; // 󰂔
} proto;
uint16_t len; // 󰏪 Mesh

uint8_t dst_addr[ESP_MESH_ADDR_LEN]; // 
uint8_t src_addr[ESP_MESH_ADDR_LEN]; // 
struct mesh_header_option_header_type option[0]; // Mesh 󰉍󰒲
} __packed;
3.1.2. Mesh 󰉍󰒲
struct mesh_header_option_header_type {
uint16_t ot_len; // 󰉍󰒲󰏪
struct mesh_header_option_format olist[0]; // 󰉍󰒲󰀓
} __packed;
Espressif / 2016.04
10 16
3. API 
3.1.3. Mesh 󰉍󰒲
struct mesh_header_option_format {
uint8_t otype; // 󰉍󰒲
uint8_t olen; // 󰉍󰒲󰏪
uint8_t ovalue[0]; // 󰉍󰒲
} __packed;
3.1.4. Mesh 󰉍󰒲
struct mesh_header_option_frag_format {
uint16_t id; //  ID
struct {
uint16_t resv:1; // 
uint16_t mf:1; // 
uint16_t idx:14; // 
} offset;
} __packed;
3.1.5. Mesh 󰃤
typedef void (* espconn_mesh_callback)(int8_t result);
3.1.6. Mesh 󰃤
typedef void (* espconn_mesh_scan_callback)(void *arg, int8_t
status);
3.1.7. Mesh 󰃤
typedef void (* espconn_mesh_usr_callback)(void *arg);
3.2.  API
📖 󰃕
󰃘 ESP8266 Non-OS SDK API Guide󰍿"
http://www.espressif.com/zh-hans/support/download/documents
Espressif / 2016.04
11 16
4. 
4. 
4.1. 󰂢
󰃈󰃘"
ESP8266_MESH_DEMO/blob/master/mesh_demo/demo/mesh_demo.c
4.2. 
void controller_entrance(Parameter list)
{
/**/
/**/
uint8_t json_control_data[] = {/**/};
uint16_t control_data_len = sizeof(json_control_data)
struct mesh_header_format *mesh_header = NULL;
/* src_addr  IP 󰂢
0󰂢󰀉󰃘*/
uint8_t src_addr[] = {0,0,0,0,0,0},
dst_addr[] = {xx,xx,xx,xx,xx,xx};
mesh_header = (struct mesh_header_format
*)espconn_mesh_create_packet(dst_addr, src_addr, false, true,
M_PROTO_JSON, control_data_len,
false, 0, false, 0, false, 0, 0);
if (!mesh_header)
{
printf(“alloc resp packet fail\n”);
return;
}
if (espconn_mesh_set_usr_data(mesh_header,
resp_json_packet_body, resp_data_len))
{
printf(“set user data fail\n”);
Espressif / 2016.04
12 16
4. 
free(mesh_header);
return;
}
// 󰉇
espconn_mesh_sent(esp, mesh_header, mesh_header->len);
free(mesh_header);
}
4.3. 
void topology_entrance(Parameter list)
{
/**/
/**/
bool res;
struct mesh_header_format *mesh_header = NULL;
struct mesh_header_option_format *topo_option = NULL;
uint8_t src_addr[] = {0,0,0,0,0,0};
uint8_t dst_addr[] = {xx,xx,xx,xx,xx,xx}; //󰂢 MAC 
uint8_t dev_mac[6] = {xx,xx,xx,xx,xx,xx}; //0 󰀓󰂢
uint16_t ot_len = sizeof(*topo_option) + sizeof(struct
mesh_header_option_header_type) + sizeof(dev_mac);
mesh_header = (struct mesh_header_format
*)espconn_mesh_create_packet(
dst_addr, src_addr, false, true, M_PROTO_NONE, 0,
true, ot_len, false, 0, false, 0, 0);
if (!mesh_header) {
printf(“alloc resp packet fail\n”);
return;
}
topo_option = (struct mesh_header_option_format
*)espconn_mesh_create_option(
M_O_TOPO_REQ, dev_mac, sizeof(dev_mac));
Espressif / 2016.04
13 16
4. 
if (!topo_option) {
printf(“alloc topo option fail\n”);
free(mesh_header);
return;
}
res = espconn_mesh_add_option(mesh_header, topo_option);
free(topo_option);
if (res) {
printf(“add topo option fail\n”);
free(mesh_header);
return;
}
// 󰉇
espconn_mesh_sent(esp, mesh_header, mesh_header->len);
free(mesh_header);
}
4.4. 󰁵
void topology_parser_entrance(uint8_t *topo_resp, uint16_t len)
{
/**/
uint16_t oidx = 1;
struct mesh_header_format *mesh_header = NULL;
struct mesh_header_option_format *topo_option = NULL;
mesh_header = (struct mesh_header_format *)topo_resp;
if (!mesh_header->oe) {
printf(“no option exist\n”);
return;
}
/* 󰑲󰁞󰉒󰁵󰉍󰒲 */
while(espconn_mesh_get_option(mesh_header, M_O_TOPO_RESP,
oidx++, &topo_option)) {
Espressif / 2016.04
14 16
4. 
uint16_t dev_count = topo_option->olen/6;
process_dev_list(topo_option->ovalue, dev_count);
}
}
4.5. Dev-App
󰃈
ESP8266_MESH_DEMO/blob/master/mesh_demo/include/user_config.h
ESP8266_MESH_DEMO/blob/master/mesh_demo/demo/mesh_demo.c
Espressif / 2016.04
15 16
󰄲
 URL 󰀉󰉘
󰄯󰄲󰉈󰎁󰉈󰉕󰒌
󰁣
󰄯󰄲󰀉󰄲
󰁻󰂪󰂝󰂝
󰈯󰂝
Wi-Fi  Wi-Fi  Bluetooth SIG 
󰄱

© 2016 󰌏
󰌏 IOT 󰐛
www.espressif.com

Navigation menu