Bluetooth device discovery method, device, terminal and storage medium
By using the corresponding relationship between the device information and the name in the RNR cache file in Bluetooth device discovery, the device name is directly displayed, which solves the problem of slow device discovery in the existing technology and achieves more efficient device discovery.
Patent Information
- Application Number
- CN202110931811.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-08-13
- Publication Date
- 2024-10-01
- Estimated Expiration
- 2041-08-13
AI Technical Summary
In the existing Bluetooth device discovery method, the device name is obtained by broadcasting device query requests and sending remote name requests (RNR), resulting in slow device discovery.
When the response result received from the target Bluetooth device does not contain the device name, the corresponding relationship between the device information and the name stored in the RNR cache file is used to directly query and display the device name without sending an RNR request to the target Bluetooth device.
It simplifies the discovery process of Bluetooth devices, shortens the device discovery time, improves device discovery efficiency, and avoids device discovery failures caused by RNR failure.
Smart Images

Figure CN113660649B_ABST
Abstract
Description
Technical Field
[0001] The embodiments of the present application relate to the field of Bluetooth technology, and in particular to a method, apparatus, terminal and storage medium for discovering a Bluetooth device. Background Art
[0002] Bluetooth technology is a radio technology that supports short-range communication between devices (e.g., within 10 meters). Bluetooth technology enables wireless information exchange between devices.
[0003] In the related art, when a Bluetooth device discovers a surrounding Bluetooth device, it first broadcasts a device inquiry request, and after receiving a device inquiry response sent by the surrounding Bluetooth device, it further sends a remote name request (RNR) to the surrounding Bluetooth device to obtain the device name of the surrounding Bluetooth device.
[0004] However, in the above method, the Bluetooth device needs to broadcast a device query request and send an RNR to complete device discovery, and the speed of device discovery is slow. Summary of the invention
[0005] The embodiments of the present application provide a method, apparatus, terminal and storage medium for discovering a Bluetooth device, which can shorten the discovery time of a Bluetooth device and improve the discovery efficiency of a Bluetooth device. The technical solution is as follows:
[0006] On the one hand, an embodiment of the present application provides a method for discovering a Bluetooth device, the method comprising:
[0007] Broadcast device query request;
[0008] In response to receiving a response result of the target Bluetooth device to the device query request, and the response result does not include the target device name of the target Bluetooth device, querying the RNR cache file based on the target device information of the target Bluetooth device, the RNR cache file includes the correspondence between the device information of the Bluetooth device and the device name, and the device name is obtained by the terminal by sending the RNR;
[0009] In response to querying the target device name of the target Bluetooth device from the RNR cache file, the target device name is displayed.
[0010] On the other hand, an embodiment of the present application provides a device for discovering a Bluetooth device, the device comprising:
[0011] Broadcast module, used to broadcast device query requests;
[0012] A query module, configured to query an RNR cache file based on the target device information of the target Bluetooth device in response to receiving a response result of the target Bluetooth device to the device query request, and the response result does not include a target device name of the target Bluetooth device, wherein the RNR cache file includes a correspondence between the device information of the Bluetooth device and the device name, and the device name is obtained by the terminal by sending the RNR;
[0013] The display module is used for displaying the target device name in response to querying the target device name of the target Bluetooth device from the RNR cache file.
[0014] On the other hand, an embodiment of the present application provides a terminal, which includes a processor and a memory, wherein the memory stores at least one instruction, and the instruction is loaded and executed by the processor to implement a method for discovering a Bluetooth device as provided in various aspects of the present application.
[0015] On the other hand, an embodiment of the present application provides a computer-readable storage medium, in which at least one instruction is stored. The instruction is loaded and executed by a processor to implement a method for discovering a Bluetooth device as provided in various aspects of the present application.
[0016] On the other hand, an embodiment of the present application provides a computer program product, which includes computer instructions, which are stored in a computer-readable storage medium. A processor of a computer device reads the computer instructions from the computer-readable storage medium, and the processor executes the computer instructions, so that the computer device executes the Bluetooth device discovery method provided in the above various optional implementations.
[0017] The beneficial effects brought by the technical solution provided by the embodiments of the present application may include:
[0018] In an embodiment of the present application, the device information of the Bluetooth device obtained by the terminal's historical sending of RNR is stored in the RNR cache file. When a device query request is broadcast and the target device name is not obtained from the response result of the target Bluetooth device, the RNR cache is first queried based on the correspondence between the device information and the device name in the RNR cache file to see whether there is the name of the target Bluetooth device in the file. When the target device name of the target Bluetooth device is included in the RNR cache file, the target device name of the target Bluetooth device is directly displayed without sending RNR to the target Bluetooth device to obtain the device name of the target Bluetooth device. This simplifies the discovery process of the Bluetooth device, thereby shortening the discovery time of the Bluetooth device and improving the discovery efficiency of the Bluetooth device. BRIEF DESCRIPTION OF THE DRAWINGS
[0019] In order to more clearly introduce the technical solutions in the embodiments of the present application, the drawings required for use in the description of the embodiments of the present application will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0020] Figure 1 is a schematic diagram of an implementation environment provided by an exemplary embodiment of the present application;
[0021] Figure 2 is a flowchart of a method for discovering a Bluetooth device provided by an exemplary embodiment of the present application;
[0022] Figure 3 is a flowchart of a method for discovering a Bluetooth device provided by another exemplary embodiment of the present application;
[0023] Figure 4 is a flowchart of a method for discovering a Bluetooth device provided by another exemplary embodiment of the present application;
[0024] Figure 5 It is a schematic diagram of an implementation of a Bluetooth device discovery and RNR cache file update process shown in an exemplary embodiment of the present application;
[0025] Figure 6 is a structural block diagram of a discovery device for a Bluetooth device shown in an exemplary embodiment of the present application;
[0026] Figure 7 It is a structural block diagram of a terminal provided by an exemplary embodiment of the present application. DETAILED DESCRIPTION
[0027] In order to make the objectives, technical solutions and advantages of the present application clearer, the implementation methods of the present application will be further described in detail below with reference to the accompanying drawings.
[0028] When the following description refers to the drawings, unless otherwise indicated, the same numbers in different drawings represent the same or similar elements. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with the present application. Instead, they are only examples of devices and methods consistent with some aspects of the present application as detailed in the attached claims.
[0029] Please refer to Figure 1 , which shows a schematic diagram of an implementation environment provided by an exemplary embodiment of the present application, wherein the implementation environment includes a terminal 110 and a Bluetooth device 120.
[0030] Both the terminal 110 and the Bluetooth device 120 are electronic devices with Bluetooth function, which may be smart phones, tablet computers, wearable devices, personal computers, etc. The embodiments of the present application do not limit the specific types of the terminal 110 and the Bluetooth device 120.
[0031] The Bluetooth functions of the terminal 110 and the Bluetooth device 120 may be implemented through a built-in Bluetooth chip or an external Bluetooth component, which is not limited in this embodiment.
[0032] In the embodiment of the present application, the terminal 110 is an electronic device having a Bluetooth device discovery function, and the Bluetooth device 120 is an electronic device to be discovered. Figure 1 As shown, the terminal 110 is a smart phone, and the Bluetooth device 120 includes a Bluetooth headset, a smart phone, and a tablet computer located within the Bluetooth discovery range of the smart phone.
[0033] In a possible application scenario, the terminal 110 and the Bluetooth device 120 both turn on the Bluetooth function, the terminal 110 broadcasts a device query request to the surrounding area, and the Bluetooth device 120 receives the device query request, responds to the device query request and sends the response result to the terminal 110. After receiving the response result sent by the Bluetooth device, if the terminal 110 successfully obtains the device name of the Bluetooth device 120, the device name of the Bluetooth device 120 is displayed in the Bluetooth scan list 111 ( Figure 1 The scan list 111 includes the device names of the discovered Bluetooth headset, smart phone and tablet computer. Further, when a Bluetooth connection operation is received, the terminal 110 initiates a connection establishment request to the selected Bluetooth device, thereby establishing a Bluetooth connection with the selected Bluetooth device, and then performing data transmission through the Bluetooth connection.
[0034] For the convenience of description, the following embodiments are applied to the discovery method of the Bluetooth device. Figure 1 The implementation environment shown is used as an example.
[0035] Please refer to Figure 2 , which shows a flowchart of a method for discovering a Bluetooth device shown in an exemplary embodiment of the present application, the method comprising:
[0036] Step 201, broadcast device query request.
[0037] In a possible implementation, when the terminal turns on the Bluetooth scanning function, it will broadcast a device query request to a certain range nearby. The device query request includes the address of the terminal and other relevant information. The embodiment of the application does not limit the specific content included in the device query request.
[0038] Optionally, the device query request is triggered by a user to broadcast the terminal.
[0039] For example, when a user wants to use a terminal to exchange information with a surrounding Bluetooth device, the user can click a "Bluetooth On" button on the Bluetooth function interface to trigger the Bluetooth chip in the terminal to broadcast a query request to the surrounding devices.
[0040] Optionally, the terminal may periodically broadcast a device query request.
[0041] Step 202, in response to receiving a response result of the target Bluetooth device to the device query request, and the response result does not include the target device name of the target Bluetooth device, query the RNR cache file based on the target device information of the target Bluetooth device, the RNR cache file contains the correspondence between the device information of the Bluetooth device and the device name, and the device name is obtained by the terminal by sending RNR.
[0042] Different from the related technology, when the response result received by the terminal does not contain the device name of the Bluetooth device, the terminal directly sends RNR to the Bluetooth device to obtain the device name. In the embodiment of the present application, when the terminal receives a response result sent by the target Bluetooth device and the response result does not contain the device name, the terminal first attempts to query the device name of the target Bluetooth device from the RNR cache file.
[0043] In an embodiment of the present application, the RNR cache file contains device information of Bluetooth devices that have historically performed RNR. The device information is used to uniquely identify the Bluetooth device. For example, the device information may be the Bluetooth address of the Bluetooth device, etc., and the device name of the Bluetooth device is associated with the device information of the Bluetooth device and stored so that the terminal can accurately query the device name of the Bluetooth device from the RNR cache file based on the device information.
[0044] It should be noted that if the response result of the target Bluetooth device includes a device name, the terminal can directly determine the device name in the response result as the target device name of the target Bluetooth device without querying the RNR cache file.
[0045] Step 203: In response to querying the target device name of the target Bluetooth device from the RNR cache file, display the target device name.
[0046] Based on the correspondence between the device name of the Bluetooth device and other device information in the RNR cache file, the terminal can query the target device name from the RNR cache file. After obtaining the device name of the target Bluetooth device, the terminal will display the target device name of the target Bluetooth device without the need for RNR operation.
[0047] In an embodiment of the present application, the target Bluetooth device will first query the RNR cache file, and then determine whether an RNR operation is still required based on the query result (no RNR operation is required when the query is completed). Compared with directly performing RNR operations in related technologies, the solution provided in an embodiment of the present application can shorten the discovery time of the Bluetooth device and avoid the problem of device discovery failure caused by RNR failure.
[0048] To sum up, in an embodiment of the present application, the device information of the Bluetooth device obtained by the terminal historically sending RNR is stored in the RNR cache file. When a device query request is broadcast and the target device name is not obtained from the response result of the target Bluetooth device, the RNR cache is first queried whether there is the name of the target Bluetooth device in the file based on the correspondence between the device information and the device name in the RNR cache file. When the target device name of the target Bluetooth device is included in the RNR cache file, the target device name of the target Bluetooth device is directly displayed without sending RNR to the target Bluetooth device to obtain the device name of the target Bluetooth device. This simplifies the discovery process of the Bluetooth device, thereby shortening the discovery time of the Bluetooth device and improving the discovery efficiency of the Bluetooth device.
[0049] In the embodiment of the present application, there are the following cases for the case where the device name of the target Bluetooth name is not included in the above response result:
[0050] 1. In response to receiving a device inquiry response from a target Bluetooth device and not receiving an extended inquiry response (Extended Inquiry Result, EIR) from the target Bluetooth device, querying the RNR cache file.
[0051] EIR is an extended response to a device inquiry request, which is usually fed back to the terminal by the Bluetooth device after sending a device inquiry response, and contains other device information (such as device name) besides the Bluetooth address. However, since not all Bluetooth devices support the EIR mechanism, when the terminal receives a device inquiry response from the target Bluetooth device and does not receive the EIR of the target Bluetooth device, it is necessary to query the device name of the target Bluetooth device in the RNR cache file.
[0052] 2. In response to receiving a device query response from a target Bluetooth device and receiving an EIR of the target Bluetooth device, parsing the EIR; in response to the EIR not containing a device name of the target Bluetooth device, querying an RNR cache file.
[0053] In one possible implementation, when the terminal receives a device query response from a target Bluetooth device and an EIR from the target Bluetooth device, the terminal will parse the EIR. When it is found after parsing the EIR that the EIR does not contain the device name of the target Bluetooth device, the terminal will query the device name of the target Bluetooth device in the RNR cache file.
[0054] Optionally, if the target Bluetooth device fails to find the target device name of the target Bluetooth device in the RNR cache file, it sends RNR to the target Bluetooth device. The target Bluetooth device receives the RNR sent by the terminal, responds to the RNR, and feeds the RNR response back to the terminal. This process takes a long time, and RNR has a certain failure rate, which may cause the Bluetooth device to be discovered for a long time, or even the Bluetooth device cannot be discovered.
[0055] Please refer to Figure 3 , which shows a flowchart of a method for discovering a Bluetooth device provided by another exemplary embodiment of the present application, the method comprising:
[0056] Step 301, broadcast device query request.
[0057] Step 302: in response to receiving a response result of the target Bluetooth device to the device query request, and the response result does not include the target device name of the target Bluetooth device, obtain the target Bluetooth address of the target Bluetooth device from the response result.
[0058] When the terminal receives the response result of the target Bluetooth device to the device query request, the terminal will parse the response result. If the response result does not contain the target Bluetooth name of the target Bluetooth device, the target Bluetooth address of the target Bluetooth device can be obtained from the parsed response result.
[0059] In the embodiment of the present application, the Bluetooth address and device name of the Bluetooth device are stored in the RNR cache file, and there is a corresponding relationship between the Bluetooth address and the device name of the Bluetooth device. Therefore, after obtaining the target Bluetooth address of the target Bluetooth device, it is possible to query whether the target device name of the target Bluetooth device is stored in the RNR cache file based on the corresponding relationship between the target Bluetooth address and the Bluetooth address and device name of the Bluetooth device in the RNR cache file.
[0060] Step 303, query the RNR cache file based on the target Bluetooth address.
[0061] After obtaining the target Bluetooth address of the target Bluetooth device from the response result, the terminal can query in the RNR cache file whether there is a Bluetooth device consistent with the target Bluetooth address based on the correspondence between the Bluetooth address and the device name in the RNR cache file.
[0062] Schematically, when the terminal discovers the surrounding Bluetooth devices, it obtains the Bluetooth address of a Bluetooth device as Bluetooth address 1, but does not obtain the device name of the Bluetooth device. At this time, according to the correspondence between the Bluetooth address and the device name in the RNR cache file, it can be queried in the RNR cache file whether there is a matching Bluetooth address that is consistent with the target Bluetooth address. The correspondence between the Bluetooth address and the device name of the Bluetooth device in the RNR cache file is shown in Table 1 below:
[0063] Table 1
[0064] Bluetooth Address Device Name Bluetooth Address 1 Zhao Er's Computer Bluetooth Address 2 Li Si's headphones Bluetooth Address 3 Zhang San's mobile phone Bluetooth Address 4 Qian San's watch Bluetooth Address 5 Wang Wu's MP3
[0065] Step 304: In response to the presence of a matching Bluetooth address identical to the target Bluetooth address in the RNR cache file, a device name corresponding to the matching Bluetooth address is determined as the target device name.
[0066] Based on the correspondence in Table 1 above, when there is a matching Bluetooth address in the RNR cache file that is consistent with the target Bluetooth address, the device name corresponding to the matching Bluetooth address can be determined as the target device name of the target Bluetooth device according to the correspondence.
[0067] Illustratively, when the Bluetooth address of the target Bluetooth device is Bluetooth address 1, and the terminal finds a Bluetooth address consistent with the Bluetooth address in the RNR cache file, it can query the device name of the Bluetooth device through the corresponding relationship in the above RNR cache file. As can be seen from the above table, the device name of the Bluetooth device with the Bluetooth address of Bluetooth address 1 is "Zhao Er's Computer". At this time, the terminal can use "Zhao Er's Computer" as the target device name of the target Bluetooth device and display it.
[0068] Since the device name of a Bluetooth device is not fixed, if the device name of a Bluetooth device is added to the RNR cache file, and the user modifies the device name of the Bluetooth device but the RNR cache file is not updated accordingly, then the next time the Bluetooth device is discovered, the displayed device name will be inconsistent with the actual device name.
[0069] In an embodiment of the present application, in order to better utilize the RNR cache file and improve the accuracy of the device name displayed based on the RNR cache file, when the terminal generates the RNR cache file, it can obtain the current timestamp when obtaining the device name of the Bluetooth device, and add the current timestamp as the cache timestamp to the RNR cache file, thereby forming a correspondence between the Bluetooth address, device name and cache timestamp of the Bluetooth device. When the target device name is subsequently obtained based on the RNR cache file, the terminal can further determine whether the obtained target device name is valid (i.e., whether it has not been updated for a long time) based on the cache timestamp.
[0070] In a possible implementation, Figure 4 As shown, this step includes the following steps 304A and 304B:
[0071] Step 304A, in response to the presence of a matching Bluetooth address identical to the target Bluetooth address in the RNR cache file, obtaining a cache timestamp corresponding to the matching Bluetooth address, where the cache timestamp is used to indicate the time when the matching Bluetooth address is added to the RNR cache file;
[0072] Based on the correspondence between the Bluetooth address, device name and cache timestamp of the Bluetooth device in the above steps, the terminal can further obtain the cache timestamp corresponding to the matching Bluetooth address when a matching Bluetooth address is queried.
[0073] Schematically, the correspondence between the three in the RNR cache file should be as shown in Table 2 below:
[0074] Table 2
[0075] Bluetooth Address Device Name Cache timestamp Bluetooth Address 1 Zhao Er's Computer 2021.7.22.12:00:00 Bluetooth Address 2 Li Si's headphones 2021.7.22.14:00:00 Bluetooth Address 3 Zhang San's mobile phone 2021.7.12.02:00:00 Bluetooth Address 4 Qian San's watch 2021.5.22.22:00:00 Bluetooth Address 5 Wang Wu's MP3 2021.7.02.08:00:00
[0076] In an illustrative example, when the matching Bluetooth address is queried as Bluetooth address 1, the terminal further obtains the cache timestamp corresponding to the matching Bluetooth address as "2021.7.22.12:00:00" (indicating that Bluetooth address 1 is added to the RNR cache file at 2021.7.22.12:00:00).
[0077] Step 304B: in response to the time interval between the cached timestamp and the current timestamp being less than the interval threshold, determining the device name corresponding to the matching Bluetooth address as the target device name.
[0078] When the corresponding relationship in the RNR cache file has not been updated for a long time, the problem of inconsistency between the cached device name and the actual device name may occur. Therefore, in a possible implementation method, the terminal calculates the time interval between the cache timestamp corresponding to the matching Bluetooth address and the current timestamp, and then determines whether the device name corresponding to the matching Bluetooth address is valid by comparing the size relationship between the time interval and the interval threshold.
[0079] Optionally, when the time interval between the cached timestamp and the current timestamp is less than the interval threshold, the terminal determines that the device name corresponding to the matching Bluetooth address is valid, thereby determining the device name corresponding to the matching Bluetooth address in the RNR cache file as the target device name of the target Bluetooth device.
[0080] Optionally, the interval threshold may be a default setting for the terminal, or may be set by a user, which is not limited in this embodiment.
[0081] Indicatively, combined with the corresponding relationship shown in Table 2, when the matching Bluetooth address is queried as Bluetooth address 1, the terminal calculates the time interval as 55 hours based on the cache timestamp corresponding to Bluetooth address 1 and the current timestamp 2021.7.24.19:00:00. Since the time interval is less than the interval threshold (for example, 72 hours), the terminal determines "Zhao Er's Computer" as the target device name.
[0082] Optionally, when the time interval is greater than the interval threshold, such as Figure 4 As shown, the terminal can obtain and display the target device name through the following steps:
[0083] Step 308: In response to the time interval between the cached timestamp and the current timestamp being greater than the interval threshold, sending the RNR to the target Bluetooth device.
[0084] When the time interval between the cached timestamp and the current timestamp is greater than the interval threshold, the terminal determines that the device name corresponding to the matching Bluetooth address is invalid and needs to send an RNR to the target Bluetooth device to regain the target device name of the target Bluetooth device.
[0085] In schematic form, combined with the correspondence shown in Table 2, when the matching Bluetooth address is queried as Bluetooth address 5, the terminal determines that the time interval between the two is greater than the interval threshold (for example, 72 hours) based on the cache timestamp corresponding to Bluetooth address 5 and the current timestamp 2021.7.24.19:00:00. Therefore, the terminal determines that the device name "Wang Wu's MP3" is invalid, and sends RNR to the target Bluetooth device based on the matching Bluetooth address to obtain the current device name of the target Bluetooth device.
[0086] Step 309: Receive the RNR response sent by the target Bluetooth device.
[0087] Step 310, display the target device name contained in the RNR response, and update the target device name and the current timestamp to the RNR cache file.
[0088] In one possible implementation, the terminal displays the target Bluetooth name contained in the RNR response, and based on the target Bluetooth name in the RNR response and the current timestamp, updates the device name matching the Bluetooth address in the RNR cache file (updated if the cached device name is inconsistent with the target Bluetooth name in the RNR response) and the cache timestamp.
[0089] Combined with the example in the above steps, the terminal sends RNR to the target Bluetooth device based on Bluetooth address 5, obtains the device name from the RNR response fed back by the target Bluetooth device, and updates the device name and cache timestamp corresponding to Bluetooth address 5. The corresponding relationship in the updated RNR cache file is shown in Table 3 below:
[0090] Table 3
[0091] Bluetooth Address Device Name Cache timestamp Bluetooth Address 1 Zhao Er's Computer 2021.7.22.12:00:00 Bluetooth Address 2 Li Si's headphones 2021.7.22.14:00:00 Bluetooth Address 3 Zhang San's mobile phone 2021.7.12.02:00:00 Bluetooth Address 4 Qian San's watch 2021.5.22.22:00:00 Bluetooth Address 5 Xiao Ming's MP3 2021.7.24.19:00:10
[0092] It should be noted that in other possible implementations, the terminal may also update the RNR cache file (filtering data with a time interval greater than the interval threshold) at predetermined intervals based on the cache timestamp and the current timestamp in the RNR cache file. This embodiment does not limit this.
[0093] Step 305: Display the target device name.
[0094] Step 306: In response to not finding the target device name of the target Bluetooth device from the RNR cache file, sending an RNR to the target Bluetooth device.
[0095] When the terminal fails to find the device name of the target Bluetooth device in the RNR cache file, the terminal will send RNR to the target Bluetooth device through the built-in Bluetooth chip or external Bluetooth component. After receiving the RNR sent by the terminal, the target Bluetooth device will respond to the RNR and send the RNR response to the terminal, so that the terminal can obtain the target device name of the target Bluetooth device.
[0096] Step 307: Receive the RNR response sent by the target Bluetooth device, and add the target device name included in the RNR response to the RNR cache file.
[0097] In a possible implementation, the device name included in the RNR response and the target Bluetooth address of the target Bluetooth device are associated and stored in the RNR cache file. Optionally, when the RNR cache file includes a cache timestamp, the terminal also needs to write the current timestamp as the cache timestamp into the RNR cache file.
[0098] Indicatively, the terminal does not find a matching Bluetooth address consistent with Bluetooth address 6 in the corresponding relationship shown in Table 3, and thus sends an RNR to the target Bluetooth device based on Bluetooth address 6, and obtains the device name "Xiaohong's Bluetooth headset" from the RNR response fed back by the target Bluetooth device, and then updates the RNR cache file according to the device name and the current timestamp. The corresponding relationship in the updated RNR cache file is shown in Table 4 below: Table 4
[0099] Bluetooth Address Device Name Cache timestamp Bluetooth Address 1 Zhao Er's Computer 2021.7.22.12:00:00 Bluetooth Address 2 Li Si's headphones 2021.7.22.14:00:00 Bluetooth Address 3 Zhang San's mobile phone 2021.7.12.02:00:00 Bluetooth Address 4 Qian San's watch 2021.5.22.22:00:00 Bluetooth Address 5 Xiao Ming's MP3 2021.7.24.19:00:10 Bluetooth Address 6 Xiaohong's Bluetooth Headset 2021.7.24.19:00:10
[0100] In actual application scenarios, the terminal may receive RNR responses sent by many surrounding Bluetooth devices. If the device names of all discovered Bluetooth devices are stored in the RNR cache file, the RNR cache file will be too large, occupying a large storage space and affecting the query speed of the RNR cache file.
[0101] Usually, the Bluetooth devices that the user expects to discover quickly are usually located near the terminal, and there is no high requirement for the discovery speed of Bluetooth devices far away from the terminal. Therefore, the terminal can only cache the device names of Bluetooth devices within a certain range nearby.
[0102] In a possible implementation, when an RNR response sent by a target Bluetooth device is received and the received signal strength (RSSI) of the target Bluetooth device is greater than a strength threshold, the terminal adds the target device name included in the RNR response to the RNR cache file.
[0103] Optionally, when an RNR response sent by a target Bluetooth device is received and the received signal strength of the target Bluetooth device is less than a strength threshold, the terminal will not add the target device name contained in the RNR response to the RNR cache file.
[0104] The intensity threshold may be set by the system by default or may be customized by the user, which is not limited in this embodiment.
[0105] Schematically, the terminal does not find a matching Bluetooth address consistent with Bluetooth addresses 7 and 8 in the corresponding relationship shown in Table 3, and thus sends RNR to the first and second target Bluetooth devices based on Bluetooth addresses 7 and 8, respectively, and obtains a first RNR response (including the device name "speaker in the living room") fed back by the first target Bluetooth device, and a second RNR response (including the device name "TV in the bedroom") fed back by the second target Bluetooth device. Since the RSSI of the first target Bluetooth device is -120dbm, the RSSI of the second target Bluetooth device is -30dbm, and the strength threshold set by the terminal is -90dbm, the terminal only updates the device name of the second target Bluetooth device to the RNR cache file. The corresponding relationship in the updated RNR cache file is shown in Table 5 below:
[0106] Table 5
[0107]
[0108]
[0109] To sum up, in an embodiment of the present application, the terminal queries the target device name of the target Bluetooth device from the RNR cache file based on the correspondence between the Bluetooth address and the device name of the Bluetooth device in the RNR cache file, thereby avoiding direct RNR operation on the target Bluetooth device, simplifying the discovery process of the Bluetooth device, and improving the accuracy of the target device name obtained by the query.
[0110] In addition, after obtaining the device name of the Bluetooth device through the RNR operation, the terminal writes the current timestamp as the cache timestamp into the RNR cache file. After subsequently querying the Bluetooth name based on the target Bluetooth address, it further determines whether the queried Bluetooth name is valid based on the time interval between the cache timestamp and the current timestamp, thereby reducing the probability of display errors caused by displaying the device name based on the RNR cache file due to the Bluetooth name not being updated for a long time, and improving the display accuracy of the device name.
[0111] At the same time, when the terminal obtains the Bluetooth name of the Bluetooth device through the RNR operation, it determines whether to write the Bluetooth name into the RNR cache file based on the RSSI of the Bluetooth device, thereby avoiding storing a large amount of device information of long-distance Bluetooth devices in the RNR cache file, helping to reduce the storage space occupied by the RNR cache file and improve the speed of querying the device name based on the RNR cache file.
[0112] In an illustrative application scenario, Figure 5 As shown, the terminal 51 stores an RNR cache file 52, which contains the correspondence between the Bluetooth address, device name and cache timestamp. When the Bluetooth scanning function is turned on, the terminal 51 broadcasts a device query request and receives a device query response fed back by each surrounding Bluetooth device.
[0113] Among them, after the terminal 51 receives the device query response feedback from the first Bluetooth device 53, it queries the RNR cache file 52 based on the Bluetooth address "Bluetooth address 1" of the first Bluetooth device 53, and queries the matching device name "Zhang San’s mobile phone". Since the time interval between the cache timestamp corresponding to the device name and the current timestamp (2021-7-23 10:00:00) is less than 7 days, the terminal 51 displays "Zhang San’s mobile phone".
[0114] After receiving the device query response fed back by the second Bluetooth device 54, the terminal 51 queries the RNR cache file 52 based on the Bluetooth address "Bluetooth address 2" of the second Bluetooth device 54, and finds the matching device name "Li Si's Computer". Since the time interval between the cache timestamp corresponding to the device name and the current timestamp (2021-7-23 10:00:00) is greater than 7 days, the terminal 51 determines that the device name is invalid, and thus sends an RNR to the second Bluetooth device 54, and obtains the device name "Xiao Ming's Computer" from the fed-back RNR response. Further, the terminal 51 displays "Xiao Ming's Computer" and updates the device name and cache timestamp corresponding to Bluetooth address 2 in the RNR cache file 52.
[0115] After receiving the device query response fed back by the third Bluetooth device 55, the terminal 51 queries the RNR cache file 52 based on the Bluetooth address "Bluetooth address 6" of the third Bluetooth device 55. Since no matching device name is found, the terminal 51 sends an RNR to the third Bluetooth device 55 and obtains the device name "Xiaohong's headphones" from the fed-back RNR response. Since the RSSI of the third Bluetooth device 55 is greater than the signal strength threshold of -90dbm, the terminal 51 displays "Xiaohong's headphones" and associates "Bluetooth address 6", "Xiaohong's headphones" and the current timestamp to store in the RNR cache file 52.
[0116] After receiving the device query response fed back by the fourth Bluetooth device 56, the terminal 51 queries the RNR cache file 52 based on the Bluetooth address "Bluetooth address 7" of the fourth Bluetooth device 56. Since no matching device name is found, the terminal 51 sends an RNR to the fourth Bluetooth device 56 and obtains the device name "Xiao Ming's tablet" from the fed-back RNR response. Since the RSSI of the fourth Bluetooth device 56 is less than the signal strength threshold of -90dbm, the terminal 51 displays "Xiao Hong's headphones", but does not store the device information of the fourth Bluetooth device 56 in the RNR cache file 52.
[0117] The following is an embodiment of the device of the present application, which can be used to execute the embodiment of the method of the present application. For details not disclosed in the embodiment of the device of the present application, please refer to the embodiment of the method of the present application.
[0118] Please refer to Figure 6 , which shows a structural block diagram of a device for discovering a Bluetooth device provided by an exemplary embodiment of the present application. The device can be implemented as all or part of a terminal through software, hardware, or a combination of both. The device includes:
[0119] Broadcast module 601, used for broadcasting device query request;
[0120] The query module 602 is used to query the RNR cache file based on the target device information of the target Bluetooth device in response to receiving a response result of the target Bluetooth device to the device query request, and the response result does not include the target device name of the target Bluetooth device. The RNR cache file contains the correspondence between the device information of the Bluetooth device and the device name, and the device name is obtained by the terminal by sending the RNR;
[0121] The display module 603 is used to display the target device name in response to querying the target device name of the target Bluetooth device from the RNR cache file.
[0122] Optionally, the query module 602 includes:
[0123] An acquisition unit, used for acquiring a target Bluetooth address of a target Bluetooth device from a response result;
[0124] A first query unit, configured to query the RNR cache file based on a target Bluetooth address;
[0125] Optionally, the display module 603 includes:
[0126] A determining unit, configured to, in response to the presence of a matching Bluetooth address identical to the target Bluetooth address in the RNR cache file, determine a device name corresponding to the matching Bluetooth address as the target device name;
[0127] The display unit is used to display the name of the target device.
[0128] Optionally, determine the unit for:
[0129] In response to the presence of a matching Bluetooth address identical to the target Bluetooth address in the RNR cache file, obtaining a cache timestamp corresponding to the matching Bluetooth address, where the cache timestamp is used to characterize the moment when the matching Bluetooth address is added to the RNR cache file;
[0130] In response to the time interval between the cached timestamp and the current timestamp being less than the interval threshold, the device name corresponding to the matching Bluetooth address is determined as the target device name.
[0131] Optionally, the device further comprises:
[0132] A first sending module, configured to send an RNR to a target Bluetooth device in response to a time interval between a cached timestamp and a current timestamp being greater than an interval threshold;
[0133] A receiving module, used to receive the RNR response sent by the target Bluetooth device;
[0134] The update module is used to display the target device name contained in the RNR response and update the target device name and current timestamp to the RNR cache file.
[0135] Optional, query modules, including:
[0136] The second query unit is configured to query the RNR cache file based on the target device information of the target Bluetooth device in response to receiving a device query response of the target Bluetooth device and not receiving the EIR of the target Bluetooth device.
[0137] Optionally, the query module also includes:
[0138] a parsing unit, configured to parse the EIR in response to receiving a device query response from a target Bluetooth device and receiving an EIR of the target Bluetooth device;
[0139] The third query unit is used for querying the RNR cache file based on the target device information of the target Bluetooth device in response to the EIR not containing the device name of the target Bluetooth device.
[0140] Optionally, the device further comprises:
[0141] A second sending module, configured to send an RNR to a target Bluetooth device in response to failure to find a target device name of the target Bluetooth device from the RNR cache file;
[0142] Add a module to receive the RNR response sent by the target Bluetooth device and add the target device name contained in the RNR response to the RNR cache file.
[0143] Optionally, add modules for:
[0144] In response to receiving an RNR response sent by a target Bluetooth device, and a received signal strength RSSI of the target Bluetooth device being greater than a strength threshold, the target device name included in the RNR response is added to the RNR cache file.
[0145] To sum up, in an embodiment of the present application, the device information of the Bluetooth device obtained by the terminal historically sending RNR is stored in the RNR cache file. When a device query request is broadcast and the target device name is not obtained from the response result of the target Bluetooth device, the RNR cache is first queried whether there is the name of the target Bluetooth device in the file based on the correspondence between the device information and the device name in the RNR cache file. When the target device name of the target Bluetooth device is included in the RNR cache file, the target device name of the target Bluetooth device is directly displayed without sending RNR to the target Bluetooth device to obtain the device name of the target Bluetooth device. This simplifies the discovery process of the Bluetooth device, thereby shortening the discovery time of the Bluetooth device and improving the discovery efficiency of the Bluetooth device.
[0146] Please refer to Figure 7, which shows a block diagram of a terminal provided by an exemplary embodiment of the present application. The terminal 700 may be a smart phone, a tablet computer, a wearable device, etc. The terminal 700 in the present application may include one or more of the following components: a processor 710, a memory 720, and a Bluetooth chip 730.
[0147] The processor 710 may include one or more processing cores. The processor 710 uses various interfaces and lines to connect the various parts of the entire terminal 700, and executes various functions and processes data of the terminal 700 by running or executing instructions, programs, code sets or instruction sets stored in the memory 720, and calling data stored in the memory 720. Optionally, the processor 710 can be implemented in at least one hardware form of digital signal processing (DSP), field-programmable gate array (FPGA), and programmable logic array (PLA). The processor 710 can integrate one or more combinations of a central processing unit (CPU), a graphics processing unit (GPU), a neural network processor (NPU), and a modem. Among them, the CPU mainly processes the operating system, user interface, and application programs; the GPU is responsible for the Bluetooth data transmission and reception and Bluetooth-related work required to be performed by the Bluetooth chip 730; the NPU is used to implement artificial intelligence (AI) functions; and the modem is used to process wireless communications. It is understandable that the above-mentioned modem may not be integrated into the processor 710, but may be implemented by a separate chip.
[0148] The memory 720 may include a random access memory (RAM) or a read-only memory (ROM). Optionally, the memory 720 includes a non-transitory computer-readable storage medium. The memory 720 may be used to store instructions, programs, codes, code sets, or instruction sets. The memory 720 may include a program storage area and a data storage area, wherein the program storage area may store instructions for implementing an operating system, instructions for at least one function (such as a touch function, a sound playback function, an image playback function, etc.), instructions for implementing the following various method embodiments, etc.; the data storage area may store data (such as audio data, a phone book), etc., created according to the use of the terminal 700.
[0149] The Bluetooth chip 730 is a component used for Bluetooth data transmission and reception and Bluetooth-related work, and is composed of related devices such as a receiver, a transmitter and a memory. The Bluetooth chip 730 can be integrated inside the terminal 700 or set in an external Bluetooth component, which is not limited in this embodiment.
[0150] In addition, those skilled in the art can understand that the structure of the terminal 700 shown in the above drawings does not constitute a limitation on the computer device, and the computer device may include more or fewer components than shown in the figure, or combine certain components, or arrange the components differently. For example, the terminal 700 also includes components such as a display screen, a sensor, an audio circuit, and a power supply, which will not be described in detail here.
[0151] An embodiment of the present application further provides a computer-readable medium storing at least one instruction, wherein the at least one instruction is loaded and executed by a processor to implement the Bluetooth device discovery method described in the above embodiments.
[0152] The embodiment of the present application provides a computer program product or a computer program, which includes a computer instruction stored in a computer-readable storage medium. The processor of the computer device reads the computer instruction from the computer-readable storage medium, and the processor executes the computer instruction, so that the computer device performs the Bluetooth device discovery method provided in various optional implementations of the above aspects.
[0153] Those skilled in the art should be aware that in one or more of the above examples, the functions described in the embodiments of the present application can be implemented with hardware, software, firmware, or any combination thereof. When implemented using software, these functions can be stored in a computer-readable medium or transmitted as one or more instructions or codes on a computer-readable medium. Computer-readable media include computer storage media and communication media, wherein the communication media include any media that facilitates the transmission of a computer program from one place to another. The storage medium can be any available medium that a general or special-purpose computer can access.
[0154] The above description is only an optional embodiment of the present application and is not intended to limit the present application. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the present application shall be included in the protection scope of the present application.
Claims
1. A method for discovering a Bluetooth device. It is characterized in that The method comprises: Broadcast device query request; In response to receiving a response result of the target Bluetooth device to the device query request, and the response result does not include the target device name of the target Bluetooth device, obtaining the target Bluetooth address of the target Bluetooth device from the response result; querying the RNR cache file based on the target Bluetooth address, the RNR cache file contains the correspondence between the Bluetooth address and the device name of the Bluetooth device that has historically performed RNR, and the device name is obtained by the terminal by sending the RNR; In response to the presence of a matching Bluetooth address identical to the target Bluetooth address in the RNR cache file, a device name corresponding to the matching Bluetooth address is determined as the target device name; and the target device name is displayed.
2. The method according to claim 1, It is characterized in that In response to the presence of a matching Bluetooth address identical to the target Bluetooth address in the RNR cache file, determining a device name corresponding to the matching Bluetooth address as the target device name, comprises: In response to the presence of the matching Bluetooth address identical to the target Bluetooth address in the RNR cache file, obtaining a cache timestamp corresponding to the matching Bluetooth address, where the cache timestamp is used to represent the time when the matching Bluetooth address is added to the RNR cache file; In response to a time interval between the cached timestamp and the current timestamp being less than an interval threshold, determining a device name corresponding to the matching Bluetooth address as the target device name.
3. The method according to claim 2, It is characterized in that After obtaining the cache timestamp corresponding to the matching Bluetooth address, the method further includes: In response to a time interval between the cached timestamp and the current timestamp being greater than the interval threshold, sending an RNR to the target Bluetooth device; Receive the RNR response sent by the target Bluetooth device; The target device name contained in the RNR response is displayed, and the target device name and the current timestamp are updated to the RNR cache file.
4. The method according to any one of claims 1 to 3, It is characterized in that The method further comprises: In response to receiving a device query response from the target Bluetooth device and not receiving an EIR from the target Bluetooth device, querying the RNR cache file based on the target device information of the target Bluetooth device.
5. The method according to claim 4, It is characterized in that The method further comprises: In response to receiving a device query response from the target Bluetooth device and receiving the EIR of the target Bluetooth device, parsing the EIR; In response to the EIR not including the target device name of the target Bluetooth device, querying the RNR cache file based on the target device information of the target Bluetooth device.
6. The method according to any one of claims 1 to 3, It is characterized in that After querying the RNR cache file based on the target Bluetooth address, the method further includes: In response to not finding the target device name of the target Bluetooth device from the RNR cache file, sending an RNR to the target Bluetooth device; Receive the RNR response sent by the target Bluetooth device, and add the target device name included in the RNR response to the RNR cache file.
7. The method according to claim 6, It is characterized in that The receiving the RNR response sent by the target Bluetooth device, and adding the target device name included in the RNR response to the RNR cache file, includes: In response to receiving the RNR response sent by the target Bluetooth device, and the received signal strength RSSI of the target Bluetooth device is greater than a strength threshold, adding the target device name included in the RNR response to the RNR cache file.
8. A device for discovering a Bluetooth device, It is characterized in that The device comprises: Broadcast module, used to broadcast device query requests; A query module, configured to obtain a target Bluetooth address of the target Bluetooth device from the response result in response to receiving a response result of the target Bluetooth device to the device query request, and the response result does not include a target device name of the target Bluetooth device; query an RNR cache file based on the target Bluetooth address, wherein the RNR cache file includes a correspondence between Bluetooth addresses and device names of Bluetooth devices that have historically performed RNR, and the device name is obtained by the terminal by sending RNR; The display module is used for determining the device name corresponding to the matching Bluetooth address as the target device name in response to the presence of a matching Bluetooth address identical to the target Bluetooth address in the RNR cache file; and displaying the target device name.
9. The device according to claim 8, It is characterized in that The display module is used for: In response to the presence of the matching Bluetooth address identical to the target Bluetooth address in the RNR cache file, obtaining a cache timestamp corresponding to the matching Bluetooth address, where the cache timestamp is used to represent the time when the matching Bluetooth address is added to the RNR cache file; In response to a time interval between the cached timestamp and the current timestamp being less than an interval threshold, determining a device name corresponding to the matching Bluetooth address as the target device name.
10. The device according to claim 9, It is characterized in that The device also includes: A first sending module, configured to send an RNR to the target Bluetooth device in response to a time interval between the cached timestamp and the current timestamp being greater than the interval threshold; A receiving module, used to receive the RNR response sent by the target Bluetooth device; An updating module is used to display the target device name contained in the RNR response, and to update the target device name and the current timestamp to the RNR cache file.
11. The device according to any one of claims 8 to 10, It is characterized in that The query module comprises: The second query unit is configured to query the RNR cache file based on the target device information of the target Bluetooth device in response to receiving a device query response from the target Bluetooth device and not receiving the EIR of the target Bluetooth device.
12. The device according to claim 11, It is characterized in that The query module further includes: a parsing unit, configured to parse the EIR in response to receiving a device query response from the target Bluetooth device and receiving the EIR of the target Bluetooth device; A third query unit is configured to query the RNR cache file based on the target device information of the target Bluetooth device in response to the EIR not containing the target device name of the target Bluetooth device.
13. The device according to any one of claims 8 to 10, It is characterized in that The device also includes: A second sending module, configured to send an RNR to the target Bluetooth device in response to not finding the target device name of the target Bluetooth device from the RNR cache file; An adding module is used to receive the RNR response sent by the target Bluetooth device and add the target device name contained in the RNR response to the RNR cache file.
14. The device according to claim 13, It is characterized in that The adding module is used for: In response to receiving the RNR response sent by the target Bluetooth device, and the received signal strength RSSI of the target Bluetooth device is greater than a strength threshold, adding the target device name included in the RNR response to the RNR cache file.
15. A terminal, It is characterized in that The terminal includes a processor and a memory, wherein the memory stores at least one instruction, at least one program, a code set or an instruction set, and the at least one instruction, the at least one program, the code set or the instruction set is loaded and executed by the processor to implement the Bluetooth device discovery method as described in any one of claims 1 to 7.
16. A computer-readable storage medium, It is characterized in that The readable storage medium stores at least one instruction, at least one program, a code set or an instruction set, and the at least one instruction, the at least one program, the code set or the instruction set is loaded and executed by the processor to implement the Bluetooth device discovery method as described in any one of claims 1 to 7.
Citation Information
Patent Citations
Method and device for searching adjacent bluetooth device
CN102684747A
Bluetooth name search method and device, electronic equipment and storage medium
CN110460983A
Bluetooth test method and device, electronic equipment and computer readable storage medium
CN112261635A
Bluetooth pairing method and related device
CN112469011A
Method to obtain friendly names for bluetooth devices
US20030165129A1
