Bluetooth LE AT example (BLE debugging assistant and module connection process)

1. Introduction

ESP-AT currently only supports the Bluetooth LE 4.2 protocol specification , and the description in this document is only applicable to the Bluetooth LE protocol 4.2 protocol specification . Please refer to Core Specification 4.2 for more information.

Bluetooth LE Protocol Architecture

The Bluetooth LE protocol stack is divided into several levels from bottom to top: Physical Layer (PHY) , Link Layer (LL) , Host Controller Interface (HCI) , Logical Link Control and Adaptation Protocol Layer (L2CAP) , Attribute Protocol (ATT) , Security Manager Protocol (SMP) , Generic Attribute Pro file (GATT) , Generic Access Profile (GAP) .

  • PHY : The PHY layer is mainly responsible for sending and receiving information packets on the physical channel. Bluetooth LE uses 40 radio frequency channels. Frequency range: 2402 MHz to 2480 MHz.

  • LL : The LL layer is primarily responsible for creating, modifying, and releasing logical links (and, if necessary, their associated logical transports), as well as updating parameters related to physical links between devices. It controls the link layer state machine to be in one of the five states of preparation , broadcast , listening/scanning , initiating connection , and connected .

  • HCI : The HCI layer provides a standardized interface to hosts and controllers. This layer can be implemented by a software API or controlled using a hardware interface UART , SPI , USB .

  • L2CAP : The L2CAP layer is responsible for protocol multiplexing, segmentation and reassembly of data exchanged between the host and the protocol stack.

  • ATT : The ATT layer implements a point-to-point protocol between attribute servers and attribute clients. The ATT client sends commands, requests and confirmations to the ATT server. The ATT server sends responses, notifications and indications to the client.

  • SMP : The SMP layer is used to generate encryption keys and identity keys. The SMP also manages the storage of encryption keys and identity keys, and is responsible for generating and resolving random addresses to known device identities.

  • GATT : The GATT layer represents the functionality of an attribute server and optionally an attribute client. This configuration file describes the hierarchy of services, characteristics, and properties used in the property server. This layer provides interfaces for discovering, reading, writing, and indicating service characteristics and attributes.

  • GAP : The GAP layer represents basic functionality common to all Bluetooth devices, such as modes and access procedures used by transports, protocols, and application profiles. GAP services include device discovery, connection mode, security, authentication, association model, and service discovery.

Bluetooth LE Role Division

Different layers in the Bluetooth LE protocol stack have different role divisions. These role divisions do not affect each other.

  • LL : The device can be divided into master and slave , the slave broadcasts, and the master can initiate a connection.

  • GAP : 4 specific roles are defined: Broadcaster , Observer , Peripheral and Central .

  • GATT : Devices can be divided into servers and clients .

important

  • The Bluetooth LE server and Bluetooth LE client described in this document are both GATT layer roles.

  • Currently, ESP-AT supports the coexistence of Bluetooth LE server and Bluetooth LE client .

  • Regardless of whether ESP-AT is initialized as a Bluetooth LE server or a Bluetooth LE client, the maximum number of devices connected at the same time is 3 .

GATT is actually an attribute transfer protocol. Simply put, it can be regarded as an application layer protocol for attribute transfer. The structure of this property is very simple. It is composed of services , each of which is composed of a variable number of characteristics , each of which is composed of many other elements.

The two roles of GATT server and GATT client exist after the Bluetooth LE connection is established. A GATT server stores data transmitted through the attribute protocol and accepts attribute protocol requests, commands, and confirmations from GATT clients. In short, the end providing data is called GATT server , and the end accessing data is called GATT client .

important

  • The ESP32 Bluetooth LE server needs to burn the ble_data.bin file into flash to provide Bluetooth LE services.

  • For the burning address of the ble_data.bin file, see the address corresponding to ble_data in at_customize.csv , or the address recorded in the file build/download.config .

2. BLE debugging assistant and module connection process

Notes only

Reference link:

(11 messages) ESP32 uses BLE Bluetooth transparent transmission_esp32 Bluetooth transparent transmission_Lele love learning 1's blog-CSDN blog

1. Hardware preparation.

Module NameESP-WROOM-32

UART0 is used to print out logs and update firmware, and UART2 is used to receive AT command communication.

The upper computer uses a serial port tool, and the USB is converted to a serial port to connect to the Bluetooth module.

The mobile APP uses "BLE Bluetooth Debugging Assistant", which can be downloaded from the mobile application market.

2. Replace the bin file of the Bluetooth module.

The default firmware of the module may not support it, and the firmware needs to be updated. i used

ESP32-WROOM-32_AT_Bin_V2.4.0.0.zip

Link

Released Firmware - ESP32 - — ESP-AT User Guide latest Documentation (espressif.com)

3. Command preparation

AT+BLEINIT=2 //将esp32设置成蓝牙服务端
AT+BLEGATTSSRVCRE //GATTS 创建服务
AT+BLEGATTSSRVSTART //GATTS 开启全部服务。
AT+BLEADDR?  //ESP32 蓝牙 LE 服务器获取其 MAC 地址。
AT+BLEADVPARAM=50,50,0,0,7,0,,  //ESP32 Bluetooth LE 服务端设置广播参数。
AT+BLENAME="AiThinker"
AT+BLEADVDATA="0201060A0941695468696E6B6572"
AT+BLEADVSTART //

4. Serial tool. To send multiple commands in the extension, remember to check "add carriage return and line feed".

5. BLE debugging assistant.

6. After the connection is successful, the serial port tool prompts

+BLECONN:0,"69:60:2c:27:27:14"
+BLECONNPARAM:0,0,0,6,0,500
+BLECONNPARAM:0,0,0,9,0,2000

7. The app sends data and the serial port receives it.

Three, summary.

1. The speed of sending a single character is relatively fast, but the speed of sending multiple characters is obviously slow. I don't know why.

2. After the connection is disconnected, the assistant can no longer find the module, and the module must send the "AT+BLEADVSTART" command.

3. The mobile phone's built-in Bluetooth cannot be found, and the device must be found in the BLE debugging assistant.

4. Finally, I want to achieve transparent transmission, but it has not yet been realized.

Guess you like

Origin blog.csdn.net/m0_38012497/article/details/129683474