30a-Esp8266 Mesh User Guide en PDF
30a-Esp8266 Mesh User Guide en PDF
Version 1.2
Copyright © 2016
About This Guide
This document introduces users to ESP8266 mesh network, including the following topics:
Introduces the mesh header format and details about the fields
Chapter 2 Mesh Header
and codes.
Chapter 3 API Reference Introduces the data structures and the APIs.
Chapter 4 Sample Code Provides some sample codes for mesh development.
Release Notes
2016.01 V1.2
Chapter 1 and Chapter 3 updated.
📖 Note:
This current version is an early release to support initial product developers. The contents are subject to
change without advance notice.
Table of Contents
1. Overview .......................................................................................................................... 1
1. Overview
The development of the Internet of Things (IoT) requires an increasing number of nodes to
connect to the internet. However, only limited number (usually fewer than 32) of nodes can
directly connect to the same router. There are two solutions currently available for this
problem.
• Super router: the higher capacity router allows more nodes to directly connect to it.
• Mesh network: the nodes can establish a network and forward packets.
ESP8266 uses mesh network as shown in Figure 1-1. As a result, a large number of nodes
can connect to the internet without any improvements of the current router.
Up to 87 Wi-Fi devices.
"
1.1. Concepts
IOT Espressif App
IOT Espressif App (hereinafter referred to as IOT App) is a mobile application developed by
Espressif. It can realize the local and remote control of Wi-Fi devices, including smart lights
and smart plugs.
ESP-Touch
ESP-Touch is a technology developed by Espressif to connect Wi-Fi devices to the router.
Smart Config Mode for ESP-Touch
Users can configure Wi-Fi devices by ESP-Touch only when the devices are in Smart
Config Mode. This status is called ESP-Touch status. For details of configuration, please
refer to 1.2. Network Structure.
Local Device
As shown in Figure 1-2, if users configure a device to connect to the router via ESP-Touch
but not activate it on the server-side, then the device is a local device.
Device
Router
Mobile App
Local Network
"
Cloud Device
As shown in Figure 1-3, if users configure a device to connect to the router via ESP-Touch
and activate it on the server-side, then the device is a cloud device.
Room Office
Router A Router B
Phone
Server
Cloud Network
"
• Online status: The device is a local device or cloud device; the device and IOT App
connect to the same router.
• Offline status: The device is a cloud device that does not connect to the router.
Cloud device ✔ ✔ ✔
Local device ❌ ✔ ❌
Internet
Non-root nodes
Dev-3-1 Dev-3-2 …… Dev-3-n
• The node that directly connects to the router is the root node and others are non-root
nodes. For more information, please refer to 1.2.3 Network Node.
• Online-Mesh: When the router connects to the internet, you can use IOT App to
control the Cloud Devices.
• Local-Mesh: You can only control the Local Devices through the router.
• It forwards the packets from server, mobile apps and its child nodes.
Or,
A Non-root Node
• Non-leaf node: It receives and sends packets, as well as forwards the packets from its
parent node and child nodes.
• Leaf node: It only receives and sends packets, but does not forward packets.
2. Mesh Header
2.1. Mesh Header Format
Figure 2-1 shows the mesh header format.
0 1 2 3
ver o flags proto len
dst_addr
src_addr
ot_len
option_list
Packet Body
"
bit 0 1 2 3 4
5 bits CP CR resv
resv Reserved.
bit 0 1 2 3 4 5 6 7
D • 0: downwards
• 1: upwards
enum mesh_usr_proto_type {
M_PROTO_NONE = 0, // used to deliver mesh management packet
M_PROTO_HTTP, // user data in HTTP protocol format
M_PROTO_JSON, // user data in JSON protocol format
M_PROTO_MQTT, // user data in MQTT protocol format
M_PROTO_BIN, // user data is binary stream
};
len 2 Bytes The length of mesh packet in bytes (mesh header included).
Destination address
dst_addr 6 Bytes • Bcast or mcast packet: dst_addr represents the bcast or mcast
MAC address.
Source address
2.2.2. Example
Flow Request Packet
"
head.proto.D 1 Upwards.
"
head.proto.D 0 Downwards.
3. API Reference
3.1. Data Structure
3.1.1. Mesh Header Format
struct mesh_header_format {
uint8_t ver:2; // version of mesh
uint8_t oe: 1; // option flag
} __packed;
📖 Note:
For the packet APIs, please refer to ESP8266 Non-OS SDK API Guide via the following link:
http://www.espressif.com/en/support/download/documents#overlay=en/admin/content.
4. Sample Code
4.1. Device
For details, please refer to:
ESP8266_MESH_DEMO/blob/master/mesh_demo/demo/mesh_demo.c.
return;
}
if (espconn_mesh_set_usr_data(mesh_header,
resp_json_packet_body, resp_data_len))
{
free(mesh_header);
return;
}
// sent control packet
return;
}
topo_option = (struct mesh_header_option_format
*)espconn_mesh_create_option(
M_O_TOPO_REQ, dev_mac, sizeof(dev_mac));
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;
}
// send packet of getting topology
espconn_mesh_sent(esp, mesh_header, mesh_header->len);
free(mesh_header);
}
{
/*Add your codes to check parameter*/
uint16_t oidx = 1;
struct mesh_header_format *mesh_header = NULL;
struct mesh_header_option_format *topo_option = NULL;
/* you need parse all the options one by one in the packet header
*/
while(espconn_mesh_get_option(mesh_header, M_O_TOPO_RESP,
oidx++, &topo_option)) {
4.5. Dev-App
For details of the example codes, please refer to:
• ESP8266_MESH_DEMO/blob/master/mesh_demo/include/user_config.h
• ESP8266_MESH_DEMO/blob/master/mesh_demo/demo/mesh_demo.c