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

Added appdata_sample #119

Merged
merged 5 commits into from
Apr 10, 2024
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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ The Application Developers Guide is the best document to read first.
- A template for the creation of a new application utilizing the csclient library.
- **app_holder**
- Just a holder for dynamic_app. See dynamic_app.
- **appdata_sample**
- Store and retrieve settings in SDK Appdata in configuration.
- **Autoinstall**
- Automatically choose fastest SIM on install. On bootup, AutoInstall detects SIMs, and ensures (clones) they have unique WAN profiles for prioritization. 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.
- **Installer_UI**
Expand Down
32 changes: 32 additions & 0 deletions appdata_sample/appdata_sample.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# appdata_sample - example of how to use SDK Appdata to store and retrieve settings in NCOS Configs.
# the get_appdata() function will return the value of the appdata entry with the specified name.
# if the appdata is not found, it will save the default_appdata to the NCOS Configs and return it.

from csclient import EventingCSClient
import json
import time

default_appdata = {
"server": "192.168.0.1",
"port": 8000
}

def get_appdata(name):
"""Get appdata from NCOS Configs. If not found, save default_appdata and return it."""
try:
appdata = cp.get('config/system/sdk/appdata')
data = json.loads([x["value"] for x in appdata if x["name"] == name][0])
except:
data = default_appdata
cp.post('config/system/sdk/appdata', {"name": name, "value": json.dumps(data)})
cp.log(f'No appdata found - Saved default: {data}')
return data

cp = EventingCSClient('appdata_sample')
cp.log('Starting...')

# Run a loop to get the appdata every 10 seconds so you can see user changes.
while True:
appdata = get_appdata('appdata_sample')
cp.log(f'Appdata: {appdata}')
time.sleep(10)
Loading
Loading