Skip to content

Commit

Permalink
Added appdata_sample (#119)
Browse files Browse the repository at this point in the history
* Added appdata_sample

* Update README.md

added appdata_sample

* Update send_to_server.py

New send_to_server app

* Update readme.txt

* Update package.ini

version 2.1.0
  • Loading branch information
phate999 authored Apr 10, 2024
1 parent deffb65 commit 49faf28
Show file tree
Hide file tree
Showing 9 changed files with 735 additions and 63 deletions.
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

0 comments on commit 49faf28

Please sign in to comment.