-
Notifications
You must be signed in to change notification settings - Fork 278
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Reconnection Attempts and Logging for Wi-Fi Checker (Issue #347) #376
Conversation
@@ -0,0 +1 @@ | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what is the need for this file? and this line specifically?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The wifi_status_log.txt file is set up to capture logs from Wi-Fi connection events. Since it only starts filling when the code runs, it’s currently empty. Let me know if you’d prefer I remove it from the repository.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you try to add the logic inside the script? This means that when the logging starts to capture, it should create the file automatically. That means there shouldn't be any file initially, but when the script runs and captures the log, it should create the file and then insert the data.
you can follow this code as reference:
file_name = "example.txt"
try:
with open(file_name, 'x') as file:
file.write("This is a new file created only if it didn't exist.")
print(f"File '{file_name}' created successfully.")
except FileExistsError:
print(f"File '{file_name}' already exists.")
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I absolutely can, I'll do that today.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Everything is done.
Here are the updates I made to the script:
Automatic log file creation:
The script now checks if the log file exists. If not, it automatically creates the file before writing any logs.
Improved error handling:
Added better error handling for netsh and ping commands to ensure the script behaves more reliably in different scenarios.
Constants for better configuration:
Extracted key values like the log file name and ping target into constants for easier customization.
I tested everything, and it works as expected. Below is the log file when the WiFi is manually disabled:
2024-11-18 19:15:02,500 - WiFi is enabled and connected to the internet.
2024-11-18 19:15:02,527 - WiFi connection not working, ping failed.
2024-11-18 19:15:02,527 - Attempt 1 to reconnect...
2024-11-18 19:15:07,146 - WiFi disabled
2024-11-18 19:15:11,814 - WiFi enabled
2024-11-18 19:15:16,864 - Reconnection attempt 1 failed.
2024-11-18 19:15:16,864 - Attempt 2 to reconnect...
2024-11-18 19:15:21,157 - WiFi disabled
2024-11-18 19:15:23,870 - WiFi enabled
2024-11-18 19:15:28,926 - Reconnection attempt 2 failed.
2024-11-18 19:15:28,936 - Attempt 3 to reconnect...
2024-11-18 19:15:33,427 - WiFi disabled
2024-11-18 19:15:35,974 - WiFi enabled
2024-11-18 19:15:41,098 - Reconnection successful!
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If it is possible to add the logic I mentioned in the comment, then you may do so. Otherwise, just request it again, and I will merge the changes. Thanks for your contributions 🥇
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@@ -0,0 +1 @@ | |||
|
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
PR Title
Add reconnection attempts for Wi-Fi with logging
Summary
This PR introduces a Wi-Fi reconnection mechanism with logging. It attempts to reconnect to Wi-Fi up to 3 times if the connection is not working. The process is logged with information on the Wi-Fi status and reconnection attempts.
Description
This change adds functionality for:
wifi_status_log.txt
records all actions.The changes are as follows:
job()
function to attempt reconnection up to 3 times if no internet is detected.Checks
in the repository
Thank You,
Badis