# Interface... interface_conf = InterfaceConf.load(Host) psu_conf = PSUConf.load(Host) psu = psu_conf.psu(Host, interface_conf.model) print(psu) print("-") try: psu.open() version = psu.version() print("version: %s" % version) print(JSONify.dumps(version)) print("-") status = psu.status() print("status: %s" % status) print(JSONify.dumps(status)) print("-") uptime = psu.uptime() print("uptime: %s" % uptime) print(JSONify.dumps(uptime)) print("-") touch = psu.watchdog_touch() print("touch: %s" % touch) print("-")
sn3 = sensors[2].gas_name sn4 = sensors[3].gas_name afe = AFEDatum(pt1, (sn1, a4_1), (sn2, a4_2), (sn3, a4_3), (sn4, pid)) print(afe) print("-") # -------------------------------------------------------------------------------------------------------------------- now = LocalizedDatetime.now() pmx = PMxDatum(now, 11, 22, 33) print(pmx) print("-") # -------------------------------------------------------------------------------------------------------------------- now = LocalizedDatetime.now() print(now) print("-") # -------------------------------------------------------------------------------------------------------------------- sample = Sample(tag, now, ('afe', afe), ('pmx', pmx)) print(sample) print("-") jstr = JSONify.dumps(sample) print(jstr) print("-")
for line in reader.lines: if chart.closed: break if line is None: chart.pause() continue datum = PathDict.construct_from_jstr(line) if datum is None: break if cmd.echo: print(JSONify.dumps(datum.node())) sys.stdout.flush() chart.plot(datum) # ---------------------------------------------------------------------------------------------------------------- # end... except KeyboardInterrupt: if cmd.verbose: print("single_chart: KeyboardInterrupt", file=sys.stderr) except Exception as ex: print(JSONify.dumps(ExceptionReport.construct(ex)), file=sys.stderr)
print("topic_list: %s" % cmd, file=sys.stderr) # ---------------------------------------------------------------------------------------------------------------- # resources... # APIAuth... api_auth = APIAuth.load(Host) if api_auth is None: print("topic_list: APIAuth not available.", file=sys.stderr) exit(1) if cmd.verbose: print("topic_list: %s" % api_auth, file=sys.stderr) sys.stderr.flush() # manager... manager = TopicManager(HTTPClient(), api_auth.api_key) # ---------------------------------------------------------------------------------------------------------------- # run... topics = manager.find_for_org(api_auth.org_id, cmd.partial_path, cmd.schema_id) for topic in topics: print(JSONify.dumps(topic)) if cmd.verbose: print("topic_list: total: %d" % len(topics), file=sys.stderr)
# ---------------------------------------------------------------------------------------------------------------- # resources... # ChromaConf... conf = DomainConf.load(Host) # ---------------------------------------------------------------------------------------------------------------- # run... if cmd.set(): if conf is None and not cmd.is_complete(): print( "domain_conf: no configuration is stored - you must therefore set all fields.", file=sys.stderr) cmd.print_help(sys.stderr) exit(2) topic_path = conf.topic_path if cmd.topic_path is None else cmd.topic_path document_node = conf.document_node if cmd.document_node is None else cmd.document_node conf = DomainConf(topic_path, document_node) conf.save(Host) if cmd.delete: conf.delete(Host) conf = None if conf: print(JSONify.dumps(conf, indent=cmd.indent))
print(request_jdict) print("-") request = MonitorRequest.construct_from_jdict(request_jdict) print(request) print("=") error = MonitorError(MonitorError.CODE_UNKNOWN_CMD, "hello") print(error) print("-") error_jdict = error.as_json() print(error_jdict) print("-") error_jstr = JSONify.dumps(error_jdict) print(error_jstr) print("=") response = MonitorResponse("bye", error) print(error) print("-") response_jdict = response.as_json() print(response_jdict) print("-") response_jstr = JSONify.dumps(response_jdict) print(response_jstr) print("=")
from scs_host.sys.host import Host from scs_philips_hue.cmd.cmd_osio_api_auth import CmdOSIOAPIAuth # -------------------------------------------------------------------------------------------------------------------- if __name__ == '__main__': # ---------------------------------------------------------------------------------------------------------------- # cmd... cmd = CmdOSIOAPIAuth() if cmd.verbose: print("osio_api_auth: %s" % cmd, file=sys.stderr) sys.stderr.flush() # ---------------------------------------------------------------------------------------------------------------- # run... if cmd.set(): auth = APIAuth(cmd.org_id, cmd.api_key) auth.save(Host) else: # find self... auth = APIAuth.load(Host) print(JSONify.dumps(auth))
cnc = round(Gas.concentration(cmd.gas, density, t, p), 1) target = PathDict() # copy... for path in paths: if path == concentration_path: continue target.append(path, datum.node(path)) if path == cmd.density_path: target.append(concentration_path, cnc) # report... print(JSONify.dumps(target)) sys.stdout.flush() processed_count += 1 # ---------------------------------------------------------------------------------------------------------------- # end... except KeyboardInterrupt: if cmd.verbose: print("sample_concentration: KeyboardInterrupt", file=sys.stderr) finally: if cmd.verbose: print("sample_concentration: documents: %d processed: %d" % (document_count, processed_count),
pt1 = Pt1000Datum(0.234567, 12.3) print(pt1) print("-") a4_1 = A4Datum(0.123456, 0.654321) print(a4_1) a4_2 = A4Datum(1.234567, 6.543210) print(a4_2) a4_3 = A4Datum(2.345678, 5.432101) print(a4_3) pid = PIDDatum(0.123456, 23) print(pid) print("-") sn1 = sensors[0].gas_name sn2 = sensors[1].gas_name sn3 = sensors[2].gas_name sn4 = sensors[3].gas_name afe = AFEDatum(pt1, (sn1, a4_1), (sn2, a4_2), (sn3, a4_3), (sn4, pid)) print(afe) print("-") jstr = JSONify.dumps(afe) print(jstr) print("-")
print(path2) print("-") path3 = "val.opc_n2.bin1.1" print(path3) print("-") target.copy(datum, path1) print(target) print("-") source = "val.opc_n2.extra" print(source) print("-") target.append("val.opc_n2.extra", "hello") print(target) print("-") jstr = JSONify.dumps(target.node()) print(jstr) print("-") jdict = json.loads(jstr) print(jdict) print("-") target = PathDict(jdict) print(target) print("-")
try: I2C.open(Host.I2C_SENSORS) monitor = OPCMonitor(OPCN2(), 5) print("main: %s" % monitor) proc = monitor.start() timer = IntervalTimer(20) while timer.true(): datum = monitor.sample() print("main: %s" % datum) print(JSONify.dumps(datum)) print("main: -") sys.stdout.flush() # if datum is not None: # proc.terminate() if not proc.is_alive(): break except KeyboardInterrupt: pass finally: if monitor:
datum = PathDict.construct_from_jstr(line) if datum is None: continue if cmd.ignore and not datum.has_path(cmd.path): continue try: node = datum.node(cmd.path) except KeyError as ex: print("node: KeyError: %s" % ex, file=sys.stderr) exit(1) document = JSONify.dumps(node) if cmd.sequence: try: for item in node: print(JSONify.dumps(item)) except TypeError: print(document) else: if cmd.array: if first: print(document, end='') first = False else:
print("datetime: %s" % record.datetime()) print("-") print("parameter: %s" % record.parameter()) print("-") print("unit: %s" % record.unit()) print("-") print("qc: %s" % record.qc()) print("-") print("method: %s" % record.method()) print("-") print("mpc: %s" % record.mpc()) print("=") jstr2 = JSONify.dumps(record) print(jstr2) print("-") print("jstr1:%d jstr2:%d" % (len(jstr1.strip()), len(jstr2.strip()))) equality = jstr1.strip() == jstr2.strip() print("jstr1 == jstr2: %s" % equality) # for i in range(len(jstr1)): # print("%3d: %s %s" % (i, jstr1[i], jstr2[i]))
import json from scs_core.data.json import JSONify from scs_core.sys.disk_volume import ReportedDiskVolume from scs_host.sys.host import Host # -------------------------------------------------------------------------------------------------------------------- mounted_on = '/srv/SCS_logging' print(mounted_on) volume = Host.disk_volume(mounted_on) print(volume) print(JSONify.dumps(volume)) print("-") mounted_on = '/' print(mounted_on) volume = Host.disk_volume(mounted_on) print(volume) print(JSONify.dumps(volume)) usage = Host.disk_usage(mounted_on) print(usage) print("-") jstr = JSONify.dumps(volume)
* BeagleBone: hexdump -e '8/1 \"%c\"' /sys/bus/i2c/devices/0-0050/eeprom -s 16 -n 12 The host_id utility should be made available to the scs_dev/control_receiver in order that the host serial number can be verified by a remote management system. SYNOPSIS host_id.py EXAMPLES ./host_id.py DOCUMENT EXAMPLE "0000000040d4d158" BUGS On Raspberry Pi, the host ID appears to be derived from the MAC address of the active interface, and is therefore unreliable on multi-homed hosts. """ from scs_core.data.json import JSONify from scs_host.sys.host import Host # -------------------------------------------------------------------------------------------------------------------- if __name__ == '__main__': serial_number = Host.serial_number() print(JSONify.dumps(serial_number))
""" Created on 27 Sep 2016 @author: Bruno Beloff ([email protected]) """ from scs_core.data.json import JSONify from scs_core.gas.pid_calib import PIDCalib # -------------------------------------------------------------------------------------------------------------------- serial_number = "143456789" sensor_type = "PIDNH" pidELC = 275 pidSENS = 0.321 # -------------------------------------------------------------------------------------------------------------------- calib = PIDCalib(serial_number, sensor_type, pidELC, pidSENS) print(calib) print("-") jstr = JSONify.dumps(calib) print(jstr) print("-")
# update Device... updated = ProjectSource.update(device, cmd.lat, cmd.lng, cmd.postcode, description, tags) device_manager.update(api_auth.org_id, device.client_id, updated) # find updated device... device = device_manager.find(api_auth.org_id, device.client_id) else: # create Device... device = ProjectSource.create(system_id, api_auth, cmd.lat, cmd.lng, cmd.postcode, description, tags) device = device_manager.create(cmd.user_id, device) # create ClientAuth... client_auth = ClientAuth(cmd.user_id, device.client_id, device.password) client_auth.save(Host) else: # find ClientAuth... client_auth = ClientAuth.load(Host) if cmd.verbose: print("osio_client_auth: %s" % client_auth, file=sys.stderr) print(JSONify.dumps(device))
#!/usr/bin/env python3 """ Created on 28 Oct 2017 @author: Bruno Beloff ([email protected]) """ import json from scs_core.data.json import JSONify from scs_philips_hue.data.light.sw_update import SWUpdate # -------------------------------------------------------------------------------------------------------------------- jstr = '{"state": "noupdates", "lastinstall": null}' print(jstr) print("-") jdict = json.loads(jstr) print(jdict) update = SWUpdate.construct_from_jdict(jdict) print(update) print("-") print(JSONify.dumps(update.as_json()))
for parameter in Parameter.instances(): unit = parameter.unit() if unit is None: print(parameter) print(unit) print("-") print("=") print("find...") code = 999 parameter = Parameter.instance(code) print("iso:%s parameter:%s" % (code, parameter)) print("-") code = 88374 parameter = Parameter.instance(code) print("iso:%s parameter:%s" % (code, parameter)) print("unit:%s" % parameter.unit()) jdict = parameter.as_json() print(JSONify.dumps(parameter)) print("-") remade = Parameter.construct_from_jdict(jdict) print(remade) equality = remade == parameter print("remade == parameter: %s" % equality) print("-")
# ---------------------------------------------------------------------------------------------------------------- # run... if cmd.set(): if org: name = org.name if cmd.name is None else cmd.name website = org.website if cmd.website is None else cmd.website description = org.description if cmd.description is None else cmd.description email = org.email if cmd.email is None else cmd.email # update Organisation... updated = Organisation(None, name, website, description, email) manager.update(org.id, updated) else: if not cmd.is_complete(): print( "organisation: The organisation does not exist. You must therefore set all fields:", file=sys.stderr) cmd.print_help(sys.stderr) exit(1) # create Organisation... org = Organisation(None, cmd.name, cmd.website, cmd.description, cmd.email) manager.create(org) org = manager.find(org.id) print(JSONify.dumps(org))
from scs_core.data.json import JSONify # -------------------------------------------------------------------------------------------------------------------- print("list...") for qualifier in Qualifier.instances(): print(qualifier) print("-") print("find...") code = None qualifier = Qualifier.instance(code) print("code:%s qualifier:%s" % (code, qualifier)) print("-") code = "BL" qualifier = Qualifier.instance(code) print("code:%s qualifier:%s" % (code, qualifier)) jdict = qualifier.as_json() print(JSONify.dumps(qualifier)) print("-") remade = Qualifier.construct_from_jdict(jdict) print(remade) equality = remade == qualifier print("remade == qualifier: %s" % equality) print("-")
# run... prev_time = None for line in sys.stdin: if cmd.verbose: print(line, file=sys.stderr) sample_datum = PathDict.construct_from_jstr(line) if sample_datum is None: break time = LocalizedDatetime.construct_from_iso8601( sample_datum.node(cmd.path)) interval = Interval.construct(prev_time, time, cmd.precision) print(JSONify.dumps(interval)) prev_time = time # ---------------------------------------------------------------------------------------------------------------- # end... except KeyboardInterrupt: if cmd.verbose: print("sample_interval: KeyboardInterrupt", file=sys.stderr) except Exception as ex: print(JSONify.dumps(ExceptionReport.construct(ex)), file=sys.stderr)
# manager... manager = UserManager(bridge.ip_address, credentials.username) # ------------------------------------------------------------------------------------------------------------ # run... users = manager.find_all() if cmd.delete: for user in users: if user.description.user == cmd.delete: response = manager.delete(application_key, user.username) if cmd.verbose: print("user: %s" % response, file=sys.stderr) sys.stderr.flush() else: for user in users: print(JSONify.dumps(user)) # ---------------------------------------------------------------------------------------------------------------- # end... except (ConnectionError, HTTPException) as ex: print("user: %s: %s" % (ex.__class__.__name__, ex), file=sys.stderr) except KeyboardInterrupt: if cmd.verbose: print("user: KeyboardInterrupt", file=sys.stderr)
if not cmd.is_valid(): cmd.print_help(sys.stderr) exit(2) if cmd.verbose: print("node: %s" % cmd, file=sys.stderr) sys.stderr.flush() try: # ------------------------------------------------------------------------------------------------------------ # run... for line in sys.stdin: datum = PathDict.construct_from_jstr(line) if cmd.ignore and not datum.has_path(cmd.path): continue node = datum.node(cmd.path) print(JSONify.dumps(node)) sys.stdout.flush() # ---------------------------------------------------------------------------------------------------------------- # end... except KeyboardInterrupt: if cmd.verbose: print("node: KeyboardInterrupt", file=sys.stderr)
print("-") light = manager.find(index) print(light) print("-") while True: state = LightState(bri=5) print(state) response = manager.set_state(index, state) print(response) print(JSONify.dumps(response.as_json())) print("-") time.sleep(1) state = LightState(bri=254) print(state) response = manager.set_state(index, state) print(response) print(JSONify.dumps(response.as_json())) print("=")
sampler = SampleRegression(cmd.path, cmd.tally) if cmd.verbose: print(sampler, file=sys.stderr) sys.stderr.flush() # ------------------------------------------------------------------------------------------------------------ # run... for line in sys.stdin: datum = PathDict.construct_from_jstr(line) if datum is None: break average = sampler.datum(datum) if average is not None: print(JSONify.dumps(average)) sys.stdout.flush() # ---------------------------------------------------------------------------------------------------------------- # end... except KeyboardInterrupt: if cmd.verbose: print("sample_regression: KeyboardInterrupt", file=sys.stderr) except Exception as ex: print(JSONify.dumps(ExceptionReport.construct(ex)), file=sys.stderr)
print(api_auth) # ClientAuth... client_auth = ClientAuth.load(Host) if client_auth is None: print("ClientAuth not available.", file=sys.stderr) exit(1) print(client_auth) # manager... manager = DeviceManager(api_auth.api_key) print(manager) # -------------------------------------------------------------------------------------------------------------------- # run... device = manager.find(api_auth.org_id, client_auth.client_id) print(device) print("-") try: manager.update(api_auth.org_id, client_auth.client_id, device) except ClientException as exc: print(JSONify.dumps(exc))
print("ndir_version: NDIRConf not available.", file=sys.stderr) exit(1) # NDIR... ndir = ndir_conf.ndir(interface, Host) if cmd.verbose: print("ndir_version: %s" % ndir, file=sys.stderr) sys.stderr.flush() # ------------------------------------------------------------------------------------------------------------ # run... ndir.power_on() version = ndir.version() print(JSONify.dumps(version)) # ---------------------------------------------------------------------------------------------------------------- # end... except NDIRException as ex: print(JSONify.dumps(ex), file=sys.stderr) exit(1) except KeyboardInterrupt: print("") finally: I2C.Sensors.close()
#!/usr/bin/env python3 """ Created on 4 Nov 2016 @author: Bruno Beloff ([email protected]) """ from scs_core.data.json import JSONify from scs_host.sys.hostname import Hostname # -------------------------------------------------------------------------------------------------------------------- hostname = Hostname.find() print(hostname) print("-") print(JSONify.dumps(hostname)) print("=")
try: # get... if cmd.topic: bylines = manager.find_bylines_for_topic(cmd.topic) else: bylines = manager.find_bylines_for_device(cmd.device) # process... for byline in bylines: if cmd.latest: if latest is None or latest.rec < byline.rec: latest = byline else: print(JSONify.dumps(byline)) sys.stdout.flush() if cmd.latest and latest is not None: print(JSONify.dumps(latest)) except HTTPException as ex: print("aws_byline: %s" % ex, file=sys.stderr) exit(1) # ---------------------------------------------------------------------------------------------------------------- # end... except KeyboardInterrupt: if cmd.verbose: print("aws_byline: KeyboardInterrupt", file=sys.stderr)