I guess this question has already been asked a couple of times but I can not get hold of the answer.
Following the issue I had with my LTE/4G router (https://community.victronenergy.com/questions/64911/issue-with-4glte-provider-assigned-non-public-ip-a.html) I have found a script to check and enable the data. I have tweaked with the test to the internet, as it is a part of the problem. Probably not most nice script, but is works.
This script works fine in terminal mode on a connected Mac OS. As I'm a newby in scripting, I want to implement this script on the Venus OS. I was able to connect to the root and run it from the terminal. Now I want to have it run in an unattend mode (when I stop the terminal, my script stops also).
Also I want it also get back running after a reboot or a new release.
Maybe somebody can point me to the right documentation, or explain it.
The cherry on the cake will be: write the messages to a logging and raise an alarm in the VRM.
Thanks in advance because the mobile operator (BASE) put the fault on the router and are not willing to help, and Netgear does not care as it is minor issue.....
Best regards,
Philippe
#!/usr/bin/env python3 """ This scripts monitors the MR1100 to re-enable Data automatically. This is useful with operators that use PPP and which systematically disconnect users after a certain period of time. Works with firmware 12.06.08.00 """ import requests import json import time import datetime import sys """ if len(sys.argv) < 2: print("Usage: {} <IP> <ADMIN_PASSWORD>".format(sys.argv[0])) sys.exit(1) ip = sys.argv[1] pwd = sys.argv[2] """ ip = "192.168.1.1" pwd = " you will get this one :) " timeout = 2 url_base = "http://{}".format(ip) url_session = "{}/sess_cd_tmp".format(url_base) url_js_token = "{}/api/model.json".format(url_base) url_config = "{}/Forms/config".format(url_base) url_json = "{}/api/model.json".format(url_base) url_json_success = "{}/success.json".format(url_base) url_success = "{}/index.html".format(url_base) def login(r): try: api = r.get(url_js_token, timeout=timeout).text except: print("Failed to connect to router") return try: api = json.loads(api) global token token = api['session']['secToken'] except: print("Failed to fetch authentification token") return data = { 'token': token, 'err_redirect': '/index.html?loginfailed', 'ok_redirect': '/index.html', 'session.password': pwd, } try: redirect_url = r.post(url_config, data=data, timeout=timeout).url if redirect_url == url_success: return True else: print("Failed to authenticate, incorrect password?") return except: print("Router failed to respond to authentication challenge") return def get_status(r): try: json_model = json.loads(r.get(url_json, timeout=10).text) status = json_model['wwan']['connection'] return status except: print("Cannot retrieve connection status") def reconnect(r): disconnect = { 'token': token, 'err_redirect': '/error.json', 'ok_redirect': '/success.json', 'wwan.autoconnect': 'Never', } connect = { 'token': token, 'err_redirect': '/error.json', 'ok_redirect': '/success.json', 'wwan.autoconnect': 'HomeNetwork', } try: push = r.post(url_config, data=disconnect, timeout=timeout) if push.url != url_json_success: print("Failed to disconnect data") except: print("Invalid answer from router") return try: push = r.post(url_config, data=connect, timeout=timeout) if push.url != url_json_success: print("Failed to reconnect data") return except: print("Invalid answer from router") def internet(): url = "http://www.google.com" timeout = 5 try: request = requests.get (url, timeout=timeout) return True except: print ("No internet connection") return False def main(dry_run=None): data_status = None r = requests.Session() login_status = login(r) if login_status != True: return else: data_status = get_status(r) if dry_run is True: return True if data_status != "Connected": print("Data appears to be disconnected, reconnecting..") reconnect(r) nb_tries = 0 while data_status != "Connected" or nb_tries < 3: data_status = get_status(r) time.sleep(1) nb_tries+=1 if data_status == "Connected": timestamp = datetime.datetime.now() timestamp = timestamp.strftime("%Y-%m-%d %H:%M:%S") print("Reconnection successful {}".format(timestamp)) else: print("Data is still offline, this should not happen") else: if internet () != True: print("Data appears to be disconnected, reconnecting..") reconnect(r) nb_tries = 0 while data_status != "Connected" or nb_tries < 3: data_status = get_status(r) time.sleep(1) nb_tries+=1 if data_status == "Connected": timestamp = datetime.datetime.now() timestamp = timestamp.strftime("%Y-%m-%d %H:%M:%S") print("Reconnection successful {}".format(timestamp)) else: print("Data is still offline, this should not happen") else: return if __name__ == '__main__': try: dry_run = main(dry_run=True) if dry_run is None: sys.exit(1) else: print("Connection to router successful. Monitoring disconnections") while True: main() time.sleep(2) except KeyboardInterrupt: sys.exit(0)