Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Converted AutoInstall to use SDK Data for settings. Updated version to 0.9. #103

Merged
merged 3 commits into from
Nov 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 31 additions & 3 deletions AutoInstall/AutoInstall.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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}')
Expand Down Expand Up @@ -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}')
Expand Down Expand Up @@ -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}')
Expand Down
6 changes: 3 additions & 3 deletions AutoInstall/package.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
8 changes: 5 additions & 3 deletions AutoInstall/readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ AutoInstall

Application Version
===================
0.8
0.9

NCOS Devices Supported
======================
Expand All @@ -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
Expand All @@ -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
Expand Down
Loading