Hey @henrik
Are you referring to my mention of this thread here?
If so that is past of our closed source production code base for the company I work for. I would have to seek permission to spin the WiFi connectivity checking and control thread off to a separate open source project. To be clear I think I could get permission to do so, but I want to make sure that it will serve your need before doing so.
I think I can describe its function as it isn’t any secret.
This thread is designed to be spun off the main process and report and maintain the connectivity status.
It does several things to accomplish that.
First it writes a new network connection with nmcli that is adapter specific and sets it up:
print_command(f'nmcli connection add ' f'con-name {self.id} ' f'ifname {self.interface.name} ' f'type wifi ' f'autoconnect yes ' f'save no ' f'ssid {self.env["prod_ssid_master"]} ' f'802-11-wireless.cloned-mac {self.env.master_mac} ' f'802-11-wireless-security.auth-alg open ' f'802-11-wireless-security.key-mgmt wpa-psk ' f'802-11-wireless-security.psk {self.env["prod_psk_master"]}')
As you can see it relies on a object framework that fills in the important settings.
Then it can use that connection to accomplish some of the more useful debugging steps below.
The connectivity loop is probably more what your after:
Over and over it checks for internet with
def internet(host="8.8.8.8", port=53, timeout=3): """ source: https://stackoverflow.com/a/33117579/11116438 Host: 8.8.8.8 (google-public-dns-a.google.com) OpenPort: 53/tcp Service: domain (DNS/TCP) """ try: socket.setdefaulttimeout(timeout) socket.socket(socket.AF_INET, socket.SOCK_STREAM).connect((host, port)) return True except Exception as ex: print(ex) return False
If that fails we do what I called a soft_reset:
def soft_reset(env): print_command('ip route flush 0/0') if not env.current_connection: if env['in_the_lab']: print_command('nmcli c up dm_debug') else: print_command(f'nmcli c up {env["primary_con_name"]}') else: env.current_connection.up() status = internet() if status: logging.info(f"Soft-reset complete, you should be able to see this") else: logging.info(f"Soft-reset failed") return status
That solves the bulk of solvable network issues in my experience. However, we ship with multiple adapters and if there is anything Network manager sucks at it is having multiple wifi adapters and only one connection settings.
So the next step would be to rotate adapters by managing and un-managing them in NM.
This is probably not relevant to most people.
@henrik
What are your needs from this python thread?
What kind of problems are you looking to solve?
What would be the most useful way to me to share this code? My preferance would be a simple python module that you can pull in from github and launch with a simple Thread() command.
-Thomas