From cfad1981e483d74da04f53b8d7b354661100d610 Mon Sep 17 00:00:00 2001 From: Stefal Date: Thu, 18 Jul 2024 17:42:41 +0200 Subject: [PATCH] nmcli down up after switch to public ip --- CHANGELOG.md | 9 ++++++ tools/modem_check.py | 32 ++++++++++++-------- rtkbase_update.sh => tools/rtkbase_update.sh | 2 +- unit/modem_check.service | 2 +- 4 files changed, 30 insertions(+), 15 deletions(-) rename rtkbase_update.sh => tools/rtkbase_update.sh (99%) diff --git a/CHANGELOG.md b/CHANGELOG.md index 706f6b61..83351a1d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,14 @@ # Changelog +## [2.6.1] - not released +### Added +### Changed +### Deprecated +### Removed +### Fixed + - Cellular modem: nmcli connection was not updated after a switch to public ip address. +### Security + ## [2.6.0] - 2024-07-05 ### Added - Septentrio Mosaic-X5 detection and configuration diff --git a/tools/modem_check.py b/tools/modem_check.py index 8b185b04..1428a5bf 100644 --- a/tools/modem_check.py +++ b/tools/modem_check.py @@ -53,6 +53,7 @@ def get_public_ip_address(): try: modem = Modem(MODEM_PORT) public_ip = modem.get_ip_address() + public_ip = None if public_ip == '0.0.0.0' else public_ip except Exception as e: print (e) @@ -76,6 +77,24 @@ def ping(host): public_ip = get_public_ip_address() ping_host = ping('caster.centipede.fr') or ping('pch.net') +if USE_PUBLIC_IP and ip_in_use != public_ip and public_ip is not None: + try: + print("Internal Ip address in use: ", ip_in_use) + print("Modem public Ip address: ", public_ip) + modem = Modem(MODEM_PORT) + modem.set_usbnetip_mode(1) + print("Request to switch to public IP address done!") + print("It could take a few minutes to be active") + time.sleep(5) + nmcli.connection.down(CONN_NAME) + time.sleep(5) + nmcli.connection.up(CONN_NAME) + except Exception as e: + print(e) + finally: + print("closing modem connexion") + modem.close() + if ip_in_use == None or public_ip == None or network_reg == False or ping_host == False: print("Internal Ip address in use: ", ip_in_use) print("Modem public Ip address: ", public_ip) @@ -94,19 +113,6 @@ def ping(host): finally: modem.close() -elif USE_PUBLIC_IP and ip_in_use != public_ip: - try: - print("Internal Ip address in use: ", ip_in_use) - print("Modem public Ip address: ", public_ip) - modem = Modem(MODEM_PORT) - modem.set_usbnetip_mode(1) - print("Request to switch to public IP address done!") - print("It could take a few minutes to be active") - except Exception as e: - print(e) - finally: - print("closing modem connexion") - modem.close() #else: # print("We are already using the public Ip") diff --git a/rtkbase_update.sh b/tools/rtkbase_update.sh similarity index 99% rename from rtkbase_update.sh rename to tools/rtkbase_update.sh index f8a394b3..dfeb21f7 100755 --- a/rtkbase_update.sh +++ b/tools/rtkbase_update.sh @@ -201,7 +201,7 @@ upd_2.5.0 () { #this update function is here only for testing update, but could be useful in case of a failed 2.5 to 2.6 update. upd_2.6.0() { - upd_2.5.0 + "${destination_directory}"/tools/install.sh --user "${standard_user}" --unit-files } #check if we can apply the update diff --git a/unit/modem_check.service b/unit/modem_check.service index d83ed587..726236f4 100644 --- a/unit/modem_check.service +++ b/unit/modem_check.service @@ -5,7 +5,7 @@ Wants=network-online.target [Service] Type=simple -User={user} +User=root ExecStart={python_path} {script_path}/tools/modem_check.py Restart=on-failure RestartSec=30