Method for realizing automatic test of Bluetooth transmission based on python
The Bluetooth transmission automated testing method developed through Python solves the problems of high price and complex operation of existing Bluetooth testing tools, achieves easy-to-use and efficient Bluetooth transmission testing, and improves testing efficiency and accuracy.
Patent Information
- Application Number
- CN202411441252.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-15
- Publication Date
- 2025-01-21
AI Technical Summary
Most of the existing Bluetooth testing tools are hardware-based, expensive and complex to operate, and lack easy-to-use, maintainability and scalability testing tools.
Use Python language to develop automated testing methods, automatically connect to Bluetooth devices through scripts, implement data transmission tests, and use timers to monitor the transmission rate, verify file integrity, and simulate abnormal scenarios to evaluate the stability and fault tolerance of the device.
An easy-to-use and efficient Bluetooth transmission automated test method is provided, which reduces test cost and complexity and improves test efficiency and accuracy.
Smart Images

Figure CN119342515A_ABST
Abstract
Description
Technical Field
[0001] The invention belongs to the technical field of Bluetooth, and specifically is a method for realizing automatic testing of Bluetooth transmission based on Python. Background Art
[0002] Bluetooth is a small-range wireless connection technology that can achieve convenient, fast, secure, flexible, low-cost, and low-power data and voice communications between different devices by establishing a wireless personal area network. It is an advanced open wireless communication that uses UHF radio waves in the ISM band of 2.4 to 2.485 GHZ to connect multiple devices and communicate or operate with each other within a distance range. Data transmission is an important function of Bluetooth, and the stability of Bluetooth data transmission between devices is an important indicator for measuring Bluetooth, which includes data transmission rate, data transmission integrity, signal strength, etc. Therefore, during the use of Bluetooth transmission, a set of convenient and effective test methods needs to be provided to help improve the stability indicators of Bluetooth data transmission.
[0003] Most of the existing Bluetooth testing tools are based on hardware or hardware-expanded test platforms. There is a lack of relatively unified testing tools that are easy to use, maintainable, and scalable. Most of the tools have the following problems: First, some testing tools are based on hardware, such as Anritsu MT8852B, Rohde&Schwarz CMW500, and EllisysBluetooth Explorer. As professional Bluetooth testing instruments, they are relatively expensive for enterprises and developers. Second, for professional Bluetooth devices, more time and energy are needed to learn them, and more professional skills and knowledge are needed to master the operation and configuration of the equipment. Summary of the invention
[0004] The purpose of the present invention is to provide a method for realizing automatic testing of Bluetooth transmission based on Python to solve the problems raised in the above background technology.
[0005] In order to achieve the above object, the present invention provides the following technical solution: a method for realizing automatic testing of Bluetooth transmission based on Python, the specific steps are as follows:
[0006] Step 1:
[0007] Start a server service, upload the data file to be transferred, or select the test data file in the use case library;
[0008] Step 2:
[0009] Circularly scan and identify Bluetooth devices and other related information;
[0010]
[0011] Step 3:
[0012] Create a BluetoothSocket object, you can use different communication protocols, use the Bluetooth MAC address or select a list device for Bluetooth connection;
[0013] sock=bluetooth.BluetoothSocket(bluetooth.RFCOMM)
[0014] sock=bluetooth.BluetoothSocket(bluetooth.L2CAP)
[0015] port = Set the port number
[0016] server_sock.bind(("",port))
[0017] server_sock.listen()
[0018] Step 4:
[0019] After connecting to the device, send the download file command to receive the file data;
[0020]
[0021]
[0022] Step 5:
[0023] Get the file size during the transmission process, define a timer to monitor the transmission rate during the data transmission process; start_time = time.time()
[0024] bytes_received += len(data)
[0025] elapsed_time=time.time()-start_time
[0026] if elapsed_time>0:
[0027] transfer_rate=bytes_received / elapsed_time
[0028] print("Transfer rate:{transfer_rate:.2f}bytes / second")
[0029] Step 6:
[0030] After the transfer is completed, the integrity of the file is verified in a variety of ways;
[0031]
[0032] Step 7:
[0033] Through the scenario use case library, the expected files are destroyed, the transmission time is disturbed, the transmission is cut off, and other abnormal transmission scenarios are simulated to verify the stability and fault tolerance of the device under test;
[0034] Step 8:
[0035] During Bluetooth transmission, the Bluetooth signal strength can be obtained in real time and converted into RSSI value for display. The optimal Bluetooth connection distance can be determined by the signal strength.
[0036] rssi=sock.getsockopt(bluetooth.SOL_BLUETOOTH,bluetooth.SO_RCVBUF)
[0037] signal_strength=-(256-ord(rssi[3]))
[0038] Calculation formula: d = 10^((abs(RSSI)-A) / (10*n))
[0039] As a preferred technical solution of the present invention, the RSSI described in step eight is an indication of the strength of the received signal, an optional part of the wireless transmission layer, used to determine the connection quality and whether to increase the broadcast transmission strength.
[0040] As a preferred technical solution of the present invention, the calculation formula described in step eight is: d=10^((abs(RSSI)-A) / (10*n)), wherein d is the calculated distance; RSSI is the received signal strength (negative value); A is the signal strength when the transmitter and the receiver are 1 meter apart; and n is the environmental attenuation factor.
[0041] As a preferred technical solution of the present invention, the scenario use case library described in step seven is a use case generated based on Python encapsulation.
[0042] As a preferred technical solution of the present invention, the multiple verification methods described in step six can improve the verification efficiency of file integrity.
[0043] As a preferred technical solution of the present invention, the operation of the defined timer described in step five enables real-time monitoring of data during transmission.
[0044] As a preferred technical solution of the present invention, the use of different communication protocols described in step three improves the connection efficiency of Bluetooth.
[0045] As a preferred technical solution of the present invention, the cyclic scanning script described in step 2 realizes automatic search of a list of nearby Bluetooth devices and obtains the Bluetooth device name, device address, device type, etc.
[0046] As a preferred technical solution of the present invention, the Bluetooth transmission automatic testing method described in any one of steps 1 to 8 has the characteristics of being easy to use and simple.
[0047] The beneficial effects of the present invention are as follows:
[0048] This solution provides a method for automatically connecting Bluetooth hardware devices based on Python development scripts, and can perform Bluetooth performance tests on data receiving devices and sending devices. The method has the following advantages: through steps one to three, data files available for transmission can be uploaded, and Bluetooth devices can be scanned and paired by matching different communication protocols; through step four, data sending and receiving instructions are performed on the device to perform file transfer; through steps five to eight, scripts are used to monitor data files during the transmission process, and abnormal scenarios of the transmitted files are controlled, which can realize the monitoring of Bluetooth transmission performance, signal strength and other dimensions, etc. BRIEF DESCRIPTION OF THE DRAWINGS
[0049] Figure 1 It is a flow chart of the present invention. DETAILED DESCRIPTION
[0050] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0051] like Figure 1 As shown, the embodiment of the present invention provides a method for realizing automatic testing of Bluetooth transmission based on Python, and the specific steps are as follows:
[0052] Step 1:
[0053] Start a server service, upload the data file to be transferred, or select the test data file in the use case library;
[0054] Step 2:
[0055] Circularly scan and identify Bluetooth devices and other related information;
[0056]
[0057] Step 3:
[0058] Create a BluetoothSocket object, you can use different communication protocols, use the Bluetooth MAC address or select a list device for Bluetooth connection;
[0059] sock=bluetooth.BluetoothSocket(bluetooth.RFCOMM)
[0060] sock=bluetooth.BluetoothSocket(bluetooth.L2CAP)
[0061] port = Set the port number
[0062] server_sock.bind(("",port))
[0063] server_sock.listen()
[0064] Step 4:
[0065] After connecting to the device, send the download file command to receive the file data;
[0066]
[0067]
[0068] Step 5:
[0069] Get the file size during the transfer process and define a timer to monitor the transfer rate during the data transfer process;
[0070] start_time = time.time()
[0071] bytes_received += len(data)
[0072] elapsed_time=time.time()-start_time
[0073] if elapsed_time>0:
[0074] transfer_rate=bytes_received / elapsed_time
[0075] print("Transfer rate:{transfer_rate:.2f}bytes / second")
[0076] Step 6:
[0077] After the transfer is completed, the integrity of the file is verified in a variety of ways;
[0078]
[0079] Step 7:
[0080] Through the scenario use case library, the expected files are destroyed, the transmission time is disturbed, the transmission is cut off, and other abnormal transmission scenarios are simulated to verify the stability and fault tolerance of the device under test;
[0081] Step 8:
[0082] During Bluetooth transmission, the Bluetooth signal strength can be obtained in real time and converted into RSSI value for display. The optimal Bluetooth connection distance can be determined by the signal strength.
[0083] rssi=sock.getsockopt(bluetooth.SOL_BLUETOOTH,bluetooth.SO_RCVBUF)
[0084] signal_strength=-(256-ord(rssi[3]))
[0085] Calculation formula: d = 10^((abs(RSSI)-A) / (10*n))
[0086] The present invention is based on Python language, combined with its cross-platform characteristics, and uses the PyBluez module library to realize automated testing of Bluetooth transmission on different platforms (Windows / MacOS / Linux) and different communication protocols. It can automatically discover nearby Bluetooth devices and establish connections through scripts to realize automated data sending and receiving. The data transmission logic can be defined in the script, and indicators such as data integrity and transmission performance during the transmission process can be monitored to improve test efficiency and accuracy.
[0087] The RSSI in step eight is a received signal strength indication, an optional part of the wireless transmission layer, used to determine the connection quality and whether to increase the broadcast transmission strength.
[0088] Converting the Bluetooth signal strength that can be obtained in real time during Bluetooth transmission into an RSSI value for display is conducive to a more intuitive display of the Bluetooth signal strength and is also conducive to calculating the optimal connection distance of Bluetooth.
[0089] Among them, the calculation formula in step eight is: d=10^((abs(RSSI)-A) / (10*n)), where d is the calculated distance; RSSI is the received signal strength (negative value); A is the signal strength when the transmitter and the receiver are 1 meter apart; n is the environmental attenuation factor.
[0090] Due to the existence of this calculation formula, accurate calculation of the optimal distance value of the Bluetooth connection is achieved, which is conducive to obtaining the optimal distance value of the Bluetooth connection more quickly.
[0091] Among them, the scenario use case library in step seven is a use case generated based on Python encapsulation.
[0092] By using the Python encapsulation method to generate use cases, the integrity of the test data, transmission rate, signal strength, receiving and transmitting frequency, etc. can be controlled, covering a variety of test scenarios and then judging the stability of Bluetooth transmission by the transmission success rate.
[0093] Among them, the multiple verification methods in step six can improve the efficiency of verifying the integrity of the file.
[0094] Verifying files in a variety of ways makes the verification of file data more comprehensive, reduces the omission of file data, and ensures the integrity of file data.
[0095] The operation of the defined timer in step 5 enables real-time monitoring of data during transmission.
[0096] By monitoring the transmission rate during data transmission in real time, the transmission performance and signal strength of Bluetooth in each time period can be monitored, which is conducive to obtaining accurate values.
[0097] Among them, the use of different communication protocols in step three improves the connection efficiency of Bluetooth.
[0098] The use of different communication protocols makes the Bluetooth connection methods more diverse, thereby reducing the waiting time for Bluetooth connection.
[0099] The cyclic scanning script in step 2 can automatically search for a list of nearby Bluetooth devices and obtain the Bluetooth device name, device address, device type, etc.
[0100] Through the circular scanning of the script, the omission of Bluetooth devices can be prevented, thereby improving the accuracy of Bluetooth device information acquisition and the efficiency of Bluetooth device acquisition.
[0101] Among them, the Bluetooth transmission automation test method of any one of steps 1 to 8 has the characteristics of being easy to use and simple.
[0102] The tester only needs to make a simple interface call and pass in the Bluetooth address or test file data, and it can automatically match and connect to the Bluetooth device for file transfer.
[0103] It should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device.
[0104] Although embodiments of the present invention have been shown and described, it will be appreciated by those skilled in the art that various changes, modifications, substitutions and variations may be made to the embodiments without departing from the principles and spirit of the present invention, and that the scope of the present invention is defined by the appended claims and their equivalents.
Claims
1. A method for realizing automatic testing of Bluetooth transmission based on Python, characterized in that: The specific steps are as follows: Step 1: Start a server service, upload the data file to be transferred, or select the test data file in the use case library; Step 2: Circularly scan and identify Bluetooth devices and other related information; foundDevs = discover_devices (nearby Bluetooth devices and identify up_names = True) for(addr,name)in foundDevs: if addr not in alreadyFound: print("Bluetooth device:"+s tr(name)) print("Bluetooth MAC:"+str(addr)) services=bluetooth.find_service(address=addr) for svc in services: print(svc) Step 3: Create a BluetoothSocket object, you can use different communication protocols, use the Bluetooth MAC address or select a list device for Bluetooth connection; sock=bluetooth.BluetoothSocket(bluetooth.RFCOMM) sock=bluetooth.BluetoothSocket(bluetooth.L2CAP) port = Set the port number server_sock.bind(("",port)) server_sock.listen() Step 4: After connecting to the device, send the download file command to receive the file data; Step 5: Get the file size during the transfer process and define a timer to monitor the transfer rate during the data transfer process; Step 6: After the transfer is completed, the integrity of the file is verified in a variety of ways; if actual_checksum==expected_checksum: print("File integrity check passed!") Step 7: Through the scenario use case library, the expected files are destroyed, the transmission time is disturbed, the transmission is cut off, and other abnormal transmission scenarios are simulated to verify the stability and fault tolerance of the device under test; Step 8: During Bluetooth transmission, the Bluetooth signal strength can be obtained in real time and converted into RSSI value for display. The optimal Bluetooth connection distance can be determined by the signal strength. rssi=sock.getsockopt(bluetooth.SOL_BLUETOOTH,bluetooth.SO_RCVBUF) signal_strength=-(256-ord(rssi[3])) Calculation formula: d = 10^((abs(RSSI)-A) / (10*n)).
2. According to claim 1, a method for realizing automatic testing of Bluetooth transmission based on Python, characterized in that: The RSSI described in step eight is a received signal strength indicator, an optional part of the wireless transmission layer, used to determine the connection quality and whether to increase the broadcast transmission strength.
3. According to claim 1, a method for realizing automatic testing of Bluetooth transmission based on Python, characterized in that: The calculation formula described in step eight is: d=10^((abs(RSSI)-A) / (10*n)), where d is the calculated distance; RSSI is the received signal strength (negative value); A is the signal strength when the transmitter and receiver are 1 meter apart; and n is the environmental attenuation factor.
4. According to claim 1, a method for realizing automatic testing of Bluetooth transmission based on Python, characterized in that: The scenario use case library described in step 7 is a use case generated based on Python encapsulation.
5. According to claim 1, a method for realizing automatic testing of Bluetooth transmission based on Python, characterized in that: The multiple verification methods described in step 6 can improve the efficiency of verifying the integrity of the file.
6. The method for realizing automatic testing of Bluetooth transmission based on Python according to claim 1, characterized in that: The operation of the defined timer described in step 5 enables real-time monitoring of data during transmission.
7. The method for realizing automatic testing of Bluetooth transmission based on Python according to claim 1, characterized in that: The use of different communication protocols described in step three improves the connection efficiency of Bluetooth.
8. The method for realizing automatic testing of Bluetooth transmission based on Python according to claim 1, characterized in that: The cyclic scanning script described in step 2 can automatically search the list of nearby Bluetooth devices and obtain the Bluetooth device name, device address, device type, etc.
9. The method for realizing automatic testing of Bluetooth transmission based on Python according to claim 1, characterized in that: The Bluetooth transmission automated testing method described in any one of steps 1 to 8 is easy to use and simple.