当前位置:网站首页>Fast implementation of thread mesh networking
Fast implementation of thread mesh networking
2022-06-27 06:24:00 【shine_ blink】
2.4G Single point to single point communication
One 、 Realization function
This chapter implements two Core Equipment communication , One of the devices is server、 Another device is client. whenever client The device presses... On the circuit board BTN1 Keystrokes , Will send to server Upload data . When server received client The data on the circuit board will also be switched after passing the verification LED1 On and off state of , meanwhile client I will also receive server Orders issued ,client After the verification command passes, the... On the circuit board will also be switched LED1 On and off state of .
in addition server and client On the circuit board LED2 Are used to indicate the connection status , Only when both sides LED2 When both lights are on at the same time , It means that the two can start normal communication .
Be careful : because Core Inside comes 2.4G Wireless capabilities , Therefore, the wireless communication function of this chapter can be realized without external devices or modules . But if it's used 2.4G function ,Core Of Ble Bluetooth features and USB The function cannot be used , Developers need to pay attention to this .
Two 、 An overview of communication principles
Core In the bottom layer, based on Thread The development of wireless network COAP agreement , In fact, it is a multipoint mesh Network communication protocol , But the point-to-point communication in this example only realizes two nodes .
By understanding Thread The mechanism of wireless network should know , stay Thread There are three types of nodes in :Leader,Router,EndDevice. But please don't compare them with COAP In the agreement server,client Conceptual confusion . Because in Thread Network server and client The node may be Leader,Router,EndDevice Any of the three , And it's not fixed , Will change with the dynamic changes of the network , And this also reflects Thread The power of the network , That is, if a routing node in the network has a problem , Other nodes in the network will dynamically adjust their roles from the network .
Server and Client Schematic diagram of communication between
Communication restrictions
There can only be one in a network server, But there can be hundreds client.
therefore server It can be used as the gateway of the whole network , To connect to other external networks such as wifi,NBIOT,LORA etc. .
PanID And frequency Channel To determine the mesh The uniqueness of the network .
Based on this , We can design PanID And frequency Channel Different Mesh The same physical space exists in the network .
client The name of must be 8 Characters ,client to server The data length of must be 8 Bytes ,server Issue to client The command length of must also be 8 Bytes .( commonly 8 The space of bytes is enough for uploading sensor data or issuing control commands .)
server Issue to client Your orders will not be immediately client received , But wait until client Upload data to next time server when ,server The command data will be attached and sent to during the response client. So if you want to make client Receive orders as soon as possible ,client Can add to server Frequency of uploading data .
There are three reasons for this :(1) If client Nodes are low-power dormant sensor devices , Probably won't be online most of the time , therefore server It is impossible to send data in real time
(2) If client Nodes are dynamically connected to and disconnected from the network ,server It is also impossible to establish a stable connection with such nodes (3)
Core Our internal resources are limited , If for each client It takes a lot of time for each node to maintain a connection Ram.
Client In the client code ClientName The name variable can be arbitrary 8 Characters ( Must be 8 individual ), For example, in this case ClientName The name is "Client01".
Be careful :ClientName yes Client In the network Server The only identity recognized ID.
3、 ... and 、Client The complete code of the terminal
--PanID and Channel To determine the mesh The uniqueness of the network
PanID = 0x1234 --16 An integer
Channel = 11 -- Choice range (11~26)
MyRole = "Client" -- Defined as client role
LIB_MeshConfig(MyRole,PanID,Channel) -- Start and join mesh The Internet
--client Own name "Client01" It has to be for 8 Characters , And and server The end mentioned client The names should be the same
ClientName = "Client01" --ClientName yes Client In the network Server The only identity recognized ID
LIB_GpioOutputConfig("D8","STANDARD") --LED1
LIB_GpioOutputConfig("D9","STANDARD") --LED2
LIB_GpioWrite("D8",1) -- destroy
LIB_GpioWrite("D9",1) -- destroy
-- Set button 1( Occupy D0 mouth , Low level active )
LIB_ButtonConfig("BTN1","D10","L")
net_state = 0
-- Start the big cycle
while(GC(1) == true)
do
-- Network state led instructions
net_state = LIB_MeshClientNetStateQuery()
if net_state == 2 then --client Joined mesh Net and found server
LIB_GpioWrite("D9",0) --LED2 bright
else
LIB_GpioWrite("D9",1) --LED2 destroy
end
-- If BTN1 Press the key briefly and client Has joined mesh And found server, As to the Server Upload data
key = LIB_ButtonQuery("BTN1")
if key == 1 and net_state == 2 then
data = {
0xA1,0x00,0x00,0x00,0x00,0x00,0x00,0x00}
LIB_MeshClientSendData(ClientName,data)
end
-- Query whether received from server Issued 8 Byte command , And analyze
recv_flag, cmd = LIB_MeshClientRecvCommand()
if recv_flag == 1 and #cmd == 8 then
if cmd[1] == 0x01 then -- Here we only analyze server The first byte of the command issued
LIB_GpioToggle("D8") --LED1 On or off switch
end
end
end
边栏推荐
猜你喜欢
JVM class loading mechanism
How to check the frequency of memory and the number of memory slots in CPU-Z?
汇编语言-王爽 第9章 转移指令的原理-笔记
汇编语言-王爽 第8章 数据处理的两个基本问题-笔记
The restart status of the openstack instance will change to the error handling method. The openstack built by the container restarts the compute service method of the computing node and prompts the gi
研究生数学建模竞赛-无人机在抢险救灾中的优化应用
Proxy-Reflect使用详解
427- binary tree (617. merge binary tree, 700. search in binary search tree, 98. verify binary search tree, 530. minimum absolute difference of binary search tree)
KubeSphere 集群配置 NFS 存储解决方案-收藏版
thrift
随机推荐
Sqlsever 字段相乘后保留2位小数
JVM tuning ideas
The risk of multithreading -- thread safety
HTAP 深入探索指南
Kubesphere cluster configuration NFS storage solution - favorite
Go log -uber open source library zap use
multiprocessing.pool详解
Program ape learning Tiktok short video production
日期 数据库日期 字符串 之间互相转换
427-二叉树(617.合并二叉树、700.二叉搜索树中的搜索、98. 验证二叉搜索树、530.二叉搜索树的最小绝对差)
Assembly language - Wang Shuang Chapter 9 Principles of transfer instructions - Notes
Proxy-Reflect使用详解
[cultivation system] common regular expressions
The SCP command is used in the expect script. The perfect solution to the problem that the SCP command in the expect script cannot obtain the value
Crawler learning 5--- anti crawling identification picture verification code (ddddocr and pyteseract measured effect)
网关状态检测 echo request/reply
[QT dot] realize the watchdog function to detect whether the external program is running
C Primer Plus 第11章_字符串和字符串函数_代码和练习题
JVM garbage collection mechanism
研究生数学建模竞赛-无人机在抢险救灾中的优化应用