Adds functionality to automaticly reconnect the modem during measurements.
This commit is contained in:
@@ -257,6 +257,29 @@ def monitor_gps(ser, output_file):
|
||||
return
|
||||
|
||||
|
||||
def connect_moden(provider="telekom"):
|
||||
print_message("Connect modem with provider {} ...".format(provider))
|
||||
os.system("/root/connect-modem.py -l {}".format(provider))
|
||||
print_message("...done")
|
||||
|
||||
|
||||
def reconnect_modem(provider="telekom"):
|
||||
print_message("Reonnect modem with provider {} ...".format(provider))
|
||||
os.system("/root/connect-modem.py -s")
|
||||
os.system("/root/connect-modem.py -l {}".format(provider))
|
||||
print_message("...done")
|
||||
|
||||
|
||||
def is_modem_connected():
|
||||
timeout = 5
|
||||
try:
|
||||
request = requests.get("http://130.75.73.69", timeout=timeout)
|
||||
return True
|
||||
except (requests.ConnectionError, requests.Timeout) as exception:
|
||||
pass
|
||||
return False
|
||||
|
||||
|
||||
class Server:
|
||||
def __init__(self, config):
|
||||
self.config = config
|
||||
@@ -724,6 +747,8 @@ class Client:
|
||||
ws_filter = "{} and port {}".format("tcp", self.config["port"])
|
||||
print_message("Use ws filter: {}".format(ws_filter))
|
||||
for n in range(1, self.config["number_of_measurements"] + 1):
|
||||
if not is_modem_connected():
|
||||
reconnect_modem()
|
||||
print_message(
|
||||
"{} of {}".format(n, self.config["number_of_measurements"])
|
||||
)
|
||||
@@ -778,6 +803,8 @@ class Client:
|
||||
enable_tcp_probe()
|
||||
print_message("tcp probe is now enabled")
|
||||
for n in range(1, self.config["number_of_measurements"] + 1):
|
||||
if not is_modem_connected():
|
||||
reconnect_modem()
|
||||
print_message(
|
||||
"{} of {}".format(n, self.config["number_of_measurements"])
|
||||
)
|
||||
@@ -975,6 +1002,8 @@ async def start_server(args):
|
||||
|
||||
|
||||
async def start_client(args):
|
||||
if not is_modem_connected():
|
||||
connect_moden()
|
||||
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
s.connect((args.client, args.port))
|
||||
s.send(config2json(args))
|
||||
|
||||
Reference in New Issue
Block a user