From ae3dbca1ff5b501f192dcc5884e124084d7616c0 Mon Sep 17 00:00:00 2001 From: Alex Terrell Date: Wed, 22 Nov 2023 09:33:15 -0700 Subject: [PATCH 1/3] Converted to use SDK Data for settings --- AutoInstall/AutoInstall.py | 34 +++++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/AutoInstall/AutoInstall.py b/AutoInstall/AutoInstall.py index 68e6887f..08c3ebbd 100644 --- a/AutoInstall/AutoInstall.py +++ b/AutoInstall/AutoInstall.py @@ -3,13 +3,22 @@ Then the app collects diagnostics and runs Ookla speedtests on each SIM. Then the app prioritizes the SIMs WAN Profiles by TCP download speed. Results are written to the log, set as the description field, and sent as a custom alert. -The app can be manually triggered again by clearing out the description field in NCM.""" +The app can be manually triggered again by clearing out the description field in NCM. +App settings can be configured in System > SDK Data.""" from csclient import EventingCSClient from speedtest import Speedtest import time import datetime +import json +defaults = { + "MIN_DOWNLOAD_SPD": 0.0, # Mbps + "MIN_UPLOAD_SPD": 0.0, # Mbps + "SCHEDULE": 0, # Run AutoInstall every {SCHEDULE} minutes. 0 = Only run on boot. + "NUM_ACTIVE_SIMS": 0, # Number of fastest (download) SIMs to keep active. 0 = all; do not disable SIMs + "ONLY_RUN_ONCE": False # True means do not run if AutoInstall has been run on this device before. +} class AutoInstallException(Exception): """General AutoInstall Exception.""" @@ -51,6 +60,23 @@ def __init__(self): self.client = EventingCSClient('AutoInstall') self.speedtest = Speedtest() + def get_config(self, name): + """Return config from /config/system/sdk/appdata.""" + appdata = cp.get('config/system/sdk/appdata') + try: + config = json.loads([x["value"] for x in appdata if x["name"] == name][0]) + if not config: + config = defaults + except: + config = defaults + cp.post('config/system/sdk/appdata', {"name": name, "value": json.dumps(config)}) + self.MIN_DOWNLOAD_SPD = config["MIN_DOWNLOAD_SPD"] + self.MIN_UPLOAD_SPD = config["MIN_UPLOAD_SPD"] + self.SCHEDULE = config["SCHEDULE"] + self.NUM_ACTIVE_SIMS = config["NUM_ACTIVE_SIMS"] + self.ONLY_RUN_ONCE = config["ONLY_RUN_ONCE"] + return + def check_if_run_before(self): """Check if AutoInstall has been run before and return boolean.""" if self.ONLY_RUN_ONCE: @@ -169,7 +195,7 @@ def create_unique_WAN_profiles(self): config.pop('_id_') config['priority'] += i i += 0.1 - config['trigger_name'] = f'{stat["info"]["port"]} {stat["info"]["sim"]}' + config['trigger_name'] = f'{stat["diagnostics"]["HOMECARRID"]} {stat["info"]["port"]} {stat["info"]["sim"]}' config['trigger_string'] = \ f'type|is|mdm%sim|is|{stat["info"]["sim"]}%port|is|{stat["info"]["port"]}' self.client.log(f'NEW WAN RULE: {config}') @@ -292,6 +318,7 @@ def prioritize_rules(self, sim_list): def run(self): """Start of Main Application.""" + self.get_config('AutoInstall') self.client.log( f'AutoInstall Starting... MIN_DOWNLOAD_SPD:{self.MIN_DOWNLOAD_SPD} MIN_UPLOAD_SPD:{self.MIN_UPLOAD_SPD} ' f'SCHEDULE:{self.SCHEDULE} NUM_ACTIVE_SIMS:{self.NUM_ACTIVE_SIMS} ONLY_RUN_ONCE:{self.ONLY_RUN_ONCE}') @@ -340,7 +367,8 @@ def run(self): self.client.put(f'config/wan/rules2/{rule_id}/disabled', True) # Prioritizes SIMs based on download speed - sorted_results = sorted(self.sims, key=lambda x: self.sims[x]['download'], reverse=True) + sorted_results = sorted(self.sims, key=lambda x: int(self.sims[x]['download']), reverse=True) # Sort by download speed + # sorted_results = sorted(self.sims, key=lambda x: int(self.sims[x]['diagnostics']['RSRP']), reverse=True) # Sort by RSRP # Configure WAN Profiles self.client.log(f'Prioritizing SIMs: {sorted_results}') From 8136ecd761677d6ea0aac22548e5f50a94342dab Mon Sep 17 00:00:00 2001 From: Alex Terrell Date: Wed, 22 Nov 2023 09:34:47 -0700 Subject: [PATCH 2/3] Updated to version 0.9 --- AutoInstall/package.ini | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/AutoInstall/package.ini b/AutoInstall/package.ini index 3570ee3f..282d79f5 100644 --- a/AutoInstall/package.ini +++ b/AutoInstall/package.ini @@ -3,10 +3,10 @@ uuid=cde20cbb-b146-40ef-9f60-1234567890ab vendor=Cradlepoint notes=AutoInstall SIM Prioritizer firmware_major=7 -firmware_minor=21 -restart=false +firmware_minor=23 +restart=true reboot=true auto_start=true app_type=0 version_major=0 -version_minor=8 +version_minor=9 From 0595964fc337e36aa569d164bd94714ed67cee30 Mon Sep 17 00:00:00 2001 From: Alex Terrell Date: Wed, 22 Nov 2023 09:36:18 -0700 Subject: [PATCH 3/3] Update readme.txt --- AutoInstall/readme.txt | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/AutoInstall/readme.txt b/AutoInstall/readme.txt index 724b659d..ea25d293 100644 --- a/AutoInstall/readme.txt +++ b/AutoInstall/readme.txt @@ -5,7 +5,7 @@ AutoInstall Application Version =================== -0.8 +0.9 NCOS Devices Supported ====================== @@ -19,7 +19,9 @@ None Application Purpose =================== -“AutoInstall” is a SIM Speedtest app designed to test TCP throughput on multiple SIMs, supporting multiple modems, and prioritize them based on download speed, including the following configurable options: +“AutoInstall” is a SIM Speedtest app designed to test TCP throughput on multiple SIMs, supporting multiple modems, and prioritize them based on download speed. + +One the app has been loaded, the following settings can be configured in the router configuration under System > SDK Data: • MIN_DOWNLOAD_SPD – If no SIM download speed meets minimum, a FAILURE report is sent. SIMs are still prioritized and slowest SIMs are disabled according to NUM_ACTIVE_SIMS. Default Value = 0.0 @@ -29,7 +31,7 @@ Default Value = 0.0 Default Value = 0 • NUM_ACTIVE_SIMS – Number of fastest SIMs to keep active. 0=all; do not disable any SIMs. Default Value = 0 -• ONLY_RUN_ONCE – True means do not run if Boot2 has run on this device before. (common for install usage). +• ONLY_RUN_ONCE – True means do not run if AutoInstall has run on this device before. (common for install usage). Default Value = False Overwrites "description" field with results