Article Directory
One, States
The status of a node, such as onoff States
,lightness States
二、Bound states
Two interrelated states, such as onoff
and lightness
.
- When the
onoff
value changes from 1 to 0, thelightness
value will become 0 - When the
onoff
value from 0 to 1 whenlightness
the value also changes from 0 to turn off the lights before thelightness
value of - Similarly, when
lightness
values varies between 0 and non-0,onoff
the values will be from 0 to 1.
Three, Messages
After the encryption is complete, sent to the mesh network packet, we also called mesh packet
, mesh command
.
四、Node & Elements
Node represents a complete node or Bluetooth module, and Element represents an operating element in Node.
Node address
One and only oneelement address
Can be one or more- When the
element address
case where a plurality of address which will be continuous - The first
element address
is also calledprimary address
- When the
Node address
And the value ofprimary address
the same.
such as:
- The
element
number of socket products (3 channels) is 3, and 3generic onoff
control commands respectively control the switches of 3 channels; - The
element
number of color temperature lights (CT Light) is 2, 2generic level model
, respectively, corresponding tolightness
andTemp
; - The
element
number of HSL lights (RGB lights) is 3, 3generic level model
corresponding tolightness
,Hue
and respectivelySat
.
When networking:
Node
The number of elements will be reported in the interactive information of the provision flow, such as 2;provisioner
An address will be assignedNode
, such as 0x0002;Node
After receiving it, 0x0002element 1
and 0x0003 will be allocated in orderelement 2
;Provisioner
When the next node is networked, it will be allocated from 0x0004.
五、Publish & Subscribe
Publish
It is Element
the process of sending status of the initiative
- By
Config Model Publication Set
the configuration publish address, command, and parameter setting period publish. - After the publish address is configured, as long as the status changes, Node will automatically execute the publish status action. Whether it needs to be sent periodically depends on the period publish parameter.
Subscribe
Is the Element
process of receiving and processing data
- By
Config Model Subscription Add
,Config Model Subscription Virtual Address Add
like adding commands Subscribe list [] Address Subscribe list[]
Which isgroup address
orvirtual address
can not beunicast address
, nor is 0xffffElement
Receive status message (such as generic onoff status) or control message (such as generic onoff) published by other nodes- The model of
Subscribe list[]
whether or not to process the message determination.
The basis for judging whether to receive and process is:
- Upon receiving
message
thedestination address
non-unicast address
, it is determined whether a corresponding model can be
matched to the address inside the Subscribe list. - Upon receipt
message
ofdestination address
isunicast address
, itself, and it is determinedelement address
whether the match. - When
destination address
is 0xffff, it indicates that meet the judgment conditions.
Six, Security
6.1 Access layer encryption
- Use
app key
ordevice key
the entire access layer (comprising op code, parameters) encrypted - If the model corresponding to the op code is the config model, use it
device key
, otherwise use itapp key
.
6.2 Network layer encryption
- Use
network key
+iv index
to encrypt the entire network layer - The network layer is the packet sent to the mesh network, including source address, destination address, and sequence number.
6.3 app key
- SDK supports 2
app key
(APP_KEY_MAX
) by default . - More
app key
it can be used to manage different levels of security products.
such as
- There are both lights and door locks in the mesh network
- If the security level of the door lock is higher, only certain people can control it
- At this time, you can assign an independent app key to the door lock separately, and ensure that this app key is only known by certain mobile apps (provisioners), and will not be shared during network sharing.
This can increase the security level.
6.4 network key
- SDK supports 2 by default
network key
(NET_KEY_MAX
) - Plurality
network key
may be used to manage a plurality of network.
6.5 Other
For messages that need to be subpackaged, because the payload of the access layer is encrypted when the entire payload is encrypted, it is necessary to receive all packets before decryption and verification can be completed.
七、Sequence Number
Sequence Number referred to SNO
orSEQ
7.1 SNO self-increment judgment
SNO
It will be accumulated every time a command is sent- Making the receiving terminal
SNO
determines the time required is larger than the value already received, and if less then the message is considered invalid
7.2 SNO storage processing
If the transmitting end each transmitting a command to be SNO
stored in the flash, the stored frequency is too high, especially when needed sub transmitted. Due to the limited number of flash reads and writes. So amended to:
- SNO increased
MESH_CMD_SNO_SAVE_DELTA
(default 0x80), only stored once - During power-on initialization, to read the
SNO
plusMESH_CMD_SNO_SAVE_DELTA
(in order to ensure that after power off and on againSNO
is greater than the value already used)
For the specific implementation, please refer to mesh_flash_save_check() and mesh_misc_retrieve() for the handling of MESH_CMD_SNO_SAVE_DELTA.
八、Friendship
Friendship refers to the relationship established between Friend Node
( FN
) and Low Power Node
( LPN
) through the established friend ship flow.
- After the friend ship is successfully established,
LPN
during sleep - When there are nodes send commands to
LPN
time,FN
it will be the first to get this message saved - When
LPN
the wake will be sent POLL command to queryFN
, thenFN
it will send the message to save LPN - In this way, lower power consumption can be achieved. The disadvantage is
LPN
that there is a certain delay in receiving and responding to commands.
Nine, Features
9.1 Relay feature
The main function of Relay relay is to spread the message among the nodes, multi-level hop, and realize the transmission distance of the mesh network is longer.
However, in order to prevent diffusion of the message infinite loop, it does not disappear . So some restrictions are made as follows
- The node receives a valid network message
- First reduce the TTL value of the message by 1, and then relay to send it out
- If the received TTL value is less than or equal to 1, no relay is performed
The introduction of TTL is mainly to control the delay time of the node that finally receives the message within the controllable range.
- The default value of SDK TTL is
TTL_DEFAULT
(0x0A), this macro can be modified - provisioner can also
Config Default TTL Set
configure the maximum is 127
9.2 Proxy feature
Proxy is the protocol used for mobile APP to access the mesh network.
- In the mesh network, APP is also an independent node, with its own Node address.
- The proxy is introduced because most mobile phones currently cannot send broadcast packets fully customized, and cannot always be in the state of monitoring the mesh network (switch to WiFi in the middle, etc.)
- Therefore, the mobile phone APP needs to connect to a node through BLE GATT, and the directly connected node will forward the data after receiving the data from the APP.
- When the directly connected node receives the message replies to the app in the mesh network, it will first reply to the mobile app via GATT according to the proxy protocol
9.3 App direct connection
The APP sends a message to the directly connected node ATT_OP_WRITE_CMD(0x52)
, and the directly connected node responds to the
message to the APP with notify, that is, ATT_OP_HANDLE_VALUE_NOTI
(0x1B).
9.4 Low Power feature
八、Friendship
9.5 Friend feature
八、Friendship
10. Mesh network topology diagram
If you think it’s good, just one click for three consecutive chants (Like+Favorite+Follow)