Networking method and device based on WIFI module to access wireless network
Patent Information
- Application Number
- CN202211002856.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-08-19
- Publication Date
- 2026-11-03
- Estimated Expiration
- 2042-08-19
AI Technical Summary
Existing technology cannot predict the AP connection status and network communication status of the WIFI module in advance, which causes the WIFI module to be offline for a long time when it malfunctions, and the network to be interrupted when it is moved, making it difficult to guarantee communication stability.
By executing the AP connection processing thread, it determines whether the WIFI module is in STA working mode, selects the AP with the strongest signal strength to connect to based on the current AP connection status and network communication status, and monitors the heartbeat count to troubleshoot problems.
This technology enables early detection of the AP connection status and network communication status of the WIFI module, timely selection of the optimal AP for wireless networking, ensuring communication stability, and timely troubleshooting of module faults, thereby improving the communication stability of the WIFI module.
Smart Images

Figure CN117082595B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of wireless communication technology, and in particular to a networking method and apparatus for accessing a wireless network based on a WIFI module. Background Technology
[0002] Wi-Fi is a wireless local area network technology based on the IEEE 802.11 standard. In a Wi-Fi wireless network, one Wi-Fi module acts as an AP (Access Point), and the other Wi-Fi modules act as STAs (Stations, similar to wireless terminals). Only after a STA successfully connects to the AP can it communicate with the AP. Communication between STAs also relies on the AP for relay. Before authentication and successful connection, STAs cannot communicate with the AP or with other STA modules.
[0003] Currently, the main approach involves manually controlling the STA to scan for nearby online access points (APs), selecting one for authentication and connection, and rescanning for another AP after a wireless network interruption. However, in practical applications, when the Wi-Fi module itself malfunctions, such as freezing after a period of operation, a power-off reset is necessary to restore normal operation. In this situation, existing technology only allows reconnection to the selected AP, failing to address the module's inherent faults and leading to prolonged offline status. Furthermore, when the Wi-Fi module is constantly moving, current technology only allows reconnection after detecting a wireless network interruption, already causing a temporary interruption of the wireless network for the device. Therefore, current Wi-Fi networking technology cannot proactively determine the AP connection and network communication status to select the optimal AP, nor can it promptly resolve Wi-Fi module malfunctions, making it difficult to comprehensively and effectively guarantee Wi-Fi communication stability. Summary of the Invention
[0004] To overcome the shortcomings of existing technologies, this invention provides a networking method and apparatus for accessing wireless networks based on a WIFI module. This method can determine the AP connection status and network communication status of the WIFI module in advance, and select the optimal AP for wireless networking in a timely manner, which is beneficial to comprehensively and effectively ensure the communication stability of the WIFI module.
[0005] To address the aforementioned technical problems, in a first aspect, an embodiment of the present invention provides a networking method for accessing a wireless network based on a WIFI module, comprising:
[0006] Start executing the AP connection processing thread to determine whether the WIFI module is in STA working mode;
[0007] When it is determined that the WIFI module is in STA working mode, it is determined whether the WIFI module needs to connect to the AP based on the current AP connection status and network communication status of the WIFI module.
[0008] When it is determined that the WIFI module needs to connect to an AP, the AP with the strongest signal strength is selected from all online APs with the same SSID as the target SSID as the optimal AP.
[0009] The WIFI module is connected to the optimal AP, and a WIFI wireless network is formed when the connection is successful. The execution of the AP connection processing thread ends, and the AP connection processing thread is executed again.
[0010] Furthermore, the networking method for accessing a wireless network based on a WIFI module also includes:
[0011] If it is determined that the WIFI module is not in STA working mode, the execution of the AP connection processing thread is terminated, and the execution of the AP connection processing thread is restarted.
[0012] When it is determined that the WIFI module does not need to connect to the AP, the execution of the AP connection processing thread ends, and the execution of the AP connection processing thread starts again.
[0013] Furthermore, the networking method for accessing a wireless network based on a WIFI module also includes:
[0014] When the AP connection processing thread starts execution, the heartbeat count of the AP connection processing thread is incremented by one, and the heartbeat count of the AP connection processing thread is updated.
[0015] If the heartbeat count of the AP connection processing thread does not change within a preset time period, the AP connection processing thread is re-executed.
[0016] When the AP connection processing thread is re-executed, the re-execution count of the AP connection processing thread is incremented by one, and the re-execution count of the AP connection processing thread is updated.
[0017] When the number of times the AP connection processing thread is re-executed reaches a preset execution threshold, the WIFI module is restarted.
[0018] Furthermore, determining whether the WIFI module needs to connect to the AP based on the current AP connection status and network communication status of the WIFI module specifically involves:
[0019] Obtain the current AP connection status of the WIFI module, and when the current AP connection status of the WIFI module is not connected to the AP, determine that the WIFI module needs to connect to the AP for the first time;
[0020] When the current AP connection status of the WIFI module is "connected to AP", the current network communication status of the WIFI module is monitored. If the current network communication status of the WIFI module is detected to be abnormal, it is determined that the WIFI module needs to reconnect to the AP.
[0021] Furthermore, the step of monitoring the current network communication status of the WIFI module, and determining that the WIFI module needs to reconnect to the AP when the current network communication status of the WIFI module is detected to be abnormal, specifically involves:
[0022] The AP currently connected to the WIFI module is used as the target AP, and the system monitors whether the WIFI module successfully obtains the network parameters sent by the target AP.
[0023] When it is detected that the WIFI module has successfully obtained the network parameters sent by the target AP, the current network connection status of the WIFI module is detected by ping processing.
[0024] When the network connection status of the WIFI module is detected to be abnormal, the network communication status of the WIFI module is determined to be abnormal.
[0025] Furthermore, when determining that the WIFI module needs to connect to an AP, the AP with the strongest signal strength is selected as the optimal AP from all online APs with the same SSID as the target SSID, specifically as follows:
[0026] When it is determined that the WIFI module needs to connect to the AP for the first time, the target SSID is selected according to the predefined AP connection mode;
[0027] When it is determined that the WIFI module needs to reconnect to the AP, the SSID corresponding to the AP currently connected to the WIFI module is used as the target SSID;
[0028] Based on a predefined timed scanning strategy or automatic scanning strategy, the AP with the strongest signal strength is selected from all online APs with the same SSID as the target SSID as the optimal AP.
[0029] Furthermore, the step of selecting the AP with the strongest signal strength from all online APs with the same SSID as the target SSID according to a predefined timed scanning strategy specifically involves:
[0030] When the preset scanning time is reached at the current time, scan all online APs and select APs with the same SSID as the target SSID as pre-selected APs;
[0031] Based on the signal strength of each of the pre-selected APs, the AP with the highest signal strength is selected as the optimal AP from all the pre-selected APs.
[0032] Furthermore, the step of selecting the AP with the strongest signal strength from all online APs with the same SSID as the target SSID according to a predefined automatic scanning strategy specifically involves:
[0033] The current gateway latency of the WIFI module is obtained using ping processing;
[0034] When the current gateway latency of the WIFI module reaches a preset gateway latency threshold, scan all online APs for APs with the same SSID as the target SSID as pre-selected APs;
[0035] Based on the signal strength of each of the pre-selected APs, the AP with the highest signal strength is selected as the optimal AP from all the pre-selected APs.
[0036] Furthermore, connecting the WIFI module to the optimal AP specifically involves:
[0037] Based on the MAC address of the optimal AP, the WIFI module is connected to the optimal AP.
[0038] Secondly, one embodiment of the present invention provides a networking device for accessing a wireless network based on a WIFI module, comprising:
[0039] The STA enable judgment module is used to start executing the AP connection processing thread and determine whether the WIFI module is in STA working mode;
[0040] The network status monitoring module is used to determine whether the WIFI module needs to connect to the AP based on the current AP connection status and network communication status of the WIFI module when it is determined that the WIFI module is in STA working mode.
[0041] The optimal AP selection module is used to select the AP with the strongest signal strength from all online APs with the same SSID as the target SSID when it is determined that the WIFI module needs to connect to an AP.
[0042] The WIFI wireless networking module is used to connect the WIFI module to the optimal AP, and when the connection is successful, form a WIFI wireless network, terminate the execution of the AP connection processing thread, and then execute the AP connection processing thread again.
[0043] Compared with the prior art, the embodiments of the present invention have the following beneficial effects:
[0044] The process begins by executing the AP connection processing thread, determining whether the Wi-Fi module is in STA mode. If it is in STA mode, the process checks the current AP connection status and network communication status to determine if the module needs to connect to an AP. If it does, the process selects the AP with the strongest signal from all online APs with the same SSID as the target AP. The module is then connected to the optimal AP, and a Wi-Fi wireless network is formed upon successful connection. The AP connection processing thread then terminates and is executed again, continuously monitoring the current AP connection status and network communication status to optimize the Wi-Fi wireless network. Compared to existing technologies, the embodiments of the present invention automatically determine whether the WIFI module needs to connect to an AP based on the current AP connection status and network communication status of the WIFI module when the WIFI module is in STA working mode. When it is determined that the WIFI module needs to connect to an AP, the optimal AP is automatically selected for wireless networking to form a WIFI wireless network. This can determine the AP connection status and network communication status of the WIFI module in advance and select the optimal AP for wireless networking in a timely manner, which is beneficial to comprehensively and effectively ensuring the communication stability of the WIFI module.
[0045] Furthermore, embodiments of the present invention monitor the heartbeat count of the AP connection processing thread and determine the operation status of the AP connection processing thread based on the changes in the heartbeat count. This can promptly eliminate WIFI module malfunctions and effectively ensure the communication stability of the WIFI module. Attached Figure Description
[0046] Figure 1 This is a flowchart illustrating a networking method for accessing a wireless network based on a WIFI module according to the first embodiment of the present invention.
[0047] Figure 2 This is an example of a data flow graph showing the connection to the optimal AP in the first embodiment of the present invention;
[0048] Figure 3 This is a data flow diagram illustrating the restart and startup of the WIFI module in the first embodiment of the present invention;
[0049] Figure 4 This is a data flow diagram illustrating AP connection determination in the first embodiment of the present invention;
[0050] Figure 5This is a data flow diagram of a timed scanning AP as exemplified in the first embodiment of the present invention;
[0051] Figure 6 This is a data flow diagram of an automatically scanning AP as exemplified in the first embodiment of the present invention;
[0052] Figure 7 This is a schematic diagram of a networking device based on a WIFI module to access a wireless network according to the second embodiment of the present invention. Detailed Implementation
[0053] The technical solutions of this invention will now be clearly and completely described with reference to the accompanying drawings. Obviously, the described embodiments are merely some, not all, of the embodiments of this invention. All other embodiments obtained by those skilled in the art based on the embodiments of this invention without creative effort are within the scope of protection of this invention.
[0054] It should be noted that the step numbers in this document are only for the convenience of explaining the specific embodiments and are not intended to limit the order in which the steps are executed. The method provided in this embodiment can be executed by relevant terminal devices, and the following description uses a WIFI device containing a WIFI module as the execution subject.
[0055] like Figure 1 As shown, the first embodiment provides a networking method for accessing a wireless network based on a WIFI module, including steps S1 to S4:
[0056] S1. Start executing the AP connection processing thread and determine whether the WIFI module is in STA working mode;
[0057] S2. When it is determined that the WIFI module is in STA working mode, determine whether the WIFI module needs to connect to the AP based on the current AP connection status and network communication status of the WIFI module.
[0058] S3. When it is determined that the WIFI module needs to connect to the AP, select the AP with the strongest signal strength from all online APs with the same SSID as the target SSID as the optimal AP;
[0059] S4. Connect the WIFI module to the optimal AP, and when the connection is successful, form a WIFI wireless network, end the execution of the AP connection processing thread, and then execute the AP connection processing thread again.
[0060] As an example, in step S1, after the WIFI device is started, the AP connection processing thread can be executed to determine whether the WIFI module is in STA working mode.
[0061] In step S2, when it is determined that the WIFI module is in STA working mode, the current AP connection status of the WIFI module and the current network communication status of the WIFI module are obtained. Based on the current AP connection status and network communication status of the WIFI module, it is determined whether the WIFI module needs to connect to the AP. Specifically, if the current AP connection status of the WIFI module is not connected to the AP, the monitoring of the current network communication status of the WIFI module is skipped, and it is directly determined that the WIFI module needs to connect to the AP for the first time; if the current AP connection status of the WIFI module is connected to the AP and the current network communication status of the WIFI module is abnormal, it is determined that the WIFI module needs to reconnect to the AP.
[0062] The AP connection status can be further divided into not connected to AP, not successfully connected to AP, and successfully connected to AP. When the current AP connection status of the WIFI module is not connected to AP or not successfully connected to AP, the monitoring of the current network communication status of the WIFI module is skipped, and it is directly determined that the WIFI module needs to connect to AP for the first time. When the current AP connection status of the WIFI module is successfully connected to AP and the current network communication status of the WIFI module is abnormal, it is determined that the WIFI module needs to reconnect to AP.
[0063] In step S3, when it is determined that the WIFI module needs to connect to the AP, the target SSID is selected according to the actual AP connection requirements, all online APs are scanned, and the AP with the strongest signal strength is selected from all online APs with the same SSID as the target SSID as the optimal AP.
[0064] SSID (Service Set Identifier) is a service set identifier. SSID technology can divide a wireless local area network into several subnets that require different authentication methods. Each subnet requires independent authentication, and only authenticated users can enter the corresponding subnet, preventing unauthorized users from entering the network.
[0065] In step S4, the WIFI module is connected to the optimal AP. It is determined whether the connection between the WIFI module and the optimal AP is successful. If the connection is successful, a WIFI wireless network is formed. Simultaneously, the current AP connection status of the WIFI module is updated to "connected to AP," and the AP connection processing thread ends. This process is repeated to continuously monitor the current AP connection status and network communication status of the WIFI module, thus optimizing the WIFI wireless network. The data flow diagram for connecting to the optimal AP is as follows: Figure 2 As shown.
[0066] This embodiment automatically determines whether the WIFI module needs to connect to an AP based on the current AP connection status and network communication status when the WIFI module is in STA working mode. When it is determined that the WIFI module needs to connect to an AP, it automatically selects the optimal AP to form a wireless network. This can determine the AP connection status and network communication status of the WIFI module in advance and select the optimal AP in time to form a wireless network, which is conducive to comprehensively and effectively ensuring the communication stability of the WIFI module.
[0067] In a preferred embodiment, the networking method for accessing a wireless network based on a WIFI module further includes steps S5 to S6:
[0068] S5. When it is determined that the WIFI module is not in STA working mode, the execution of the AP connection processing thread ends and the execution of the AP connection processing thread starts again.
[0069] S6. When it is determined that the WIFI module does not need to connect to the AP, the execution of the AP connection processing thread ends, and the execution of the AP connection processing thread starts again.
[0070] This embodiment terminates the AP connection processing thread when it determines that the WIFI module is not in STA working mode or that the WIFI module does not need to connect to the AP, and then restarts the AP connection processing thread. This process continuously monitors the current AP connection status and network communication status of the WIFI module to optimize the WIFI wireless networking.
[0071] In a preferred embodiment, the networking method for accessing a wireless network based on a WIFI module further includes steps S7 to S10:
[0072] S7. When the AP connection processing thread starts executing, increment the heartbeat count of the AP connection processing thread by one and update the heartbeat count of the AP connection processing thread.
[0073] S8. If the number of heartbeats of the AP connection processing thread does not change within the preset time period, the AP connection processing thread is re-executed.
[0074] S9. When re-executing the AP connection processing thread, increment the re-execution count of the AP connection processing thread by one and update the re-execution count of the AP connection processing thread.
[0075] S10. When the number of times the AP connection processing thread is re-executed reaches the preset execution threshold, restart the WIFI module.
[0076] As an example, in step S7, when the AP connection processing thread starts to be executed, the heartbeat count of the AP connection processing thread is incremented by one, and the heartbeat count of the AP connection processing thread is updated.
[0077] In step S8, if the number of heartbeats of the AP connection processing thread does not change within a preset time period, such as within 1 minute, the AP connection processing thread is re-executed.
[0078] In step S9, when the AP connection processing thread is re-executed, the re-execution count of the AP connection processing thread is incremented by one, and the re-execution count of the AP connection processing thread is updated.
[0079] In step S10, when the number of re-executions of the AP connection processing thread reaches a preset execution threshold, for example, the WIFI module is restarted. The data flow diagram for restarting the WIFI module is shown below. Figure 3 As shown.
[0080] Understandably, if the heartbeat count of the AP connection processing thread does not change for a long time, it means that the AP connection processing thread has been suspended or exited, and the WIFI module needs to be restarted to restore normal operation.
[0081] This embodiment monitors the heartbeat count of the AP connection processing thread and judges the operation status of the AP connection processing thread based on the changes in the heartbeat count. This can promptly eliminate malfunctions of the WIFI module itself and help to comprehensively and effectively ensure the communication stability of the WIFI module.
[0082] In a preferred embodiment, determining whether the WIFI module needs to connect to the AP based on the current AP connection status and network communication status of the WIFI module specifically involves: obtaining the current AP connection status of the WIFI module, and determining that the WIFI module needs to connect to the AP for the first time when the current AP connection status of the WIFI module is not connected to the AP; and monitoring the current network communication status of the WIFI module when the current AP connection status of the WIFI module is connected to the AP, and determining that the WIFI module needs to reconnect to the AP when the current network communication status of the WIFI module is detected to be abnormal.
[0083] In a preferred embodiment, the monitoring of the current network communication status of the WIFI module, and determining that the WIFI module needs to reconnect to the AP when the current network communication status of the WIFI module is detected to be abnormal, specifically involves: taking the AP currently connected to the WIFI module as the target AP, and monitoring whether the WIFI module successfully obtains the network parameters sent by the target AP; when the WIFI module successfully obtains the network parameters sent by the target AP, using ping processing to detect the current network connection status of the WIFI module; and when the current network connection status of the WIFI module is detected to be abnormal, determining that the network communication status of the WIFI module is abnormal.
[0084] As an example, when it is determined that the WIFI module is in STA working mode, the current AP connection status of the WIFI module is obtained and the current network communication status of the WIFI module is monitored. When the current AP connection status of the WIFI module is not connected to the AP, the monitoring of the current network communication status of the WIFI module is skipped and the WIFI module is directly determined to need to connect to the AP for the first time.
[0085] When the current AP connection status of the WIFI module is "connected to AP," the system continues to monitor the current network communication status of the WIFI module. This includes monitoring whether the WIFI module has successfully acquired the target AP, i.e., the network parameters such as IP address and gateway sent by the AP to which the WIFI module is currently connected. If the WIFI module has not successfully acquired the network parameters sent by the target AP, the system continues to monitor whether the WIFI module has successfully acquired the network parameters sent by the target AP until it does, or until the monitoring time reaches a preset monitoring time threshold. At this point, the AP connection processing thread ends and restarts. If the WIFI module successfully acquires the network parameters sent by the target AP, the system checks the STA network parameters by pinging the gateway to detect whether the current network connection status of the WIFI module is abnormal. If the current network communication status of the WIFI module is detected to be normal, the AP connection processing thread ends and restarts. If the current network communication status of the WIFI module is detected to be abnormal, it is determined that the WIFI module needs to reconnect to the AP. The data flow diagram for AP connection determination is as follows: Figure 4 As shown.
[0086] This embodiment continuously judges the current AP connection status and network communication status of the WIFI module while the WIFI module is in STA working mode. When the current AP connection status of the WIFI module is not connected to the AP, and when the current AP connection status of the WIFI module is not connected to the AP and the current network communication status of the WIFI module is abnormal, the optimal AP is selected in time for wireless networking, which helps to comprehensively and effectively ensure the communication stability of the WIFI module.
[0087] In a preferred embodiment, when it is determined that the WIFI module needs to connect to the AP, the AP with the strongest signal strength is selected as the optimal AP from all online APs with the same SSID as the target SSID. Specifically, when it is determined that the WIFI module needs to connect to the AP for the first time, the target SSID is selected according to a predefined AP connection mode; when it is determined that the WIFI module needs to reconnect to the AP, the SSID corresponding to the AP currently connected to the WIFI module is used as the target SSID; and according to a predefined timed scanning strategy or automatic scanning strategy, the AP with the strongest signal strength is selected as the optimal AP from all online APs with the same SSID as the target SSID.
[0088] For example, when it is determined that the WIFI module needs to connect to the AP for the first time, a predefined AP connection mode is obtained. When the predefined AP connection mode is 2.4G mode, the 2.4G SSID is selected as the target SSID. According to a predefined timed scanning policy or automatic scanning policy, the AP with the strongest signal strength is selected from all online APs with the same SSID as the target SSID as the optimal AP. When the predefined AP connection mode is 5G mode, the 5G SSID is selected as the target SSID. According to a predefined timed scanning policy or automatic scanning policy, the AP with the strongest signal strength is selected from all online APs with the same SSID as the target SSID as the optimal AP. When the predefined AP connection mode is a 2.4G+5G combined mode, the 2.4G SSID is first selected as the target SSID. According to a predefined timed scanning policy or automatic scanning policy, the AP with the strongest signal strength is selected from all online APs with the same SSID as the target SSID as the optimal AP. If the WIFI module fails to connect to the optimal AP a certain number of times in 2.4G mode, the system switches to 5G mode and selects the 5G AP. Using the SSID as the target SSID, the system selects the AP with the strongest signal from all online APs with the same SSID as the target SSID, according to a predefined timed scanning strategy or automatic scanning strategy. If the connection between the WIFI module and the optimal AP fails after a certain number of attempts in 5G mode, the system switches back to 2.4G mode, and repeats this process until the connection is successful.
[0089] When it is determined that the WIFI module needs to reconnect to the AP, the SSID of the AP currently connected to the WIFI module is used as the target SSID. According to the predefined timed scanning strategy or automatic scanning strategy, the AP with the strongest signal strength is selected from all online APs with the same SSID as the target SSID as the optimal AP.
[0090] In a preferred embodiment, the step of selecting the AP with the strongest signal strength from all online APs with the same SSID as the target SSID according to a predefined timed scanning strategy specifically involves: when the current time reaches the preset scanning time, scanning all online APs with the same SSID as the target SSID as pre-selected APs; and selecting the AP with the strongest signal strength from all pre-selected APs as the optimal AP based on the signal strength of each pre-selected AP.
[0091] As an example, during the initial connection process of selecting an optimal AP for the WIFI module, a predefined timed scanning strategy is selected, and the timed scanning mode is started. When the current time reaches the preset scanning time, APs with the same SSID as the target SSID are scanned from all online APs as pre-selected APs. Information such as the signal strength and MAC address of each pre-selected AP is obtained. Based on the signal strength of each pre-selected AP, the AP with the strongest signal strength is selected from all pre-selected APs as the optimal AP.
[0092] During the process of selecting an optimal AP for reconnection to the Wi-Fi module, a predefined timed scanning strategy is selected, and the timed scanning mode is initiated. When the preset scanning time is reached, all online APs are scanned for APs with the same SSID as the target SSID as pre-selected APs. Information such as signal strength and MAC address of each pre-selected AP is obtained. Simultaneously, it is determined whether the signal strength of the target AP (the AP currently connected to the Wi-Fi module) is lower than the preset signal strength. If the target AP's signal strength is not lower than the preset signal strength, the Wi-Fi module maintains its connection to the target AP, the reconnection count is reset to zero, and the scan resumes at the next preset scanning time. If the target AP's signal strength is lower than the preset signal strength, the AP with the strongest signal strength is selected as the optimal AP based on the signal strength of each pre-selected AP. The data flow diagram for the timed AP scanning is as follows: Figure 5 As shown.
[0093] In a preferred embodiment, the step of selecting the AP with the strongest signal strength from all online APs with the same SSID as the target SSID according to a predefined automatic scanning strategy specifically involves: using ping processing to obtain the current gateway latency of the WIFI module; when the current gateway latency of the WIFI module reaches a preset gateway latency threshold, scanning all online APs for APs with the same SSID as the target SSID as pre-selected APs; and selecting the AP with the strongest signal strength from all pre-selected APs as the optimal AP based on the signal strength of each pre-selected AP.
[0094] As an example, during the process of selecting an optimal AP for the initial connection or reconnection of the WIFI module, ping processing is used to obtain the current gateway latency of the WIFI module. A predefined automatic scanning strategy is selected, and automatic scanning mode is started. When the current gateway latency of the WIFI module reaches a preset gateway latency threshold, APs with the same SSID as the target SSID are scanned from all online APs as pre-selected APs. The signal strength, MAC address, and other information of each pre-selected AP are obtained. Based on the signal strength of each pre-selected AP, the AP with the strongest signal strength is selected as the optimal AP. The data flow diagram of automatic AP scanning is as follows: Figure 6 As shown.
[0095] In a preferred embodiment, connecting the WIFI module to the optimal AP specifically means connecting the WIFI module to the optimal AP based on the MAC address of the optimal AP.
[0096] Understandably, the WIFI module connects to the optimal access point (AP) based on the AP's MAC address.
[0097] Based on the same inventive concept as the first embodiment, the second embodiment provides as follows: Figure 7 The network device shown includes: a STA enable judgment module 21, used to start executing the AP connection processing thread and determine whether the WIFI module is in STA working mode; a network status monitoring module 22, used to determine whether the WIFI module needs to connect to the AP based on the current AP connection status and network communication status when the WIFI module is determined to be in STA working mode; an optimal AP selection module 23, used to select the AP with the strongest signal strength from all online APs with the same SSID as the target SSID when the WIFI module needs to connect to the AP; and a WIFI wireless networking module 24, used to connect the WIFI module to the optimal AP, and form a WIFI wireless network when the connection is successful, end the execution of the AP connection processing thread, and then execute the AP connection processing thread again.
[0098] In a preferred embodiment, the networking device for accessing the wireless network based on the WIFI module further includes: a thread execution control module, used to: terminate the execution of the AP connection processing thread and restart the execution of the AP connection processing thread when it is determined that the WIFI module is not in STA working mode; and terminate the execution of the AP connection processing thread and restart the execution of the AP connection processing thread when it is determined that the WIFI module does not need to connect to the AP.
[0099] In a preferred embodiment, the networking device for accessing the wireless network based on the WIFI module further includes: a WIFI module restart module, configured to: increment the heartbeat count of the AP connection processing thread by one when the AP connection processing thread starts to execute, and update the heartbeat count of the AP connection processing thread; re-execute the AP connection processing thread when the heartbeat count of the AP connection processing thread does not change within a preset time period; increment the re-execution count of the AP connection processing thread by one when the AP connection processing thread is re-executed, and update the re-execution count of the AP connection processing thread; and restart the WIFI module when the re-execution count of the AP connection processing thread reaches a preset execution count threshold.
[0100] In a preferred embodiment, the network status monitoring module 22 includes: an AP connection status judgment unit, used to obtain the current AP connection status of the WIFI module, and determine that the WIFI module needs to connect to the AP for the first time when the current AP connection status of the WIFI module is not connected to the AP; and a network communication status judgment unit, used to monitor the current network communication status of the WIFI module when the current AP connection status of the WIFI module is connected to the AP, and determine that the WIFI module needs to reconnect to the AP when the current network communication status of the WIFI module is detected to be abnormal.
[0101] In a preferred embodiment, the network communication status determination unit is specifically used to: take the AP currently connected to the WIFI module as the target AP, and monitor whether the WIFI module has successfully obtained the network parameters sent by the target AP; when it is detected that the WIFI module has successfully obtained the network parameters sent by the target AP, use ping processing to detect the current network connection status of the WIFI module; when it is detected that the current network connection status of the WIFI module is abnormal, determine that the network communication status of the WIFI module is abnormal.
[0102] In a preferred embodiment, the optimal AP selection module 23 includes: a target SSID selection unit, used to select a target SSID according to a predefined AP connection mode when it is determined that the WIFI module needs to connect to the AP for the first time; the target SSID selection unit is also used to use the SSID corresponding to the AP currently connected to the WIFI module as the target SSID when it is determined that the WIFI module needs to reconnect to the AP; and an optimal AP selection unit, used to select the AP with the strongest signal strength from all online APs with the same SSID as the target SSID according to a predefined timed scanning strategy or automatic scanning strategy.
[0103] In a preferred embodiment, the optimal AP selection unit is specifically used to: when the current time reaches the preset scanning time, scan all online APs for APs with the same SSID as the target SSID as pre-selected APs; and select the AP with the strongest signal strength from all pre-selected APs as the optimal AP based on the signal strength of each pre-selected AP.
[0104] In a preferred embodiment, the optimal AP selection unit is specifically used to: obtain the current gateway latency of the WIFI module using ping processing; when the current gateway latency of the WIFI module reaches a preset gateway latency threshold, scan all online APs for APs with the same SSID as the target SSID as pre-selected APs; and select the AP with the strongest signal strength from all pre-selected APs as the optimal AP based on the signal strength of each pre-selected AP.
[0105] In a preferred embodiment, the WIFI wireless networking module 24 is specifically used to connect the WIFI module to the optimal AP based on the MAC address of the optimal AP.
[0106] In summary, implementing the embodiments of the present invention has the following beneficial effects:
[0107] By initiating the AP connection processing thread, the system determines whether the Wi-Fi module is in STA mode. If it is in STA mode, it determines whether the module needs to connect to an AP based on the current AP connection status and network communication status. If the module needs to connect, it selects the AP with the strongest signal strength from all online APs with the same SSID as the target SSID as the optimal AP. The Wi-Fi module is then connected to the optimal AP, and upon successful connection, a Wi-Fi wireless network is formed. The AP connection processing thread then terminates and is executed again, continuously monitoring the current AP connection status and network communication status to optimize the Wi-Fi wireless network. This embodiment of the invention, by automatically determining whether the Wi-Fi module needs to connect to an AP based on its current AP connection status and network communication status when it is in STA mode, and automatically selecting the optimal AP for wireless networking when necessary, effectively ensures the communication stability of the Wi-Fi module.
[0108] Furthermore, embodiments of the present invention monitor the heartbeat count of the AP connection processing thread and determine the operation status of the AP connection processing thread based on the changes in the heartbeat count. This can promptly eliminate WIFI module malfunctions and effectively ensure the communication stability of the WIFI module.
[0109] The above description represents the preferred embodiments of the present invention. It should be noted that those skilled in the art can make various improvements and modifications without departing from the principles of the present invention, and these improvements and modifications are also considered to be within the scope of protection of the present invention.
[0110] Those skilled in the art will understand that all or part of the processes in the above embodiments can be implemented by a computer program instructing related hardware. The program can be stored in a computer-readable storage medium, and when executed, it can include the processes described in the above embodiments. The storage medium can be a magnetic disk, optical disk, read-only memory (ROM), or random access memory (RAM), etc.
Claims
1. A networking method for accessing a wireless network based on a WIFI module, characterized in that, include: Start executing the AP connection processing thread to determine whether the WIFI module is in STA working mode; When it is determined that the WIFI module is in STA working mode, it is determined whether the WIFI module needs to connect to the AP based on the current AP connection status and network communication status of the WIFI module. When it is determined that the WIFI module needs to connect to an AP, the AP with the strongest signal strength is selected from all online APs with the same SSID as the target SSID as the optimal AP. The WIFI module is connected to the optimal AP, and a WIFI wireless network is formed when the connection is successful. The execution of the AP connection processing thread ends, and the AP connection processing thread is executed again. Also includes: If it is determined that the WIFI module is not in STA working mode, the execution of the AP connection processing thread is terminated, and the execution of the AP connection processing thread is restarted. When it is determined that the WIFI module does not need to connect to the AP, the execution of the AP connection processing thread ends, and the execution of the AP connection processing thread starts again. Also includes: When the AP connection processing thread starts execution, the heartbeat count of the AP connection processing thread is incremented by one, and the heartbeat count of the AP connection processing thread is updated. If the heartbeat count of the AP connection processing thread does not change within a preset time period, the AP connection processing thread is re-executed. When the AP connection processing thread is re-executed, the re-execution count of the AP connection processing thread is incremented by one, and the re-execution count of the AP connection processing thread is updated. When the number of times the AP connection processing thread is re-executed reaches a preset execution threshold, the WIFI module is restarted.
2. The networking method for accessing a wireless network based on a WIFI module as described in claim 1, characterized in that, The step of determining whether the WIFI module needs to connect to the AP based on the current AP connection status and network communication status of the WIFI module is as follows: Obtain the current AP connection status of the WIFI module, and when the current AP connection status of the WIFI module is not connected to the AP, determine that the WIFI module needs to connect to the AP for the first time; When the current AP connection status of the WIFI module is "connected to AP", the current network communication status of the WIFI module is monitored. If the current network communication status of the WIFI module is detected to be abnormal, it is determined that the WIFI module needs to reconnect to the AP.
3. The networking method for accessing a wireless network based on a WIFI module as described in claim 2, characterized in that, The process involves monitoring the current network communication status of the Wi-Fi module and, when an abnormality is detected in the current network communication status of the Wi-Fi module, determining that the Wi-Fi module needs to reconnect to the access point. Specifically: The AP currently connected to the WIFI module is used as the target AP, and the system monitors whether the WIFI module successfully obtains the network parameters sent by the target AP. When it is detected that the WIFI module has successfully obtained the network parameters sent by the target AP, the current network connection status of the WIFI module is detected by ping processing. When the network connection status of the WIFI module is detected to be abnormal, the network communication status of the WIFI module is determined to be abnormal.
4. The networking method for accessing a wireless network based on a WIFI module as described in claim 1, characterized in that, When determining that the WIFI module needs to connect to an AP, the AP with the strongest signal strength is selected as the optimal AP from all online APs with the same SSID as the target SSID. Specifically: When it is determined that the WIFI module needs to connect to the AP for the first time, the target SSID is selected according to the predefined AP connection mode; When it is determined that the WIFI module needs to reconnect to the AP, the SSID corresponding to the AP currently connected to the WIFI module is used as the target SSID; Based on a predefined timed scanning strategy or automatic scanning strategy, the AP with the strongest signal strength is selected from all online APs with the same SSID as the target SSID as the optimal AP.
5. The networking method for accessing a wireless network based on a WIFI module as described in claim 4, characterized in that, The step of selecting the AP with the strongest signal strength from all online APs with the same SSID as the target SSID according to a predefined timed scanning strategy is as follows: When the preset scanning time is reached at the current time, scan all online APs and select APs with the same SSID as the target SSID as pre-selected APs; Based on the signal strength of each of the pre-selected APs, the AP with the highest signal strength is selected as the optimal AP from all the pre-selected APs.
6. The networking method for accessing a wireless network based on a WIFI module as described in claim 4, characterized in that, The step of selecting the AP with the strongest signal strength from all online APs with the same SSID as the target SSID according to a predefined automatic scanning strategy is as follows: The current gateway latency of the WIFI module is obtained using ping processing; When the current gateway latency of the WIFI module reaches a preset gateway latency threshold, scan all online APs for APs with the same SSID as the target SSID as pre-selected APs; Based on the signal strength of each of the pre-selected APs, the AP with the highest signal strength is selected as the optimal AP from all the pre-selected APs.
7. The networking method for accessing a wireless network based on a WIFI module as described in claim 1, characterized in that, The connection of the WIFI module to the optimal AP is specifically as follows: Based on the MAC address of the optimal AP, the WIFI module is connected to the optimal AP.
8. A networking device for accessing a wireless network based on a WIFI module, characterized in that, include: The STA enable judgment module is used to start executing the AP connection processing thread and determine whether the WIFI module is in STA working mode; The network status monitoring module is used to determine whether the WIFI module needs to connect to the AP based on the current AP connection status and network communication status of the WIFI module when it is determined that the WIFI module is in STA working mode. The optimal AP selection module is used to select the AP with the strongest signal strength from all online APs with the same SSID as the target SSID when it is determined that the WIFI module needs to connect to an AP. The WIFI wireless networking module is used to connect the WIFI module to the optimal AP, and when the connection is successful, form a WIFI wireless network, end the execution of the AP connection processing thread, and then execute the AP connection processing thread again. Also used for: If it is determined that the WIFI module is not in STA working mode, the execution of the AP connection processing thread is terminated, and the execution of the AP connection processing thread is restarted. When it is determined that the WIFI module does not need to connect to the AP, the execution of the AP connection processing thread ends, and the execution of the AP connection processing thread starts again. Also used for: When the AP connection processing thread starts execution, the heartbeat count of the AP connection processing thread is incremented by one, and the heartbeat count of the AP connection processing thread is updated. If the heartbeat count of the AP connection processing thread does not change within a preset time period, the AP connection processing thread is re-executed. When the AP connection processing thread is re-executed, the re-execution count of the AP connection processing thread is incremented by one, and the re-execution count of the AP connection processing thread is updated. When the number of times the AP connection processing thread is re-executed reaches a preset execution threshold, the WIFI module is restarted.
Citation Information
Patent Citations
AP switching method and device, equipment and medium
CN110572859A
Methods and systems for software watchdog support
US20040073891A1
