Skip to content

Commit

Permalink
nmcli down up after switch to public ip
Browse files Browse the repository at this point in the history
  • Loading branch information
Stefal committed Jul 18, 2024
1 parent 18e5dd2 commit cfad198
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 15 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
32 changes: 19 additions & 13 deletions tools/modem_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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")

2 changes: 1 addition & 1 deletion rtkbase_update.sh → tools/rtkbase_update.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion unit/modem_check.service
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit cfad198

Please sign in to comment.