Multi-thread control method of Bluetooth device and electronic device

By using the MAC address of the Bluetooth device as the thread ID and putting the threads into the thread pool, the threads of multiple Bluetooth devices run in parallel, the disconnection and reconnection problems when the APP controls multiple Bluetooth devices is solved, and the convenience is achieved multi-device management and stable control.

CN119211897APending Publication Date: 2024-12-27ROYPOW TECH CO LTD
View PDF 3 Cites 0 Cited by

Patent Information

Application Number
CN202411589732.9
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-11-08
Publication Date
2024-12-27

AI Technical Summary

Technical Problem

When the prior art controls multiple Bluetooth devices through one APP, disconnection and reconnection operations frequently occur, resulting in complex operations and inability to effectively manage multiple smart home devices.

Method used

Using multi-threading control method, by obtaining the MAC address of the Bluetooth device as the thread ID, corresponding to the thread one by one, and putting the thread into the thread pool, so that the threads of multiple Bluetooth devices can run in parallel, avoiding frequent disconnection and repetition. Continuous operation, and convenient control of multiple Bluetooth devices at the same time.

Benefits of technology

The function of one APP to control multiple Bluetooth devices simultaneously is realized, which simplifies the operation process, avoids frequent disconnection and reconnection, and improves the convenience and stability of control.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119211897A_ABST
    Figure CN119211897A_ABST
Patent Text Reader

Abstract

The invention provides a multi-thread control method of Bluetooth equipment and an electronic device. The method is executed based on an APP, and comprises the following steps: establishing a Bluetooth connection with a Bluetooth device; the MAC address of the Bluetooth device is acquired; taking the MAC address as a thread ID to establish a corresponding thread for the Bluetooth device, wherein the thread is used for communicating with the Bluetooth device; the threads are put into a thread pool, the thread pool comprises threads corresponding to one or more Bluetooth devices, the threads corresponding to the Bluetooth devices are parallel, and the Bluetooth connection states of the one or more Bluetooth devices are recorded through a Bluetooth device list.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of Bluetooth technology, and in particular to a multi-thread control method and an electronic device for a Bluetooth device. Background Art

[0002] With the continuous development of technology, people can establish connections with Bluetooth devices and control Bluetooth devices through applications (APPs) on smart devices in their lives. For example, through mobile phone APPs, we can control various devices in the home anytime and anywhere, such as remotely turning on and off air conditioners, TVs, lights, etc. However, as the types of Bluetooth devices continue to increase, more and more APPs are required, which brings a great burden to smart devices. However, if you control many Bluetooth devices through one APP, it may involve frequent disconnection and reconnection of Bluetooth operations, making the operation more complicated. Summary of the invention The embodiments of the present application provide a multi-thread control method for a Bluetooth device and an electronic device.

[0003] In a first aspect, an embodiment of the present application provides a multi-thread control method for a Bluetooth device, the method being executed based on an APP, the method comprising: Establish a Bluetooth connection with a Bluetooth device; Get the MAC address of the Bluetooth device; Use the MAC address as the thread ID to create a corresponding thread for the Bluetooth device, and the thread is used to communicate with the Bluetooth device; The thread is put into a thread pool, which includes threads corresponding to one or more Bluetooth devices. The threads corresponding to multiple Bluetooth devices are parallel, and the Bluetooth connection status of one or more Bluetooth devices is recorded through a Bluetooth device list.

[0004] Optionally, the method further includes: Monitor each thread in the thread pool and the status of each Bluetooth device in the Bluetooth device list; Based on the correspondence between each thread and the online Bluetooth devices in the Bluetooth device list, each Bluetooth device and / or each thread is controlled.

[0005] Optionally, based on the correspondence between each thread and the online Bluetooth device in the Bluetooth device list, each Bluetooth device and / or each thread is controlled, including: Determine whether each thread corresponds to the online Bluetooth devices in the Bluetooth device list; If there is an online Bluetooth device in the Bluetooth device list that lacks a corresponding thread, use the MAC address of the Bluetooth device as the thread ID to create a corresponding thread for the Bluetooth device, and put the thread into the thread pool; and / or, If there is a thread in the thread pool that lacks a corresponding online Bluetooth device, the thread is removed from the thread pool, and a Bluetooth connection is re-established with the Bluetooth device whose MAC address is the thread ID of the thread.

[0006] Optionally, the Bluetooth device is a smart home device.

[0007] In a second aspect, an embodiment of the present application provides an electronic device, which controls one or more Bluetooth devices based on an APP, and the electronic device includes: A Bluetooth connection module, used to establish a Bluetooth connection with a Bluetooth device; Acquisition module, used to obtain the MAC address of the Bluetooth device; A thread establishment module, used to establish a corresponding thread for a Bluetooth device using the MAC address as a thread ID, and the established thread is used to communicate with the Bluetooth device; The thread pool management module is used to put the established threads into the thread pool. The thread pool includes threads corresponding to one or more Bluetooth devices. The threads corresponding to multiple Bluetooth devices are parallel. The Bluetooth connection status of one or more Bluetooth devices is recorded through the Bluetooth device list.

[0008] Optionally, the electronic device further includes: The monitoring module is used to monitor the status of each thread in the thread pool and each Bluetooth device in the Bluetooth device list; The control module is used to control each Bluetooth device and / or each thread based on the corresponding relationship between each thread and the online Bluetooth device in the Bluetooth device list.

[0009] Optionally, the control module includes: A judgment module, used to judge whether each thread corresponds to an online Bluetooth device in the Bluetooth device list; The sub-control module is used to, when the judgment module finds that there is an online Bluetooth device in the Bluetooth device list that lacks a corresponding thread, use the MAC address of the Bluetooth device as the thread ID to establish a corresponding thread for the Bluetooth device and put the thread into the thread pool; and / or, when the judgment module finds that there is a thread in the thread pool that lacks a corresponding online Bluetooth device, remove the thread from the thread pool and re-establish a Bluetooth connection with the Bluetooth device with the thread ID of the thread as the MAC address.

[0010] Optionally, the Bluetooth device is a smart home device.

[0011] In a third aspect, an embodiment of the present application provides an electronic device comprising a memory, at least one processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the computer program, a method as described in any one of the above-mentioned first aspects is implemented.

[0012] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the method as described in any one of the above-mentioned first aspects is implemented.

[0013] In a fifth aspect, an embodiment of the present application provides a computer program product. When the computer program product is run on an electronic device, the electronic device executes any one of the methods described in the first aspect.

[0014] In this application, when controlling multiple Bluetooth devices based on one APP, the MAC address of the Bluetooth device can be used as the thread ID to establish a corresponding thread for it, so that the MAC address of the Bluetooth device corresponds to its thread ID one by one, ensuring the uniqueness of the thread ID in the thread pool. In addition, the threads in the thread pool are parallel, so that one APP can control multiple Bluetooth devices at the same time while avoiding frequent disconnection and reconnection of Bluetooth operations, which helps to control Bluetooth devices more conveniently. BRIEF DESCRIPTION OF THE DRAWINGS

[0015] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings required for describing the embodiments are briefly introduced below.

[0016] Figure 1 It is a flowchart of a multi-threaded control method for a Bluetooth device provided in an embodiment of the present application.

[0017] Figure 2 This is an example diagram of a multi-threaded control method for a Bluetooth device provided in an embodiment of the present application.

[0018] Figure 3 It is a schematic diagram of the structure of an electronic device provided in one embodiment of the present application.

[0019] Figure 4 It is a structural schematic diagram of an electronic device provided in another embodiment of the present application. DETAILED DESCRIPTION

[0020] The technical solution of the embodiment of the present invention will be described below in conjunction with the accompanying drawings in the embodiment of the present invention.

[0021] With the continuous development of science and technology, people can establish connections with Bluetooth devices and control Bluetooth devices through apps on smart devices. Taking smart home devices as an example, smart homes have become a part of our daily lives. Smart home technology can be controlled and managed through the Internet and Bluetooth, helping us to manage our home life more conveniently. Due to the large number of smart home device products, multiple apps need to be installed. However, as the types of smart home devices continue to increase, more and more apps are needed, which brings a great burden.

[0022] For the sake of security, convenience, and less mobile phone memory, multiple apps can be integrated into one app. The convenience and reliability of apps have been recognized and widely used in payment, medical equipment, home appliances, etc. It improves our quality of life and living standards, provides a more convenient and fast lifestyle, and achieves the goals of energy conservation, emission reduction, and environmental protection and sustainable development.

[0023] However, if you control multiple Bluetooth devices through an APP, it may involve frequent disconnection and reconnection of Bluetooth, making the operation more complicated. This is because when the App communicates with a Bluetooth device, it can usually only connect to one Bluetooth device at a time. When you want to control another Bluetooth device, you have to disconnect the currently connected Bluetooth device and then connect to other Bluetooth devices. When you want to control multiple Bluetooth devices at the same time, it will be very inconvenient.

[0024] Based on this, Figure 1 It is shown that an embodiment of the present application provides a multi-threaded control method for a Bluetooth device. Figure 1 The method shown is applicable to smart devices, such as mobile phones, tablets, etc., and the method can be executed based on an APP. Figure 1 As shown, the method may include steps S110-S140.

[0025] In step S110, a Bluetooth connection is established with the Bluetooth device. Usually, when the Bluetooth of a Bluetooth device is turned on, the Bluetooth device can be retrieved within a certain range and a Bluetooth connection can be established with it. For example, the currently detected Bluetooth devices can be displayed on the APP page, and when the corresponding Bluetooth device icon is clicked, an attempt can be made to establish a Bluetooth connection with it. In this application, the type of Bluetooth device is not limited, and it can be any device that meets the standard Bluetooth communication protocol. As an example, the Bluetooth device can be a smart home device, such as a sweeping robot, an air conditioner, etc.

[0026] In step S120, the media access control address (MAC) address of the Bluetooth device is obtained. Any Bluetooth device has a globally unique MAC address, which can be used as a basis for distinguishing different Bluetooth devices. The MAC address of a Bluetooth device is a 48-bit unique hardware identifier used to establish connections and communications between Bluetooth devices. The MAC address of a Bluetooth device is usually expressed as 12 hexadecimal numbers (for example: 00:11:22:33:44:55), where the first 6 digits represent the manufacturer's identification (ID) of the Bluetooth device, and the last 6 digits are the unique serial number of the Bluetooth device. Usually in the Bluetooth communication process, Bluetooth devices do not communicate with each other directly using MAC addresses, but communicate through the relevant layers on the Bluetooth protocol stack. The relevant layers use their own channel IDs to identify the Bluetooth devices that are exchanging data.

[0027] In step S130, the MAC address is used as the thread ID to establish a corresponding thread for the Bluetooth device, and the established thread is used to communicate with the Bluetooth device. That is, a separate thread is assigned to the Bluetooth device and its MAC address is used as the thread ID to distinguish the threads, and the thread ID is bound to the Bluetooth MAC address in a one-to-one correspondence to ensure that each Bluetooth device has its own separate thread. If the thread is not distinguished, command concatenation errors may occur, resulting in the inability to control the device to be controlled. Based on the thread of each Bluetooth device, commands can be sent to it or its response can be received, thereby achieving control of the Bluetooth device.

[0028] In step S140, the established thread is placed in a thread pool, which may include threads corresponding to one or more Bluetooth devices. In the thread pool, Bluetooth electronic devices can be easily located by thread ID. When it is necessary to communicate with a Bluetooth device, each Bluetooth device can be identified based on whether the thread ID and the Bluetooth MAC address are equal. In addition, the threads corresponding to multiple Bluetooth devices in the thread pool are parallel, so that command concatenation can be avoided while achieving simultaneous control of multiple Bluetooth devices. The number of threads in the thread pool is not limited, for example, the corresponding number of threads can be determined according to the configuration of the applicable device. The Bluetooth connection status of one or more Bluetooth devices can be recorded through a Bluetooth device list, for example, the Bluetooth device list can show that the Bluetooth device is connecting (i.e. online) or disconnected (i.e. offline or offline). In the Bluetooth device list, Bluetooth devices can be distinguished by name. For example, "sweeping robot", "air conditioner", etc. are displayed in the Bluetooth device list.

[0029] In this application, when controlling multiple Bluetooth devices based on one APP, the MAC address of the Bluetooth device can be used as the thread ID to establish a corresponding thread for it, so that the MAC address of the Bluetooth device corresponds to its thread ID one by one, ensuring the uniqueness of the thread ID in the thread pool. In addition, the threads in the thread pool are parallel, so that one APP can control multiple Bluetooth devices at the same time while avoiding frequent disconnection and reconnection of Bluetooth operations, which helps to control Bluetooth devices more conveniently.

[0030] Optional, Figure 1 The method shown may further include step S150 and step S160.

[0031] In step S150, the status of each thread in the thread pool and each Bluetooth device in the Bluetooth device list is monitored. For example, based on the MAC address of the online Bluetooth device, it is possible to search in the thread pool whether there is a thread with a thread ID of the MAC address. For another example, based on the thread ID of each thread in the thread pool, it is possible to search in the Bluetooth device list whether there is an online Bluetooth device with a MAC address of the thread ID. Based on the monitoring of the status of the threads and Bluetooth devices, some abnormal situations can be noticed in time, such as the Bluetooth device being disconnected or the thread of the Bluetooth device being removed from the thread pool.

[0032] In step S160, each Bluetooth device and / or each thread is controlled based on the corresponding relationship between each thread and the online Bluetooth device in the Bluetooth device list. Based on this, some abnormal situations can be responded to in time to avoid confusion or errors.

[0033] Optionally, step S160 may include step S161 and step S162.

[0034] In step S161, it is determined whether each thread corresponds to an online Bluetooth device in the Bluetooth device list. The online Bluetooth devices in the Bluetooth device list are devices that have established Bluetooth connections, and usually there will be corresponding threads in the thread pool. If the threads in the thread pool correspond to the online Bluetooth devices in the Bluetooth device list, it means that no abnormal situation has occurred, and no further operation is required. If the threads in the thread pool do not correspond to the online Bluetooth devices in the Bluetooth device list, it means that an abnormal situation may have occurred, and then proceed to step S162.

[0035] In step S162, if there is an online Bluetooth device in the Bluetooth device list that lacks a corresponding thread, the MAC address of the Bluetooth device is used as the thread ID to create a corresponding thread for the Bluetooth device, and the created thread is placed in the thread pool. If there is an online Bluetooth device in the Bluetooth device list that lacks a corresponding thread, it may be because the thread of the online Bluetooth device has not been used for a long time and has been removed from the thread pool. In this case, a thread can be re-created for it to control it.

[0036] And / or, if there is a thread missing corresponding to an online Bluetooth device in the thread pool, the thread is removed from the thread pool, and a Bluetooth connection is re-established with the Bluetooth device whose MAC address is the thread ID of the thread. If there is a thread missing corresponding to an online Bluetooth device in the thread pool, it may be because the Bluetooth device corresponding to the thread is offline. In this case, a Bluetooth connection can be re-established with the Bluetooth device. Since a thread will be established for a Bluetooth device when a Bluetooth connection is established with the Bluetooth device, the old thread of the Bluetooth device in the thread pool is removed to ensure the uniqueness of the thread of the Bluetooth device.

[0037] Based on this, abnormal situations in the control process of Bluetooth devices can be monitored so that timely adjustments can be made to ensure the stability of the control process.

[0038] Combine the following Figure 2 , the multi-thread control method of the Bluetooth device of the embodiment of the present application is introduced by example. As an example, Figure 2 The method in is executed by a mobile phone APP to control one or more smart home devices. Figure 2 As shown, the method includes steps S201-S207.

[0039] In step S201, open the APP.

[0040] In step S202, a Bluetooth device is searched, for example, a Bluetooth device within an allowed Bluetooth connection range may be searched.

[0041] In step S203, the Bluetooth device is connected via Bluetooth to obtain the MAC address. For example, after searching for the target Bluetooth device, the icon of the Bluetooth device can be clicked on the APP to establish a Bluetooth connection with it, and then its MAC address can be obtained.

[0042] In step S204, a thread is generated according to the MAC address (the MAC address is used as the thread ID). The thread is a dedicated thread of the Bluetooth device, and communication with the Bluetooth device can be carried out through the thread.

[0043] In step S205, each thread in the thread pool is monitored to detect the Bluetooth status of the Bluetooth device list.

[0044] In step S206, it is determined whether there is an online Bluetooth device lacking a corresponding thread in the Bluetooth device list. If so, the process proceeds to step S207. If not, no operation is performed.

[0045] In step S207, a new thread is generated according to the MAC address of the online Bluetooth device that lacks a corresponding thread.

[0046] In step S206', it is determined whether there is a thread in the thread pool that lacks a corresponding online Bluetooth device. If there is, the process proceeds to step S207'. If not, no operation is performed.

[0047] In step S207', the thread lacking the corresponding online Bluetooth device is removed, and a connection is re-established with the corresponding Bluetooth device to obtain the MAC address to generate a new thread.

[0048] based on Figure 2 The method shown can realize multiple Bluetooth devices in one App at the same time, and has universality and compatibility, which greatly improves convenience and realizes a more intelligent life experience.

[0049] The method provided in the embodiment of the present application is described in detail above. The device provided in the embodiment of the present application is described in detail below with reference to the accompanying drawings.

[0050] See also Figure 3 , is a schematic diagram of the structure of an electronic device provided in an embodiment of the present application. Figure 3 The electronic device 300 shown can control one or more Bluetooth devices based on an APP. The electronic device 300 can include a Bluetooth connection module 310, an acquisition module 320, a thread establishment module 330 and a thread pool management module 340.

[0051] The Bluetooth connection module 310 may be used to establish a Bluetooth connection with a Bluetooth device; The acquisition module 320 may be used to acquire the MAC address of the Bluetooth device; The thread establishment module 330 may be used to establish a corresponding thread for the Bluetooth device using the MAC address as the thread ID, and the established thread may be used to communicate with the Bluetooth device; The thread pool management module 340 can be used to put the established threads into the thread pool, which includes threads corresponding to one or more Bluetooth devices. The threads corresponding to multiple Bluetooth devices are parallel, and the Bluetooth connection status of one or more Bluetooth devices is recorded through the Bluetooth device list.

[0052] Optionally, the electronic device 300 may further include a monitoring module 350 and a control module 360 ​​.

[0053] The monitoring module 350 may be used to monitor the status of each thread in the thread pool and each Bluetooth device in the Bluetooth device list; The control module 360 ​​may be configured to control each Bluetooth device and / or each thread based on a correspondence between each thread and an online Bluetooth device in the Bluetooth device list.

[0054] Optionally, the control module 360 ​​may include a determination module 361 and a sub-control module 362 .

[0055] The determination module 361 may be used to determine whether each thread corresponds one-to-one to an online Bluetooth device in the Bluetooth device list; The sub-control module 362 can be used to, when the judgment module finds that there is an online Bluetooth device in the Bluetooth device list that lacks a corresponding thread, use the MAC address of the Bluetooth device as the thread ID to establish a corresponding thread for the Bluetooth device and put the thread into the thread pool; and / or, when the judgment module finds that there is a thread in the thread pool that lacks a corresponding online Bluetooth device, remove the thread from the thread pool and re-establish a Bluetooth connection with the Bluetooth device with the thread ID of the thread as the MAC address.

[0056] Optionally, the Bluetooth device may be a smart home device.

[0057] The present application also provides an electronic device. Figure 4 As shown, the electronic device 400 includes: at least one processor 401, a memory 402, and a computer program 403 stored in the memory 402 and executable on the at least one processor 401. When the processor 401 executes the computer program 403, the method provided in the present application is implemented.

[0058] Exemplarily, the computer program 403 may be divided into one or more modules / units, one or more modules / units are stored in the memory 402, and executed by the processor 401 to complete the present application. One or more modules / units may be a series of computer program instruction segments capable of completing specific functions, and the instruction segments are used to describe the execution process of the computer program in the electronic device 400.

[0059] Those skilled in the art will understand that Figure 4 It is only an example of the electronic device 400 and does not constitute a limitation of the electronic device. It may include more or fewer components than shown in the figure, or a combination of certain components, or different components. For example, the electronic device 400 may also include input and output devices, network access devices, buses, etc.

[0060] The processor 401 may be a central processing unit (CPU), or other general-purpose processors, digital signal processors (DSP), application specific integrated circuits (ASIC), field-programmable gate arrays (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. A general-purpose processor may be a microprocessor or the processor may also be any conventional processor, etc.

[0061] The memory 402 may be an internal storage unit of the electronic device 400, such as a hard disk or memory of the electronic device 400. The memory 402 may also be an external storage device of the electronic device 400, such as a plug-in hard disk, a smart media card (SMC), a secure digital (SD) card, a flash card, etc. equipped on the electronic device 400. Further, the memory 402 may also include both an internal storage unit of the electronic device 400 and an external storage device. The memory 402 is used to store computer programs and other programs and data required by the electronic device 400. The memory 402 may also be used to temporarily store data that has been output or is to be output.

[0062] The electronic device 400 provided in this embodiment can execute the above method embodiment, and its implementation principle and technical effect are similar, which will not be repeated here.

[0063] An embodiment of the present application further provides a computer-readable storage medium, which stores a computer program. When the computer program is executed by a processor, the steps in the above-mentioned method embodiments can be implemented.

[0064] An embodiment of the present application provides a computer program product. When the computer program product runs on an electronic device, the electronic device can implement the steps in the above-mentioned method embodiments when executing the computer program product.

[0065] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the present application implements all or part of the processes in the above method embodiments, which can be completed by instructing the relevant hardware through a computer program. The computer program can be stored in a computer-readable storage medium. When the computer program is executed by the processor, the steps of the above method embodiments can be implemented. Among them, the computer program includes computer program code, which can be in source code form, object code form, executable file or some intermediate form. The computer-readable medium may at least include: any entity or device that can carry the computer program code to the camera / electronic device, recording medium, computer memory, ROM (read-only memory), RAM (random access memory), CD-ROM (compact disc read-only memory), magnetic tape, floppy disk and optical data storage device. The computer-readable storage medium mentioned in the present application can be a non-volatile storage medium, in other words, it can be a non-transient storage medium.

[0066] In the above embodiments, the description of each embodiment has its own emphasis. For parts that are not described or recorded in detail in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.

[0067] Those of ordinary skill in the art will appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of this application.

[0068] In the embodiments provided in the present application, it should be understood that the disclosed devices / equipment and methods can be implemented in other ways. For example, the device / equipment embodiments described above are only schematic, for example, the division of modules or units is only a logical function division, and there may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms.

[0069] It should be understood that when used in the present specification and the appended claims, the term "comprising" indicates the presence of described features, wholes, steps, operations, elements and / or components, but does not exclude the presence or addition of one or more other features, wholes, steps, operations, elements, components and / or combinations thereof.

[0070] It should also be understood that the term “and / or” used in the specification and appended claims refers to any and all possible combinations of one or more of the associated listed items, and includes these combinations.

[0071] As used in the specification and appended claims of this application, the term "if" can be interpreted as "when" or "uponce" or "in response to determining" or "in response to detecting", depending on the context. Similarly, the phrase "if it is determined" or "if [described condition or event] is detected" can be interpreted as meaning "uponce it is determined" or "in response to determining" or "uponce [described condition or event] is detected" or "in response to detecting [described condition or event]", depending on the context.

[0072] In addition, in the description of the present application specification and the appended claims, the terms "first", "second", etc. are only used to distinguish the descriptions and cannot be understood as indicating or implying relative importance.

[0073] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present application, rather than to limit it. Although the present application has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or replace some or all of the technical features therein with equivalents. However, these modifications or replacements do not cause the essence of the corresponding technical solutions to deviate from the scope of the technical solutions of the embodiments of the present application.

Claims

1. A multi-thread control method for a Bluetooth device, characterized in that: The method is performed based on an application program APP, and the method includes: Establish a Bluetooth connection with a Bluetooth device; Obtaining the media access control address MAC address of the Bluetooth device; Using the MAC address as a thread identity ID to establish a corresponding thread for the Bluetooth device, wherein the thread is used to communicate with the Bluetooth device; The thread is put into a thread pool, which includes threads corresponding to one or more Bluetooth devices respectively. The threads corresponding to the multiple Bluetooth devices are parallelized, and the Bluetooth connection status of the one or more Bluetooth devices is recorded through a Bluetooth device list.

2. The method according to claim 1, characterized in that The method further comprises: Monitor the status of each thread in the thread pool and each Bluetooth device in the Bluetooth device list; Based on the correspondence between each thread and the online Bluetooth devices in the Bluetooth device list, each Bluetooth device and / or each thread is controlled.

3. The method according to claim 2, characterized in that The controlling each Bluetooth device and / or each thread based on the correspondence between each thread and the online Bluetooth device in the Bluetooth device list includes: Determine whether each of the threads corresponds one-to-one to the online Bluetooth devices in the Bluetooth device list; If there is an online Bluetooth device in the Bluetooth device list that lacks a corresponding thread, using the MAC address of the Bluetooth device as the thread ID to create a corresponding thread for the Bluetooth device, and placing the thread in the thread pool; and / or, If there is a thread in the thread pool that lacks a corresponding online Bluetooth device, the thread is removed from the thread pool, and a Bluetooth connection is re-established with the Bluetooth device with the thread ID of the thread as the MAC address.

4. The method according to claim 3, characterized in that: The Bluetooth device is a smart home device.

5. An electronic device, characterized in that: The electronic device controls one or more Bluetooth devices based on an application APP, and the electronic device includes: A Bluetooth connection module, used to establish a Bluetooth connection with a Bluetooth device; An acquisition module, used for acquiring a media access control address MAC address of the Bluetooth device; A thread establishment module, used for establishing a corresponding thread for the Bluetooth device using the MAC address as a thread identity ID, wherein the thread is used for communicating with the Bluetooth device; The thread pool management module is used to put the thread into a thread pool, wherein the thread pool includes threads corresponding to one or more Bluetooth devices, the threads corresponding to the multiple Bluetooth devices are parallel, and the Bluetooth connection status of the one or more Bluetooth devices is recorded through a Bluetooth device list.

6. The electronic device according to claim 5, characterized in that: The electronic device further comprises: A monitoring module, used to monitor the status of each thread in the thread pool and each Bluetooth device in the Bluetooth device list; The control module is used to control each Bluetooth device and / or each thread based on the corresponding relationship between each thread and the online Bluetooth device in the Bluetooth device list.

7. The electronic device according to claim 6, characterized in that: The control module comprises: A judging module, used for judging whether each of the threads corresponds one-to-one to an online Bluetooth device in the Bluetooth device list; The sub-control module is used to, when the judgment module finds that there is an online Bluetooth device in the Bluetooth device list that lacks a corresponding thread, use the MAC address of the Bluetooth device as the thread ID to establish a corresponding thread for the Bluetooth device and put the thread into the thread pool; and / or, when the judgment module finds that there is a thread in the thread pool that lacks a corresponding online Bluetooth device, remove the thread from the thread pool and re-establish a Bluetooth connection with a Bluetooth device with the thread ID of the thread as the MAC address.

8. The electronic device according to claim 7, characterized in that: The Bluetooth device is a smart home device.

9. An electronic device comprising a memory, at least one processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the computer program, the method according to any one of claims 1 to 4 is implemented.

10. A computer-readable storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, the method according to any one of claims 1 to 4 is implemented.

Citation Information

Patent Citations

  • Android thread pool design method for multi-point continuous collection Bluetooth communication

    CN105868013A

  • Multi-Bluetooth equipment management and non-inductive data acquisition algorithm

    CN111711997A

  • Method for implementing bluetooth automatic return link in android system

    US20180103338A1