当前位置:网站首页>Things about Bluetooth development (10) -- getting to know ble for the first time
Things about Bluetooth development (10) -- getting to know ble for the first time
2022-06-11 00:09:00 【yuanyun_ elber】
Actually LE and BR/EDR It's two completely different things , Physical layer channel The number has been halved ,AFH FM algorithm has been improved ,
The application scenarios are different ,LE It is mainly used in the Internet of things , So in terms of design , There are the following considerations :
- Low power consumption , Less data , Based on this consideration , Unlike traditional Bluetooth , A lot of scenarios ,BLE It doesn't depend on the way there are connections , The connectionless mode has low power consumption , Advantages of longer use time , such as BLE Of beacon Technology is a device that sends non connected broadcast packets regularly , Such a node is usually required , Can work for about one to two years . although BR There is also broadcast content , But in BLE In the field of , The importance of broadcasting has been reinforced .
- Because they are all Bluetooth systems , To maximize reuse BR/EDR Things that are , So although LE Physical layer and BR Dissimilarity ,LE Of controller stay core spec Is a separate chapter six , But the architecture of the protocol stack has not changed ,LE host and LE controller The interaction is still through HCI Interface , Packets also use acl data Format , Just one of them CID yes fixed channel Of , That is to say ATT Fixed channel value 4.
- LE The agreement HOST Joined the ATT and GATT The content of , Why add it ? Or because LE Working scene of , Mainly server/client Architecturally , For example, temperature and humidity sensors , You need to upload data to the server regularly , Small amount of data , Time delay is not sensitive , There are many such scenes . So we need to abstract out ATT Such a general specification becomes necessary .
ATT The full name is attribute protocol,attribute The translation is attribute , This and GATT Of characteristic( characteristic ) The concept of is easy to get up .
Simply speaking , Attributes are a basic form of data organization , contain handle,type,value, Any attribute can be passed through handle Go to unique addressing .Type It is defined by the Bluetooth Association UUID, The value range is 0x2800-0x28ff, for instance , Battery service attribute , Its attribute type is ATT_DECL_PRIMARY_SERVICE(0x2800).
Value Represents the value of the property , For example, the attribute value of battery service , Access is readable and defined by the Bluetooth standards organization 0x180f.
ATT Just one. protocol, It is also quite abstract , So the upper layer further defines GATT, Although it's just one more ”G”,
But the meaning is very different , because GATT Already included profile The concept of , Bluetooth profile It's a vague concept , Contains application scenarios 、 function 、 How to use it , When we talked about classic Bluetooth , Has focused on a2dp This profile, It's already quite complicated . Compared with ,BLE It's really much simpler . In terms of design , Simplicity is elegance .
to glance at gatt The architecture of the figure :

GATT It contains a series of service,characteristic,service Can pass include The way includes other service, One service Can contain one or more characteristic( features ),characteristic Is the basic unit , Contains property,value and descriptor,property Defines how the feature is used , as well as descriptor How to be accessed ,value Is the value of this characteristic .
be-all service,characteristic Use the above ATT Of attibute To describe the , It's just old wine in new bottles .
With GATT Of service, Classic Bluetooth sdp( Service Discovery Protocol ) It is also unnecessary , All things use GATT This set of things to describe , grace .
Let's take a look at the specific status of the data with examples , Before explaining the examples , Let's make a comparison BLE and BR Of packet Format .
BR Review the format of :

LE Format and BR The format of is similar , There are different places ; among access address Similar to classic Bluetooth access code, And classic Bluetooth packet header and payload header Different ,LE Only in pdu There was a header, It basically includes the flow control of the former 、 Retransmission function and LLID etc. , according to packet Different types (advertising channel Bao also data channel package )header The format of is different . Speaking of these two kinds of bags ,LE In fact, there are two application scenarios when designing , One is to transmit more data , Connection required , One is lightweight , Just broadcast . therefore ,gap Layer of role Divided into broadcast oriented broadcaster,
Observer; And connection oriented peripheral,central Four kinds of .

Link layer The state machine of is as follows :

The following is to use sniffer grabbing flip4 Speaker through mobile phone app Connect , And pass BLE Read and write some packets , See how this state machine works .

First of all flip4 Send a connectable broadcast packet and wait for the mobile phone to connect , Be careful adv Bag access address Is a fixed address 0x8e89bed6, And then it's important to note that PDU_Type, The broadcast package has 8 format , Some can be connected , Some cannot be connected , Here is a connectable adv_ind,payload The content mainly includes the Bluetooth address, manufacturer, name, etc , there flip4 The address is 04fea100254b, BLE Specified broadcast packet physical channel yes 37、38、39,adv The package will take turns broadcasting on three channels , The packet in the picture is a channel 37.BLE This characteristic determines that the connection speed can 3ms about , Better than classic Bluetooth inquiry、page Frequency hopping is much better , Because those two ways of telling the truth are both making up . here flip4 The state of is in advertising state .
At this time, the mobile terminal is turned on app, Can scan the surrounding BLE equipment , It should be possible to find flip4 Of the broadcast package , The mobile terminal is in scanning state .
Click to connect on the mobile terminal , Will enter initiating state :

Get into initiating Status of the mobile phone trying to and flip4 Connect , Issued connect ind package , It contains the address of the mobile phone (initiator address) and flip4 The address of (advertiser address), The connection is now complete , Got exclusive access address:0xaf9a8559, The whole process is super simple . Of course , On cell phones and flip4 Internal , Some more hci Layer interaction notifies the completion of the upper layer connection , The flow chart is as follows :

to glance at conn ind What information does the package contain , except initiator and adverter Outside their respective addresses , The main contents are as follows

Inside winsize,winoffset,inerval And so on BLE An important parameter of , It determines the time point and window length of both sides , We know BLE Data interaction ratio BR A lot less , It is important to agree on these for power savings .
This is also true BLE The true meaning of establishing connections , Both parties have agreed on the time point for subsequent communication ,( With interval For cycles ), And frequency hopping of each communication channel( according to Hop Sequence calculation ).
Our parameters this time conn interval yes 25ms:

Let's take a look at the back connection event Time sequence , The cycle is 25ms Of .

BLE In this way with BR There are different ways to communicate at random points in time .
We often encounter BLE Broken chain , On the one hand, it is related to the robustness of the software , On the one hand, it is related to this loose way of dating ——BLE After building the chain , Is to maintain a timer Of , Each communication between the two sides is called a connection event, Will reset this timer, If you lose contact for a period of time , exceed Timeout( The full name should be connSupervisionTimeout) Value , The chain is broken .
As the saying goes , Even if the case is raised in unison , It's hard to make up one's mind ……
however , Fortunately BLE Your connection is too fast , Many times we don't care Is it .
After the connection is established , The two sides of the role Will determine the , The mobile phone is the initiator initiater On the side of , yes master, from gap The official name of the layer is central,flip4 yes pheriperal. Although there are many names , Just different perspectives ,central,pheriperal Is more in line with the application layer .
边栏推荐
- WinDriver compilation summary
- Kubernetes 基本介绍及核心组件
- [pyGame games] here it is. This Gobang game is super A. share it with your friends~
- Shell Sort
- IGBT与三代半导体SiC双脉冲测试方案
- [pyGame games] story stream recommendation: what kind of games can you like? (devil lover, bully's wife version)
- Serial port missing in Ni Max in LabVIEW
- 【LaTex】latex VS Code snippets(代码片段)
- [pyGame collection] please check the game guide through childhood: are there any games you have played? (attach five source codes for self access)
- [AI card player] for the first time to see such an "exciting" landowner, the key factor for a high winning rate is
猜你喜欢

Leetcode-209 minimum length subarray

Error 1046 when LabVIEW uses MathScript node or matlab script

C language file operation

Hyperleger fabric installation

【自动回复or提醒小助手】妈妈再也不用担心我漏掉消息了(10行代码系列)

From the perspective of Confucius Temple IP crossover, we can see how the six walnuts become "butterflies" for the second time

【Pygame小游戏】“史上最炫酷贪吃蛇”驾到,FUN开玩(不好玩不要钱)
![[pyGame games] here it is. This Gobang game is super A. share it with your friends~](/img/76/faea3558ed6fadff755c517922088b.png)
[pyGame games] here it is. This Gobang game is super A. share it with your friends~

【Pygame小游戏】趣味益智游戏 :打地鼠,看一下能打多少只呢?(附源码)

A simple understanding of B tree
随机推荐
Lambda learning records
It is said that the verification code is a barrier in the crawler. I can break through it with only five lines of code.
From the perspective of Confucius Temple IP crossover, we can see how the six walnuts become "butterflies" for the second time
763. 划分字母区间
【Pygame小游戏】来了来了它来了——这款五子棋小游戏超A的,分享给你的小伙伴儿一起pk吧~
In the month of safety production, Huangpu launched a publicity campaign for gas safety in shops
Several common current transformer sampling circuits
集合删除元素技巧 removeIf
博文推荐|构建 IoT 应用——FLiP 技术栈简介
【Pygame小遊戲】別找了,休閑遊戲專題來了丨泡泡龍小程序——休閑遊戲研發推薦
MP框架基本操作(自用)
When leaving the web page, the website displays 404 Not found- starze V Club
From the perspective of Confucius Temple IP crossover, we can see how the six walnuts become "butterflies" for the second time
Redis installation and common problem solving based on centeros7 (explanation with pictures)
How to remove the blank at the top of listview
C language file operation
Pseudo static setting of Typecho - starze V Club
IGBT and third generation semiconductor SiC double pulse test scheme
Error report of curl import postman
How to check the variable waveform when debugging the program? Look here