A bluetooth communication method, a first device, a second device and a storage medium
By sending and receiving broadcast messages three times in Bluetooth communication, the first device and the second device can establish a GATT connection without pairing, solving the problem of insufficient convenience and versatility of Bluetooth communication in the existing technology, and achieving a better Applicability to a wide range of application scenarios.
Patent Information
- Application Number
- CN202111030729.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-09-03
- Publication Date
- 2024-09-17
- Estimated Expiration
- 2041-09-03
AI Technical Summary
Existing wireless communication methods, especially Bluetooth technology, require devices to be paired in advance or connected to the same network, resulting in poor convenience and versatility, and limiting application scenarios.
By sending and receiving broadcast messages three times, the first device and the second device can establish a general attribute profile GATT connection without Bluetooth pairing to achieve Bluetooth communication.
It improves the convenience and versatility of Bluetooth communication, allowing devices to be connected and controlled without pairing, making it suitable for more application scenarios.
Smart Images

Figure CN115767486B
Abstract
Description
Technical Field
[0001] The present application relates to the technical field of behavioral wireless communications, and in particular to a Bluetooth communication method, a first device, a second device, and a storage medium. Background Art
[0002] At present, different devices can achieve wireless communication through technologies such as Bluetooth and LAN, and then realize data transmission or wireless control. However, Bluetooth technology requires two devices to be paired in advance, and LAN technology requires two devices to be connected to the same network, which limits the application scenarios. In other words, the existing wireless communication methods all require the completion of certain prerequisites, and their convenience and versatility are poor, which brings inconvenience to users. Summary of the invention
[0003] The present application provides a Bluetooth communication method, a first device, a second device and a storage medium, which can improve the convenience and versatility of Bluetooth communication.
[0004] The technical solution of this application is implemented as follows:
[0005] In a first aspect, an embodiment of the present application provides a Bluetooth communication method, which is applied to a first device, and the method includes:
[0006] Sending a first broadcast message, and receiving at least one second broadcast message returned by at least one second device in response to the first broadcast message;
[0007] determining a target second device from the at least one second device according to the at least one second broadcast message, and generating a third broadcast message based on a device identifier of the target second device;
[0008] After sending the third broadcast message, a Generic Attribute Profile GATT connection is established with the target second device.
[0009] In a second aspect, an embodiment of the present application provides a Bluetooth communication method, which is applied to a second device, and the method includes:
[0010] generating a second broadcast message in response to a first broadcast message sent by the first device;
[0011] After sending the second broadcast message, receiving a third broadcast message sent by the first device;
[0012] When the third broadcast message carries the device identification of the second device, a GATT connection is established with the first device.
[0013] In a third aspect, an embodiment of the present application provides a first device, the first device comprising a first sending unit, a generating unit and a first connecting unit; wherein,
[0014] A first sending unit, configured to send a first broadcast message, and receive at least one second broadcast message returned by at least one second device in response to the first broadcast message;
[0015] a generating unit configured to determine a target second device from at least one second device according to at least one second broadcast message, and generate a third broadcast message based on a device identifier of the target second device;
[0016] The first connection unit is configured to establish a general attribute profile GATT connection with a target second device after sending the third broadcast message.
[0017] In a fourth aspect, an embodiment of the present application provides a first device, the first device comprising a first memory and a first processor; wherein:
[0018] A first memory, for storing a computer program that can be run on the processor;
[0019] The first processor is used to execute the steps of the method of the first aspect when running a computer program.
[0020] In a fifth aspect, an embodiment of the present application provides a second device, the second device comprising a response unit, a second sending unit and a second connection unit; wherein,
[0021] a response unit, configured to generate a second broadcast message in response to the first broadcast message sent by the first device;
[0022] A second sending unit, configured to receive a third broadcast message sent by the first device after sending the second broadcast message;
[0023] The second connection unit is configured to establish a GATT connection with the first device when the third broadcast message carries the device identifier of the second device.
[0024] In a sixth aspect, an embodiment of the present application provides a second device, the second device comprising: a second memory and a second processor; wherein:
[0025] A second memory, for storing a computer program that can be run on the processor;
[0026] The second processor is used to execute the steps of the method described in the second aspect when running the computer program.
[0027] In a seventh aspect, an embodiment of the present application provides a computer storage medium, which stores a computer program, and when the computer program is executed by a first processor, it implements the steps of the method of the first aspect, or when it is executed by a second processor, it implements the steps of the method of the second aspect.
[0028] The embodiment of the present application provides a Bluetooth communication method, a first device, a second device and a storage medium, which are applied to the first device and the second device. On the first device side, a first broadcast message is sent, and at least one second broadcast message returned by at least one second device in response to the first broadcast message is received; according to at least one second broadcast message, a target second device is determined from at least one second device, and a third broadcast message is generated based on the device identification of the target second device; after sending the third broadcast message, a general attribute profile GATT connection is established with the target second device. On the second device side, a second broadcast message is generated in response to the first broadcast message sent by the first device; after sending the second broadcast message, a third broadcast message sent by the first device is received; and a GATT connection is established with the first device when the device identification of the second device is carried in the third broadcast message. In this way, through the interaction of three broadcast messages, the first device and the second device can establish a GATT connection, and then realize Bluetooth communication without Bluetooth pairing, thereby improving the convenience and versatility of Bluetooth communication. BRIEF DESCRIPTION OF THE DRAWINGS
[0029] Figure 1 A schematic diagram of a flow chart of a Bluetooth communication method provided in an embodiment of the present application;
[0030] Figure 2 A schematic diagram of a flow chart of another Bluetooth communication method provided in an embodiment of the present application;
[0031] Figure 3 A flowchart of another Bluetooth communication method provided in an embodiment of the present application;
[0032] Figure 4 A flowchart of another Bluetooth communication method provided in an embodiment of the present application;
[0033] Figure 5 A schematic diagram of the composition structure of a first device provided in an embodiment of the present application;
[0034] Figure 6 A schematic diagram of the hardware structure of a first device provided in an embodiment of the present application;
[0035] Figure 7 A schematic diagram of the composition structure of a second device provided in an embodiment of the present application;
[0036] Figure 8 A schematic diagram of the hardware structure of a second device provided in an embodiment of the present application;
[0037] Fig. 9 A schematic diagram of the structure of a Bluetooth communication system provided in an embodiment of the present application. DETAILED DESCRIPTION
[0038] The following will be combined with the accompanying drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. It is understood that the specific embodiments described herein are only used to explain the related applications, rather than to limit the applications. It should also be noted that, for the convenience of description, only the parts related to the related applications are shown in the accompanying drawings.
[0039] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as those commonly understood by those skilled in the art to which this application belongs. The terms used herein are only for the purpose of describing the embodiments of this application and are not intended to limit this application.
[0040] In the following description, reference is made to “some embodiments”, which describe a subset of all possible embodiments, but it will be understood that “some embodiments” may be the same subset or different subsets of all possible embodiments and may be combined with each other without conflict.
[0041] It should be pointed out that the terms "first\second\third" involved in the embodiments of the present application are only used to distinguish similar objects and do not represent a specific ordering of the objects. It can be understood that "first\second\third" can be interchanged in a specific order or sequence where permitted, so that the embodiments of the present application described here can be implemented in an order other than that illustrated or described here.
[0042] Before further describing the embodiments of the present application in detail, the nouns and terms involved in the embodiments of the present application are described first. The nouns and terms involved in the embodiments of the present application are subject to the following interpretations:
[0043] Generic Attribute Profile (GATT) connection: A general specification for sending and receiving short data segments over a Bluetooth connection. In a GATT connection, two different devices act as a server and a client. After the GATT connection is established, the GATT Server sets the write and read characteristics for the GATT service, thereby providing the GATT Client with the ability to write or read data.
[0044] Read characteristic parameters: The GATT Server sets read characteristics for certain parameters to allow the GATT Client to read these parameters. The read characteristic descriptor is set under the read characteristic parameters.
[0045] Write Characteristics: The GATT Server sets write characteristics for certain parameters, thereby allowing the GATT Client to modify these parameters. The write characteristic descriptor is set under the write characteristic parameters.
[0046] Universally Unique Identifier (UUID): used to uniquely identify an object, such as a parameter, device, attribute, service, etc.
[0047] It is understandable that currently different devices can be connected wirelessly through technologies such as Bluetooth technology and local area network technology to achieve data transmission or wireless control. For example, you can download an application (Application, APP) through your mobile phone, and then use Bluetooth communication technology to control the switch and brightness of the smart light. In another related technology, the control logic of the Bluetooth remote control is implemented based on the GATT service. In another related technology, the headset can be connected to the host through the Bluetooth Low Energy (BLE) protocol, which has a fast transmission and reception speed and low power consumption.
[0048] Taking projection equipment as an example, there are currently two main ways for users to control projection equipment: control by Bluetooth remote control and sending commands from a mobile phone in the local area network. Both methods require some prerequisites, such as establishing Bluetooth pairing in advance, or connecting the mobile phone and the projection equipment to the same local area network. However, if in a certain application scenario, the projection equipment cannot be connected to the Internet and cannot be operated by the remote control (such as forgetting to bring the remote control or the remote control function malfunctions, etc.), then it is impossible to control the projection equipment using a mobile phone.
[0049] Based on this, an embodiment of the present application provides a Bluetooth communication method, the basic idea of which is: on the first device side, a first broadcast message is sent, and at least one second broadcast message returned by at least one second device in response to the first broadcast message is received; according to at least one second broadcast message, a target second device is determined from at least one second device, and a third broadcast message is generated based on the device identification of the target second device; after sending the third broadcast message, a general attribute profile GATT connection is established with the target second device. On the second device side, a second broadcast message is generated in response to the first broadcast message sent by the first device; after sending the second broadcast message, a third broadcast message sent by the first device is received; when the third broadcast message carries the device identification of the second device, a GATT connection is established with the first device. In this way, through the interaction of three broadcast messages, the first device and the second device can establish a GATT connection, and then realize Bluetooth communication without Bluetooth pairing, thereby improving the convenience and versatility of Bluetooth communication.
[0050] The embodiments of the present application will be described in detail below with reference to the accompanying drawings.
[0051] In one embodiment of the present application, see Figure 1 , which shows a schematic diagram of a flow chart of a Bluetooth communication method provided in an embodiment of the present application. Figure 1 As shown, the method may include:
[0052] S101: Send a first broadcast message, and receive at least one second broadcast message returned by at least one second device in response to the first broadcast message.
[0053] It should be noted that the Bluetooth communication method (or Bluetooth control method) provided in the embodiment of the present application is applied to the first device, and the first device refers to the main control device in the Bluetooth control process. Here, the first device can be a variety of electronic devices, such as a personal computer (PC), a laptop, a personal digital assistant (PDA), a wireless communication terminal (Wireless Communication Terminal), a smart phone (Smart Phone), etc., and the embodiment of the present application does not make any limitation.
[0054] In the related art, Bluetooth communication can only be performed after two devices complete Bluetooth pairing, which has certain limitations on application scenarios. In the embodiment of the present application, the first device and the second device directly implement the Bluetooth communication process through an agreed protocol without Bluetooth pairing, thereby improving the versatility and convenience of Bluetooth communication.
[0055] Specifically, the first device generates a first broadcast message, and broadcasts the first broadcast message in the environment where the first device is located. Generally speaking, the first broadcast message includes a target field, which is a field agreed upon in advance by the first device and the second device and is used to trigger a response from the second device.
[0056] Therefore, after the second device in the environment monitors the first broadcast message containing the target field, it generates a second broadcast message carrying its own device identification and broadcasts the second broadcast message so that the first device can understand which candidate second devices can establish a Bluetooth connection with it. At this time, when there are multiple second devices in the environment, the first device will actually receive multiple second broadcast messages.
[0057] Here, the target field is designed according to the actual application scenario, and the embodiments of the present application do not impose any specific restrictions.
[0058] S102: Determine a target second device from at least one second device according to at least one second broadcast message, and generate a third broadcast message based on a device identifier of the target second device.
[0059] It should be noted that, for the first device, after receiving at least one second broadcast message, it can learn which candidate second devices exist in the surrounding environment. Therefore, the first device needs to determine the target second device from these second devices and generate a third broadcast message according to the device identifier of the target second device.
[0060] It should also be noted that the second broadcast message carries the device identification of the corresponding device, so that the first device can determine the second device that sends the second broadcast message and obtain the device identification of the target second device. In this way, after the first device learns about multiple candidate second devices in the environment, it can present the information of multiple second devices to the user, so that the user can select the target second device. Therefore, in some embodiments, the determination of the target second device from at least one second device according to at least one second broadcast message may include:
[0061] Determining at least one second device according to a device identifier respectively carried in at least one second broadcast message;
[0062] A selection instruction is received from a user, and a target second device is determined from at least one second device according to the selection instruction.
[0063] It should be understood that the device identification of the second device may include one or more information, such as name, type, model, machine serial number, etc. Taking a projector as an example, each projector has a unique serial number when it leaves the factory, and the serial number can be used as the device identification.
[0064] In addition, in order to better display the candidate second devices to the user, the device identification of the second device can be displayed in a variety of preset display modes. For example, the device identification of at least one second device can be presented to the user in the form of an icon, text, etc.
[0065] In this way, after the first device determines the target second device, it can also generate a third broadcast message to notify the target second device to perform subsequent actions.
[0066] S103: After sending the third broadcast message, establish a Generic Attribute Profile GATT connection with the target second device.
[0067] It should be noted that the embodiment of the present application uses GATT connection to implement Bluetooth control between two devices. Therefore, after determining the third broadcast message containing the device identification of the target second device, the first device broadcasts the third broadcast message to request the second device to connect to the first device. In other words, the essence of the third broadcast message is the connection broadcast of GATT.
[0068] Here, GATT is a low-energy Bluetooth protocol. The Bluetooth communication method based on the GATT protocol enables two devices to achieve Bluetooth communication / Bluetooth control without pairing. For example, a mobile phone and a projection device can directly achieve the purpose of controlling the projection device with a mobile phone through an agreed protocol. In this way, in the awkward scenario where the target second device is not connected to the Internet and it is not convenient to directly control it, the first device can also control the target second device, which improves the convenience and versatility of Bluetooth communication. In addition, the GATT connection is a two-way communication, which can also make up for the defect of non-directional communication of Bluetooth broadcasting and improve the effect of Bluetooth control.
[0069] In this way, there are three broadcast messages between the first device and the target second device, thereby completing the device discovery process and accurately achieving the GATT connection between the first device and the target second device, so that the first device can perform Bluetooth control on the second device.
[0070] In the embodiment of the present application, the first device can be used as a server of the GATT connection to provide GATT services, and the target second device can be used as a client of the GATT connection to call the GATT service. Therefore, in some embodiments, before sending the third broadcast message, the method may also include:
[0071] Establish a GATT service, configure a read characteristic parameter, a read characteristic descriptor, a write characteristic parameter, and a write characteristic descriptor for the GATT service, wherein the GATT service has a first preset identification code, the read characteristic parameter has a second preset identification code, the read characteristic descriptor has a third preset identification code, the write characteristic parameter has a fourth preset identification code, and the write characteristic descriptor has a fifth preset identification code;
[0072] After establishing a Generic Attribute Profile GATT connection with the target second device, the method may further include:
[0073] Provide GATT services to the target second device.
[0074] It should be noted that, before sending the third broadcast message, the first device needs to establish a GATT service and configure various parameters and descriptors of the GATT service, as well as preset identification codes of different parameters and different descriptors.
[0075] Here, the read characteristic parameters refer to those parameters that allow the client to read, and the write characteristic parameters refer to those parameters that allow the client to write. Specifically, the read characteristic parameters include a read characteristic descriptor, and the write characteristic parameters include a write characteristic descriptor, which are used to write or read information respectively.
[0076] In addition, the preset identification code of each of the GATT service, read characteristic parameter, read characteristic descriptor, write characteristic parameter and write characteristic descriptor can be a UUID. Here, the allocation method of the preset identification code needs to refer to the unified standard in the industry.
[0077] In this way, for a GATT service, a responder can respond to multiple GATT servers at the same time. In the embodiment of the present application, since the first device is the server of the GATT service and the second device is the responder of the GATT service, the second device can establish different GATT connections with multiple first devices as a responder, that is, the second device can be controlled by multiple first devices at the same time.
[0078] Furthermore, after the first device and the second device establish a GATT connection, the first device can send a control instruction to the second device through the GATT connection, and the second device can also transmit relevant data to the first device through the GATT connection, thereby realizing Bluetooth communication between the first device and the target second device. Specifically, in some embodiments, the method may also include:
[0079] Based on the read characteristic parameter, perform Bluetooth communication with the target second device; and / or
[0080] Based on the write characteristic parameter, Bluetooth communication is performed with the target second device.
[0081] In a specific embodiment, performing Bluetooth communication with the target second device based on reading characteristic parameters may include:
[0082] Determine target instruction information;
[0083] The target instruction information is written into the read characteristic descriptor, so that the first device sends the target instruction information to the target second device.
[0084] Here, the target instruction information refers to the control instruction sent by the first device to the target second device. Taking the target second device as a projector as an example, the target instruction information may be to instruct the target second device to exit, confirm, next, move (projection angle) up, move (projection angle) down, etc.; if the target second device is a TV, the target instruction information may be to pause, play, volume up, shut down, etc.
[0085] It should be noted that, since the read characteristic parameter is a parameter that allows the target second device to read, the read characteristic parameter can be used to implement the first device sending instruction information to the target second device. Specifically, the first device can write the target instruction information into the read characteristic descriptor. In this way, after the first device and the target second device establish a GATT connection, the target second device obtains the target instruction information after obtaining the read characteristic descriptor in the GATT service.
[0086] Furthermore, the first device may send multiple instruction information to the target second device, that is, after the target second device has read the read characteristic descriptor, the first device may write new target instruction information into the read characteristic descriptor again. At this time, the first device also needs to send a modification notification to the second device. Therefore, in some embodiments, after writing the target instruction information into the read characteristic descriptor, the method may also include:
[0087] A modification notification is sent to the target second device.
[0088] Here, the modification notification is used to instruct the target second device to read the read characteristic descriptor.
[0089] It should be noted that the first device sending the target instruction information includes two different situations:
[0090] (1) The first device has determined the target command information to be sent before creating the GATT service. In this case, the first device can write the target command information into the read characteristic descriptor when creating the read characteristic parameters and read characteristic descriptor of the GATT service. In this way, after the target second device establishes a GATT connection with the first device, the target second device will sequentially obtain the GATT service, the read characteristic parameters / write characteristic parameters, and the read characteristic descriptor / write characteristic descriptor in the GATT service, so the target second device can also obtain the target command information.
[0091] (2) The first device needs to send the target command information again after creating the GATT service. In this case, the target second device may have completed the initial acquisition of the read characteristic descriptor. At this time, after the first device writes the target command information into the read characteristic descriptor, it is also necessary to send a modification notification to the target second device to instruct the target second device to read the read characteristic descriptor, thereby implementing the sending of the target command information to the target second device.
[0092] In addition, the first device needs to enable the feature notification function for the target second device, so that a modification notification can be sent after each modification of the read feature descriptor.
[0093] Further, in some embodiments, performing Bluetooth communication with the target second device based on writing characteristic parameters may include:
[0094] After detecting that the target second device performs a modification operation, the write characteristic descriptor is read to obtain the target state information, so that the first device receives the target state information sent by the target second device.
[0095] Here, the target status information is used to indicate the status information sent by the target second device to the first device, and the status information is information indicating the operating status of the target second device itself, such as network disconnection, power status, etc. In addition, the modification operation refers to the target second device modifying the write characteristic descriptor.
[0096] It should be noted that since the write characteristic parameter is a parameter that allows the target second device to write, the write characteristic parameter can be used to enable the target second device to send status information to the first device. Specifically, the target second device can modify the write characteristic descriptor of the write characteristic parameter. As the server of the GATT service, the first device can perceive the modification operation of the target second device and read the write characteristic descriptor to obtain the target status information.
[0097] That is to say, on the one hand, the first device can send target instruction information to the target second device, and this function is realized by means of the read characteristic descriptor, so that the first device can control the Bluetooth of the target second device. Specifically, according to the target instruction information to be transmitted, the first device will modify the read characteristic descriptor, and after the target second device reads the read characteristic descriptor, the target instruction information is obtained, thereby realizing the data transmission from the first device to the target second device.
[0098] On the other hand, the target second device can send target status information to the first device. This function is implemented with the help of write characteristic descriptors, so that the target second device sends status information to the first device, thereby realizing two-way communication. Specifically, according to the target status information that needs to be transmitted, the target second device will modify the write characteristic parameters. Here, since the GATT service itself is provided by the first device, after the target second device modifies the write characteristic parameters, the first device also obtains the target status information, thereby realizing the data transmission from the target second device to the first device.
[0099] In addition, the embodiment of the present application can also allow multiple first devices to perform Bluetooth control on the second device at the same time. The reason is that the first device acts as the server of the GATT device and the second device acts as the client of the GATT device. Therefore, the second device as the client can establish GATT connections with multiple first devices.
[0100] It should also be noted that the underlying control logic of the above Bluetooth communication method can be packaged as a carrier of an application and installed in the first device / second device. In other words, the first device and / or the second device needs to install a specified application so that the user can implement the above steps with the help of the application.
[0101] The embodiment of the present application provides a Bluetooth communication method, which is applied to a first device, sends a first broadcast message, and receives at least one second broadcast message returned by at least one second device in response to the first broadcast message; determines a target second device from at least one second device according to at least one second broadcast message, and generates a third broadcast message based on the device identifier of the target second device; after sending the third broadcast message, establishes a general attribute profile GATT connection with the target second device. In this way, through the interaction of the third broadcast message, the first device and the second device can establish a GATT connection, and then realize Bluetooth communication without Bluetooth pairing, which improves the convenience and versatility of Bluetooth communication.
[0102] In another embodiment of the present application, see Figure 2 , which shows a flow chart of another Bluetooth communication method provided by an embodiment of the present application. Figure 2 As shown, the method may include:
[0103] S201: Generate a second broadcast message in response to a first broadcast message sent by a first device.
[0104] It should be noted that the Bluetooth communication method (or Bluetooth control method) provided in the embodiment of the present application is applied to the second device, and the second device refers to the controlled device in the Bluetooth control process. Here, the second device can be a variety of electronic devices, such as audio, television, projector, smart home device, portable multimedia player (Portable Multimedia Player, PMP), augmented reality device (Augmented Reality, AR), mixed reality device (Mixed Reality, MR), smart glasses (Smart Glasses).
[0105] In the related art, Bluetooth communication needs to be performed based on Bluetooth pairing between two devices, which limits the application of some scenarios. In the embodiment of the present application, the first device and the second device implement Bluetooth communication through an agreed protocol, thereby improving the versatility and convenience of Bluetooth communication.
[0106] Specifically, a Bluetooth communication-related program is pre-set in the second device, in which a target field is set. When the second device scans the first broadcast message containing the target field, the device sending the first broadcast message is determined as the first device. Then, in response to the first broadcast message, the second device generates and sends a second broadcast message to inform the first device that it can be used as a candidate controlled device.
[0107] It should be noted that the second broadcast message needs to include the device identification of the second device so that the first device can learn the identity information of the second device. Therefore, in response to the first broadcast message sent by the first device, generating the second broadcast message may include:
[0108] determining a device identification of a second device;
[0109] A second broadcast message is generated according to the device identification.
[0110] In this way, the first device and the second device do not need to be paired, but can directly implement the device discovery process in the form of Bluetooth broadcasting, and then establish a GATT connection.
[0111] S202: After sending the second broadcast message, receiving a third broadcast message sent by the first device.
[0112] S203: When the third broadcast message carries the device identification of the second device, establish a GATT connection with the first device.
[0113] It should be noted that, since there may be more than one candidate second device that can be controlled by the first device in the environment, the first device will determine the target second device to be controlled based on the received second broadcast message and generate a third broadcast message including the device identifier of the target second device.
[0114] The embodiment of the present application describes the workflow of the target second device. That is, the third broadcast message carries the device identification of the second device to inform the second device to establish a GATT connection with the first device.
[0115] Furthermore, in some embodiments, the method may further include:
[0116] After calling a preset connection interface of the first device, acquiring a GATT service provided by the first device based on the first preset identification code; wherein the GATT service is created by the first device before sending the third broadcast message;
[0117] Based on the second preset identification code, obtaining a read characteristic parameter of the GATT service, and based on the third preset identification code, obtaining a read characteristic descriptor;
[0118] The target instruction information sent by the first device is determined according to the acquired read characteristic descriptor.
[0119] It should be noted that in the embodiment of the present application, the first device can act as a server of the GATT connection to provide GATT services; the second device can act as a client of the GATT connection to call the GATT service.
[0120] Here, the first device will establish a GATT service, which includes read characteristic parameters, read characteristic descriptors, write characteristic parameters, and write characteristic descriptors, and the GATT service, read characteristic parameters, read characteristic descriptors, write characteristic parameters, and write characteristic descriptors each have a different preset identification code. The second device will call the preset connection interface of the first device to obtain the GATT service and various parameters in the GATT service. Among them, the preset connection interface refers to the interface used to obtain the GATT service created by the first device, which can generally be named connectGatt.
[0121] Specifically, for the first device, if the target instruction information to be sent to the second device has been determined when establishing the GATT service, the target instruction information can be directly written into the read characteristic descriptor. In this way, after the second device calls the preset connection interface of the first device, the GATT service provided by the first device is obtained through the first preset identification code, and the read characteristic parameters of the GATT service are obtained based on the second preset identification code, and the read characteristic descriptor is obtained based on the third preset identification code, thereby obtaining the target instruction information.
[0122] In addition, if the first device needs to send a control command to the second device again after establishing the GATT service, it still needs to write the target command information into the read characteristic descriptor. However, since the second device has already obtained the read characteristic descriptor, the first device needs to send a modification notification to the second device to remind the second device to read the read characteristic descriptor again.
[0123] Specifically, the first device needs to provide a feature notification function for enabling the feature, so that after the first device modifies the read feature parameter, the second device is notified in time to read the feature.
[0124] Furthermore, in some embodiments, after establishing a GATT connection with the first device, the method may further include:
[0125] Obtain a write characteristic parameter of the GATT service based on the fourth preset identification code, and obtain a write characteristic descriptor based on the fifth preset identification code;
[0126] When detecting that the state information of the first device changes, determining target state information;
[0127] Write target status information to the write characteristic descriptor.
[0128] It should be noted that the second device can obtain the write characteristic parameters of the GATT service based on the fourth preset identification code, and obtain the write characteristic descriptor of the GATT service based on the fifth preset identification code. Then, if the second device needs to transmit the target state information to the first device, it needs to write the target state information into the write characteristic descriptor to enable the second device to send data to the first device.
[0129] Here, the preset identification codes are all unified standards in the industry, or in other words, the first device and the second device have agreed in advance on the meanings of different preset identification codes.
[0130] In a specific embodiment, the first preset identification code may be UUID_SERVER, the second preset identification code may be UUID_CHARREAD, the third preset identification code may be UUID_DESCRIPTOR1, the fourth preset identification code may be UUID_CHARWRITE, and the fifth preset identification code may be UUID_DESCRIPTOR2. It should be understood that the Bluetooth technical specification provided by the Bluetooth Technology Alliance specifies specific encodings of different UUIDs, for example, UUID_DESCRIPTOR1 may be 00002602-0000-700-5000-00505f9b34fb.
[0131] It should also be noted that in the embodiment of the present application, the first device is the server of the GATT device, and the second device is the client of the GATT device. Therefore, multiple first devices are allowed to connect to the second device at the same time, that is, multiple first devices are allowed to perform Bluetooth control on the second device at the same time.
[0132] The embodiment of the present application provides a Bluetooth communication method, which is applied to a second device, and generates a second broadcast message in response to a first broadcast message sent by a first device; after sending the second broadcast message, a third broadcast message sent by the first device is received; and a GATT connection is established with the first device when the third broadcast message carries the device identifier of the second device. In this way, through the interaction of three broadcast messages, the first device and the second device can establish a GATT connection, and then realize Bluetooth communication without Bluetooth pairing, which improves the convenience and versatility of Bluetooth communication; in addition, with the help of broadcast messages sent multiple times, the first device can accurately connect to the specified second device, and it can also allow multiple first devices to simultaneously control the second device through Bluetooth.
[0133] In another embodiment of the present application, taking the first device as a mobile phone (or called a mobile phone terminal) and the second device as a projection device (or called a projection terminal) as an example, the Bluetooth communication method provided in the embodiment of the present application is specifically described.
[0134] See also Figure 3 , which shows a flow chart of another Bluetooth communication method provided by an embodiment of the present application. The method may include three parts: device discovery, GATT connection, and control instruction sending. Figure 3As shown, device discovery includes steps S301 to S303, GATT connection includes step S304, and control instruction sending includes steps S305 and S306. The specific description is as follows:
[0135] S301: The mobile phone sends a first broadcast message.
[0136] It should be noted that, in the case where the mobile phone and the projector are not paired via Bluetooth, a Bluetooth communication method is provided to enable the mobile phone to discover the projection device and authorize the user to control the projection.
[0137] It should be noted that the mobile phone and the projection device carry their own information by sending and scanning Bluetooth broadcasts to achieve device discovery. The mobile phone first sends the first Bluetooth broadcast (i.e., the first broadcast message), and the Bluetooth broadcast carries the xf-device field (FIND), which is equivalent to the aforementioned target field.
[0138] S302: After receiving the first broadcast message, the projection end sends a second broadcast message, and the second broadcast message carries the device identification of the projection end.
[0139] It should be noted that after receiving the first Bluetooth broadcast, the projector parses and compares the fields. If the xf-device field is parsed, the trigger condition is met, and the projector sends a second Bluetooth broadcast (i.e., the second broadcast message). Here, the second Bluetooth broadcast carries the xr-+machine serial number field (RESPOND), which is the device identifier of the projection device.
[0140] S303: After receiving at least one second broadcast message, the mobile phone creates a GATT service and sends a third broadcast message, and the third broadcast message carries the device identifier of the target projection terminal.
[0141] It should be noted that after the mobile phone receives the second Bluetooth broadcast, it uses the device identifier in the second Bluetooth broadcast to identify different candidate controlled devices (i.e., candidate second devices) to facilitate selection and connection. After the user selects the target controlled device (i.e., the target second device), the mobile phone will create a GATT service and send a third Bluetooth broadcast (i.e., the third broadcast message). The third Bluetooth broadcast carries the xc-+ machine serial number field (CONNECT) of the target controlled device to request a GATT connection with the target controlled device.
[0142] For the convenience of description, in the embodiment of the present application, the projector terminal is used as the target controlled device. In this way, after receiving the third Bluetooth broadcast, the projector terminal knows that the third Bluetooth broadcast is used for subsequent establishment of a GATT connection.
[0143] Here, both the first device and the second device are installed with Bluetooth service. In the above process, the scanning of Bluetooth broadcast is to call the startScan interface of Bluetooth service and register the mScanCallBack callback interface. After receiving the surrounding Bluetooth broadcast, the callback interface will be triggered to respond. The sending of Bluetooth broadcast is to call the startAdvertising interface of Bluetooth and carry the broadcast information.
[0144] It should also be noted that for GATT services, the mobile phone and the projection device act as GATT Server and GATT Client respectively to establish GATT Connect (i.e. GATT connection). Specifically. The mobile phone first creates a GATT service through openGattServer, and adds read and write characteristics to this service, and adds a descriptor for the read characteristic (i.e. read characteristic descriptor), and also adds a descriptor for the write characteristic (i.e. write characteristic descriptor). Here, the read characteristic descriptor is used for notification (Notify). The above services, characteristics and descriptors are identified by UUID (i.e. preset identification code), and the projection end can obtain them through a fixed UUID.
[0145] S304: The projector calls the connection interface of the GATT service to obtain the GATT service created by the first device.
[0146] It should be noted that after the projector receives the third Bluetooth broadcast from the mobile phone, it can obtain BluetoothDevice through the third Bluetooth broadcast, and then call the connection interface connectGatt (i.e. the preset connection interface) of BluetoothDevice. After the connection is successful, the callback interface onServiceDiscoverd will be triggered.
[0147] Then, the projector can obtain the GATT service created by the server through UUID_SERVER (i.e. the first preset identification code), and then obtain the read characteristics and write characteristics through UUID_CHARREAD (i.e. the second preset identification code) and UUID_CHARWRITE (i.e. the fourth preset identification code) respectively, and obtain the descriptor in the read characteristic through UUID_DESCRIPTOR1 (i.e. the third preset identification code), the descriptor is used to notify (Notify) information, and obtain the descriptor in the write characteristic through UUID_DESCRIPTOR2 (i.e. the fifth preset identification code).
[0148] S305: The projector modifies the corresponding attribute value by writing characteristics, thereby sending target status information to the mobile phone.
[0149] It should be noted that the characteristics of the GATT service and the descriptors of the characteristics can be used to send and receive messages and send notifications. The projector can call writeCharacteristic by writing characteristics, carrying the target status information to be transmitted, such as some states of the projection network disconnection, which can be sent to the mobile phone by writing characteristics. Specifically, the projector needs to write the target status information into the descriptor in the write characteristic, and the attribute value refers to the specific content of the descriptor.
[0150] S306: The mobile phone terminal modifies the corresponding attribute value by reading the characteristic, thereby sending a target control instruction to the projection terminal.
[0151] In the embodiment of the present application, the execution order of step S305 and step S306 is not particular.
[0152] It should also be noted that the mobile phone can carry the device identification and characteristic value of the notified device by reading the characteristic notifyCharacteristicChanged, and send the target control instruction to the projection end. After that, the projection end will trigger the callback onCharacteristicChanged, and then the desired information can be read. It should be noted here that the projection end needs to call the interface setCharacteristicNotification to enable the characteristic notification function, and the UUID of the descriptor needs to use the Bluetooth standard UUID type, that is, "00002602-0000-700-5000-00505f9b34fb", otherwise it will not be able to receive the NOTIFY instruction sent by the server. The currently supported control instructions include the up key, down key, left key, right key, confirm key, return key, power off key, etc. Specifically, the mobile phone needs to write the target control instruction into the descriptor in the read characteristic.
[0153] It should also be noted that in the embodiment of the present application, multiple mobile phones are supported to control the projection because the mobile phone is used as the server of GATT. Different servers are created for multiple mobile phones, and the projection device can initiate GATT connections to multiple mobile phones as a client. If the roles are reversed, it cannot be achieved because a Bluetooth GATT server can only wait for one client to connect, that is, a slave device (mobile phone) can only wait for the master device (projection device) to initiate a connection, while the master device (projection device) can initiate connections to multiple slave devices (mobile phones).
[0154] For example, Figure 4As shown, a Bluetooth communication method is provided in an embodiment of the present application. For a mobile phone with a certain assistant APP installed, device discovery can be achieved with the projector through three Bluetooth broadcasts; then, the mobile phone acts as a GATT server and the projector acts as a GATT client, thereby establishing a GATT connection between the mobile phone and the projector; finally, the mobile phone and the projector realize command transmission and reception through the GATT connection, thereby realizing the Bluetooth control of the projector by the mobile phone.
[0155] In this way, on the one hand, device discovery is achieved by carrying machine information through Bluetooth broadcast, and when there are multiple controlled devices in the environment, the user can choose to connect; on the other hand, supporting two-way communication through GATT allows users to get timely feedback after issuing instructions; on the other hand, it supports different mobile phones to connect to the projector in succession, because this solution regards the projector as the client and the mobile phone as the server. In this way, the Bluetooth communication method of the embodiment of the present application can meet many-to-one requirements, which is mainly achieved by relying on three broadcast interactions between the mobile phone and the projector.
[0156] The embodiment of the present application provides a Bluetooth communication method. The specific implementation method of the aforementioned embodiment is elaborated in detail through this embodiment. It can be seen that through the interaction of the first broadcast message and the second broadcast message, the first device and the second device can establish a GATT connection, and then realize Bluetooth communication without the need for Bluetooth pairing, thereby improving the convenience and versatility of Bluetooth communication; in addition, with the help of multiple broadcast messages sent, the first device can accurately connect to the specified target second device, and can also allow multiple first devices to perform Bluetooth control on the second device at the same time.
[0157] In yet another embodiment of the present application, see Figure 5 , which shows a schematic diagram of the composition structure of a first device 40 provided in an embodiment of the present application. Figure 5 As shown, the first device 40 includes a first sending unit 401, a generating unit 402 and a first connecting unit 403; wherein,
[0158] The first sending unit 401 is configured to send a first broadcast message, and receive at least one second broadcast message returned by at least one second device in response to the first broadcast message;
[0159] The generating unit 402 is configured to determine a target second device from at least one second device according to the at least one second broadcast message, and generate a third broadcast message based on a device identifier of the target second device;
[0160] The first connection unit state 403 is configured to establish a Generic Attribute Profile GATT connection with the target second device after sending the third broadcast message.
[0161] In some embodiments, the second broadcast message carries a corresponding device identifier. Accordingly, the generating unit 402 is further configured to determine at least one second device according to the device identifiers respectively carried in at least one second broadcast message; receive a selection instruction from a user, and determine a target second device from the at least one second device according to the selection instruction.
[0162] In some embodiments, Figure 5 As shown, the first device 40 further includes a first control unit 404. The first control unit 404 is configured to establish a GATT service, configure a read characteristic parameter, a read characteristic descriptor, a write characteristic parameter, and a write characteristic descriptor for the GATT service, and the GATT service has a first preset identification code, the read characteristic parameter has a second preset identification code, the read characteristic descriptor has a third preset identification code, the write characteristic parameter has a fourth preset identification code, and the write characteristic descriptor has a fifth preset identification code; after establishing a general attribute profile GATT connection with the target second device, provide the GATT service to the target second device.
[0163] In some embodiments, Figure 5 As shown, the first control unit 404 is further configured to perform Bluetooth communication with the target second device based on the read characteristic parameter; and / or perform Bluetooth communication with the target second device based on the write characteristic parameter.
[0164] In some embodiments, the first control unit 404 is further configured to determine target instruction information; write the target instruction information into the read characteristic descriptor to enable the first device to send the target instruction information to the target second device.
[0165] In some embodiments, the first control unit 404 is further configured to send a modification notification to the target second device, wherein the modification notification is used to instruct the target second device to read the read characteristic descriptor.
[0166] In some embodiments, the first control unit 404 is further configured to read the write characteristic descriptor to obtain target status information after detecting that the target second device performs a modification operation, so as to enable the first device to receive the target status information sent by the target second device; wherein the modification operation refers to the target second device modifying the write characteristic descriptor.
[0167] It can be understood that in this embodiment, the "unit" can be a part of the circuit, a part of the first processor, a part of the program or software, etc., and of course it can also be a module, or it can be non-modular. Moreover, the components in this embodiment can be integrated into a processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The above-mentioned integrated unit can be implemented in the form of hardware or in the form of software functional modules.
[0168] If the integrated unit is implemented in the form of a software function module and is not sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this embodiment is essentially or the part that contributes to the prior art or the whole or part of the technical solution can be embodied in the form of a software product. The computer software product is stored in a storage medium, including several instructions for a computer device (which can be a personal computer, server, or network device, etc.) or a processor (first processor) to perform all or part of the steps of the method of this embodiment. The aforementioned storage medium includes: U disk, mobile hard disk, read-only first memory (Read Only Memory, ROM), random access first memory (Random Access Memory, RAM), disk or optical disk and other media that can store program codes.
[0169] Therefore, this embodiment provides a computer storage medium, which stores a computer program. When the computer program is executed by multiple first processors, the steps of the method in any one of the above embodiments are implemented.
[0170] Based on the above-mentioned composition of the first device 40 and the computer storage medium, see Figure 6 , which shows a hardware structure diagram of a first device 40 provided in an embodiment of the present application. Figure 6 As shown, the first device 40 may include: a first communication interface 501, a first memory 502 and a first processor 503; each component is coupled together via a first bus system 504. It is understood that the first bus system 504 is used to realize the connection and communication between these components. In addition to the data bus, the first bus system 504 also includes a power bus, a control bus and a status signal bus. However, for the sake of clarity, Figure 6 In the figure, various buses are marked as the first bus system 504. Among them, the first communication interface 501 is used for receiving and sending signals in the process of sending and receiving information between other external network elements;
[0171] A first memory 502, used to store a computer program that can be run on the first processor 503;
[0172] The first processor 503 is configured to execute, when running the computer program:
[0173] Sending a first broadcast message, and receiving at least one second broadcast message returned by at least one second device in response to the first broadcast message;
[0174] determining a target second device from the at least one second device according to the at least one second broadcast message, and generating a third broadcast message based on a device identifier of the target second device;
[0175] After sending the third broadcast message, a Generic Attribute Profile GATT connection is established with the target second device.
[0176] It can be understood that the first memory 502 in the embodiment of the present application can be a volatile first memory or a non-volatile first memory, or can include both volatile and non-volatile first memories. Among them, the non-volatile first memory can be a read-only first memory (Read-Only Memory, ROM), a programmable read-only first memory (ProgrammableROM, PROM), an erasable programmable read-only first memory (Erasable PROM, EPROM), an electrically erasable programmable read-only first memory (Electrically EPROM, EEPROM) or a flash memory. The volatile first memory can be a random access first memory (Random Access Memory, RAM), which is used as an external cache. By way of example but not limitation, many forms of RAM are available, such as static random access first memory (Static RAM, SRAM), dynamic random access first memory (Dynamic RAM, DRAM), synchronous dynamic random access first memory (Synchronous DRAM, SDRAM), double data rate synchronous dynamic random access first memory (Double Data Rate SDRAM, DDRSDRAM), enhanced synchronous dynamic random access first memory (Enhanced SDRAM, ESDRAM), synchronous link dynamic random access first memory (Synchronous link DRAM, SLDRAM) and direct memory bus random access first memory (Direct Rambus RAM, DRRAM). The first memory 502 of the apparatus and method described in the present application is intended to include but is not limited to these and any other suitable types of first memory.
[0177] The first processor 503 may be an integrated circuit chip with signal processing capabilities. In the implementation process, each step of the above method can be completed by the hardware integrated logic circuit or software instructions in the first processor 503. The above-mentioned first processor 503 can be a general first processor, a digital signal first processor (DigitalSignal Processor, DSP), an application-specific integrated circuit (Application Specific Integrated Circuit, ASIC), a field programmable gate array (Field Programmable Gate Array, FPGA) or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components. The methods, steps and logic block diagrams disclosed in the embodiments of the present application can be implemented or executed. The general first processor can be a micro first processor or the first processor can also be any conventional first processor, etc. The steps of the method disclosed in the embodiment of the present application can be directly embodied as a hardware decoding first processor to execute, or a combination of hardware and software modules in the decoding first processor to execute. The software module can be located in a mature storage medium in the field such as a random first memory, a flash memory, a read-only first memory, a programmable read-only first memory or an electrically erasable programmable first memory, a register, etc. The storage medium is located in the first memory 502, and the first processor 503 reads the information in the first memory 502 and completes the steps of the above method in combination with its hardware.
[0178] It is understood that the embodiments described in the present application can be implemented by hardware, software, firmware, middleware, microcode or a combination thereof. For hardware implementation, the processing unit can be implemented in one or more application specific integrated circuits (ASIC), digital signal processing (DSP), digital signal processing device (DSPD), programmable logic device (PLD), field programmable gate array (FPGA), general-purpose first processor, controller, microcontroller, micro first processor, other electronic units for performing the functions of the present application or a combination thereof.
[0179] For software implementation, the technology of the present application can be implemented by a module (e.g., a process, a function, etc.) that performs the functions of the present application. The software code can be stored in a first memory and executed by a first processor. The first memory can be implemented in the first processor or outside the first processor.
[0180] Optionally, as another embodiment, the first processor 503 is further configured to execute the steps of the method in any one of the aforementioned embodiments when running the computer program.
[0181] The embodiment of the present application provides a first device, which includes a first sending unit, a generating unit and a first connecting unit. Through the interaction of three broadcast messages, the first device and the second device can establish a GATT connection, and then realize Bluetooth communication without Bluetooth pairing, thereby improving the convenience and versatility of Bluetooth communication; with the help of multiple broadcast messages, the first device can accurately connect to the designated target second device. In addition, since the first device is the server of GATT and the second device is the responder of GATT, it can also allow multiple first devices to simultaneously control the second device through Bluetooth.
[0182] In yet another embodiment of the present application, see Figure 7 , which shows a schematic diagram of the composition structure of a second device 60 provided in an embodiment of the present application. Figure 7 As shown, the second device 60 includes a responding unit 601, a second sending unit 602 and a second connecting unit 603, wherein:
[0183] The responding unit 601 is configured to generate a second broadcast message in response to the first broadcast message sent by the first device;
[0184] The second sending unit 602 is configured to receive a third broadcast message sent by the first device after sending the second broadcast message;
[0185] The second connection unit 603 is configured to establish a GATT connection with the first device when the third broadcast message carries the device identifier of the second device.
[0186] In some embodiments, Figure 7 As shown, the second device 60 also includes a second control unit 604. The second control unit 604 is configured to, after calling the preset connection interface of the first device, obtain the GATT service provided by the first device based on the first preset identification code; wherein the GATT service is created by the first device before sending the third broadcast message; based on the second preset identification code, obtain the read characteristic parameter of the GATT service, and based on the third preset identification code, obtain the read characteristic descriptor; and determine the target instruction information sent by the first device according to the obtained read characteristic descriptor.
[0187] In some embodiments, the second control unit 604 is further configured to obtain the write characteristic parameters of the GATT service based on the fourth preset identification code, and obtain the write characteristic descriptor based on the fifth preset identification code; when a change in the status information of the first device is detected, determine the target status information; and write the target status information into the write characteristic descriptor.
[0188] It can be understood that in this embodiment, a "unit" can be a part of a circuit, a part of a processor, a part of a program or software, etc., and of course it can also be a module, or it can be non-modular. Moreover, the components in this embodiment can be integrated into a processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The above-mentioned integrated unit can be implemented in the form of hardware or in the form of a software functional module.
[0189] If the integrated unit is implemented in the form of a software function module and is not sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, this embodiment provides a computer storage medium, which is applied to the second device 60. The computer storage medium stores a storage management program, and when the host classification program is executed by the second processor, the method of any one of the above embodiments is implemented.
[0190] Based on the composition of the second device 60 and the computer storage medium, see Figure 8 , which shows a specific hardware structure example of the second device 60 provided in an embodiment of the present application, such as Figure 8 As shown, the second device 60 may include: a second communication interface 701, a second memory 702, and a second processor 703; each component is coupled together via a second bus system 704. It is understood that the second bus system 704 is used to achieve connection and communication between these components. In addition to the data bus, the second bus system 704 also includes a power bus, a control bus, and a status signal bus. However, for the sake of clarity, Figure 8 In FIG. 7 , various buses are labeled as the second bus system 704. Among them,
[0191] The second communication interface 701 is used for receiving and sending signals during the process of sending and receiving information with other external network elements;
[0192] The second memory 702 is used to store a computer program that can be run on the second processor 703;
[0193] The second processor 703 is configured to execute, when running the computer program:
[0194] generating a second broadcast message in response to a first broadcast message sent by the first device;
[0195] After sending the second broadcast message, receiving a third broadcast message sent by the first device;
[0196] When the third broadcast message carries the device identification of the second device, a GATT connection is established with the first device.
[0197] Optionally, as another embodiment, the second processor 703 is further configured to execute any method in the foregoing embodiments when running the computer program.
[0198] It can be understood that the hardware functions of the second memory 702 and the first memory 502 are similar, and the hardware functions of the second processor 703 and the first processor 503 are similar; they will not be described in detail here.
[0199] The embodiment of the present application provides a second device, which includes a response unit, a second sending unit, and a second connection unit. Through the interaction of three broadcast messages, the first device and the second device can establish a GATT connection, and then realize Bluetooth communication without Bluetooth pairing, thereby improving the convenience and versatility of Bluetooth communication; with the help of multiple broadcast messages, the first device can accurately connect to the designated target second device. In addition, since the first device is the server of GATT and the second device is the responder of GATT, it can also allow multiple first devices to simultaneously control the second device through Bluetooth.
[0200] In yet another embodiment of the present application, see Fig. 9 , which shows a schematic diagram of the structure of a Bluetooth communication system 80 provided in an embodiment of the present application. Fig. 9 As shown, the Bluetooth communication system 80 may include at least the first device 40 of any one of the aforementioned embodiments and the second device 60 of any one of the aforementioned embodiments.
[0201] In the embodiment of the present application, since the Bluetooth communication system 80 includes at least the first device 40 and the second device 60 of any one of the aforementioned embodiments, through the interaction of three broadcast messages, the first device and the second device can establish a GATT connection, and then realize Bluetooth communication without Bluetooth pairing, thereby improving the convenience and versatility of Bluetooth communication; with the help of multiple broadcast messages, the first device can accurately connect to the designated target second device. In addition, since the first device is the server of GATT and the second device is the responder of GATT, it can also allow multiple first devices to simultaneously control the second device through Bluetooth.
[0202] The above are only preferred embodiments of the present application and are not intended to limit the protection scope of the present application.
[0203] It should be noted that, in this application, the terms "include", "comprises" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, an element defined by the sentence "includes a ..." does not exclude the existence of other identical elements in the process, method, article or device including the element.
[0204] The serial numbers of the above-mentioned embodiments of the present application are for description only and do not represent the advantages or disadvantages of the embodiments.
[0205] The methods disclosed in several method embodiments provided in this application can be arbitrarily combined without conflict to obtain new method embodiments.
[0206] The features disclosed in several product embodiments provided in this application can be arbitrarily combined without conflict to obtain new product embodiments.
[0207] The features disclosed in several method or device embodiments provided in this application can be arbitrarily combined without conflict to obtain new method embodiments or device embodiments.
[0208] The above are only specific implementations of the present application, but the protection scope of the present application is not limited thereto. Any technician familiar with the technical field can easily think of changes or substitutions within the technical scope disclosed in the present application, which should be included in the protection scope of the present application. Therefore, the protection scope of the present application should be based on the protection scope of the claims.
Claims
1. A Bluetooth communication method, It is characterized in that Applied to a first device, the method includes: Sending a first broadcast message including a target field, and receiving at least one second broadcast message returned by at least one second device in response to the first broadcast message; the target field is used to trigger a response from the second device, and the second broadcast message carries a device identifier of the second device; Determine a target second device from the at least one second device according to the device identifiers respectively carried in the at least one second broadcast message, and generate a third broadcast message based on the device identifiers of the target second device; After sending the third broadcast message, a general attribute profile GATT connection is established with the target second device; the first device is a server of the GATT connection, and the target second device is a client of the GATT connection; After establishing a GATT connection with the target second device, the method further includes: A GATT service is provided to the target second device.
2. The Bluetooth communication method according to claim 1, It is characterized in that The determining the target second device from the at least one second device according to the device identifiers respectively carried in the at least one second broadcast message includes: Determining the at least one second device according to the device identifiers respectively carried in the at least one second broadcast message; A selection instruction is received from a user, and the target second device is determined from the at least one second device according to the selection instruction.
3. The Bluetooth communication method according to claim 1, It is characterized in that Before sending the third broadcast message, the method further includes: A GATT service is established, and a read characteristic parameter, a read characteristic descriptor, a write characteristic parameter, and a write characteristic descriptor are configured for the GATT service, wherein the GATT service has a first preset identification code, the read characteristic parameter has a second preset identification code, the read characteristic descriptor has a third preset identification code, the write characteristic parameter has a fourth preset identification code, and the write characteristic descriptor has a fifth preset identification code.
4. The Bluetooth communication method according to claim 3, It is characterized in that The method further comprises: Based on the read characteristic parameter, performing Bluetooth communication with the target second device; and / or Based on the write characteristic parameter, Bluetooth communication is performed with the target second device.
5. The Bluetooth communication method according to claim 4, It is characterized in that The performing Bluetooth communication with the target second device based on the read characteristic parameter includes: Determine target instruction information; The target instruction information is written into the read characteristic descriptor, so that the first device sends the target instruction information to the target second device.
6. The Bluetooth communication method according to claim 5, It is characterized in that After writing the target instruction information into the read characteristic descriptor, the method further includes: Sending a modification notification to the target second device; The modification notification is used to instruct the target second device to read the read characteristic descriptor.
7. The Bluetooth communication method according to claim 4, It is characterized in that The performing Bluetooth communication with the target second device based on the writing characteristic parameter includes: After detecting that the target second device performs a modification operation, reading the write characteristic descriptor to obtain target state information, so that the first device receives the target state information sent by the target second device; The modification operation refers to the target second device modifying the write characteristic descriptor.
8. A Bluetooth communication method, It is characterized in that Applied to the second device, the method includes: In response to a first broadcast message sent by a first device and containing a target field, generating a second broadcast message; the target field is used to trigger a response from the second device, and the second broadcast message carries a device identifier of the second device; After sending the second broadcast message, receiving a third broadcast message sent by the first device; In a case where the third broadcast message carries the device identifier of the second device, a GATT connection is established with the first device; the first device is a server of the GATT connection, and the second device is a client of the GATT connection; After establishing a GATT connection with the first device, the method further includes: The GATT service provided by the first device is called.
9. The Bluetooth communication method according to claim 8, It is characterized in that The establishing a GATT connection with the first device includes: After calling a preset connection interface of the first device, acquiring a GATT service provided by the first device based on a first preset identification code; wherein the GATT service is created by the first device before sending the third broadcast message; Based on the second preset identification code, obtaining a read characteristic parameter of the GATT service, and based on the third preset identification code, obtaining a read characteristic descriptor; The target instruction information sent by the first device is determined according to the acquired read characteristic descriptor.
10. The Bluetooth communication method according to claim 8, It is characterized in that The establishing a GATT connection with the first device includes: Acquire a write characteristic parameter of the GATT service based on a fourth preset identification code, and acquire a write characteristic descriptor based on a fifth preset identification code; When detecting that the state information of the first device changes, determining target state information; The target status information is written into the write characteristic descriptor.
11. A first device, It is characterized in that The first device includes a first sending unit, a generating unit, a first connecting unit and a first controlling unit; wherein, The first sending unit is configured to send a first broadcast message including a target field, and receive at least one second broadcast message returned by at least one second device in response to the first broadcast message; the target field is used to trigger a response from the second device, and the second broadcast message carries a device identifier of the second device; The generating unit is configured to determine a target second device from the at least one second device according to the device identifiers respectively carried in the at least one second broadcast message, and generate a third broadcast message based on the device identifiers of the target second device; The first connection unit is configured to establish a general attribute profile GATT connection with the target second device after sending the third broadcast message; the first device is a server of the GATT connection, and the target second device is a client of the GATT connection; The first control unit is configured to provide GATT services to the target second device after establishing a general attribute profile GATT connection with the target second device.
12. A first device, It is characterized in that The first device includes a first memory and a first processor; wherein, The first memory is used to store a computer program that can be run on the processor; The first processor is configured to execute the steps of the method according to any one of claims 1 to 7 when running the computer program.
13. A second device, It is characterized in that The second device includes a response unit, a second sending unit, a second connection unit and a second control unit; wherein, The response unit is configured to generate a second broadcast message in response to a first broadcast message sent by the first device and containing a target field; the target field is used to trigger a response from the second device, and the second broadcast message carries a device identifier of the second device; The second sending unit is configured to receive a third broadcast message sent by the first device after sending the second broadcast message; The second connection unit is configured to establish a GATT connection with the first device when the device identifier of the second device is carried in the third broadcast message; the first device is a server of the GATT connection, and the second device is a client of the GATT connection; The second control unit is configured to call the GATT service provided by the first device after establishing a GATT connection with the first device.
14. A second device, It is characterized in that The second device includes: a second memory and a second processor; wherein, The second memory is used to store a computer program that can be run on the processor; The second processor is configured to execute the steps of the method according to any one of claims 8 to 10 when running the computer program.
15. A computer storage medium, It is characterized in that The computer storage medium stores a computer program, which implements the steps of the method according to any one of claims 1 to 7 when executed by a first processor, or implements the steps of the method according to any one of claims 8 to 10 when executed by a second processor.
Citation Information
Patent Citations
Information interaction method between on-board terminals, and on-board terminal
CN105723753A
Service data transmission method, apparatus and system
CN107465994A
Method for discovering bluetooth device and bluetooth device
CN108605371A
A source device broadcasts synchronization information associated with a bluetooth isochronous channel
CN108702720A
Information pushing method and system, server and computer readable storage medium
CN110012049A
