示例#1
0
        print("APIAuth not available.", file=sys.stderr)
        exit(1)

    if cmd.verbose:
        print(api_auth, file=sys.stderr)
        sys.stderr.flush()

    # manager...
    manager = DeviceManager(HTTPClient(), api_auth.api_key)

    # check for existing registration...
    device = manager.find(api_auth.org_id, cmd.client_id)

    if device is None:
        print("Device not found.", file=sys.stderr)
        exit(1)

    # ----------------------------------------------------------------------------------------------------------------
    # run...

    if cmd.set():
        # update Device...
        updated = ProjectSource.update(device, cmd.lat, cmd.lng, cmd.postcode,
                                       cmd.description)
        manager.update(api_auth.org_id, device.client_id, updated)

        # find updated device...
        device = manager.find(api_auth.org_id, device.client_id)

    print(JSONify.dumps(device))
示例#2
0
    conf = TimezoneConf.load(Host)

    # ----------------------------------------------------------------------------------------------------------------
    # run...

    now = LocalizedDatetime.now()

    if cmd.list:
        for zone in Timezone.zones():
            print(zone, file=sys.stderr)
        exit(0)

    elif cmd.set():
        if not Timezone.is_valid(cmd.zone):
            print("zone is not valid: %s" % cmd.zone, file=sys.stderr)
            exit(1)

        if cmd.zone != conf.name:
            conf = TimezoneConf(now, cmd.zone)
            conf.save(Host)

    elif cmd.link:
        if not conf.uses_system_name() or conf.set_on is None:
            conf = TimezoneConf(now, None)
            conf.save(Host)

    print(JSONify.dumps(conf))

    if cmd.verbose:
        print(JSONify.dumps(conf.timezone()), file=sys.stderr)
示例#3
0
        if cmd.verbose:
            print("ndir_measure: %s" % ndir, file=sys.stderr)
            sys.stderr.flush()


        # ------------------------------------------------------------------------------------------------------------
        # run...

        ndir.power_on()

        runner = TimedRunner(cmd.interval, cmd.samples)
        sampler = NDIRVoltageMeasure(runner, ndir)

        for sample in sampler.samples():
            print(JSONify.dumps(sample))
            sys.stdout.flush()


    # ----------------------------------------------------------------------------------------------------------------
    # end...

    except NDIRException as ex:
        print(JSONify.dumps(ex), file=sys.stderr)
        exit(1)

    except KeyboardInterrupt:
        print("")

    finally:
        I2C.Sensors.close()
示例#4
0
    if cmd.verbose:
        print("user: %s" % client_auth, file=sys.stderr)
        sys.stderr.flush()

    # manager...
    manager = UserManager(HTTPClient(), api_auth.api_key)

    # ----------------------------------------------------------------------------------------------------------------
    # run...

    # find self...
    user = manager.find(client_auth.user_id)

    if user is None:
        print("user: User not found.", file=sys.stderr)
        exit(1)

    if cmd.set():
        name = user.name if cmd.name is None else cmd.name
        email = user.email if cmd.email is None else cmd.email
        password = user.password if cmd.password is None else cmd.password

        updated = User(None, name, email, password, None)

        manager.update(user.id, updated)

        user = manager.find(client_auth.user_id)

    print(JSONify.dumps(user))
示例#5
0
            document_count += 1

            if cmd.path not in datum.paths():
                continue

            try:
                value = float(datum.node(cmd.path))
            except (TypeError, ValueError):
                continue

            if min_datum is None or value < min_datum.node(cmd.path):
                min_datum = datum

            processed_count += 1

        if min_datum:
            print(JSONify.dumps(min_datum.node()))

    # ----------------------------------------------------------------------------------------------------------------
    # end...

    except KeyboardInterrupt:
        if cmd.verbose:
            print("sample_min: KeyboardInterrupt", file=sys.stderr)

    finally:
        if cmd.verbose:
            print("sample_min: documents: %d processed: %d" %
                  (document_count, processed_count),
                  file=sys.stderr)
示例#6
0
    'eth0: connected to Wired connection 1',
    '	"TP-LINK USB 10/100/1000 LAN"',
    '    ethernet (r8152), 98:DE:D0:04:9B:CC, hw, mtu 1500',
    '    ip4 default',
    '    inet4 192.168.1.88/24',
    '    inet6 fe80::131d:325a:f7bd:e3e/64',
    '',
    'wlan0: connected to TP-Link_0F04',
    '    "Broadcom "',
    '    wifi (brcmfmac), B8:27:EB:56:50:8F, hw, mtu 1500',
    '    inet4 192.168.1.122/24',
    '    inet6 fe80::212a:9d31:4b3e:59c/64',
    '',
    'lo: unmanaged',
    '    loopback (unknown), 00:00:00:00:00:00, sw, mtu 65536']

conns = NMCLi.parse(response)
print(conns)
print("-")

nmcli = NMCLi(conns)
print(nmcli)
print("-")

print(JSONify.dumps(nmcli))
print("-")

print("find...")
nmcli = NMCLi.find()
print(nmcli)
示例#7
0
        print("schedule: %s" % cmd, file=sys.stderr)
        sys.stderr.flush()

    if not cmd.is_valid():
        cmd.print_help(sys.stderr)
        exit(2)

    # ----------------------------------------------------------------------------------------------------------------
    # resources...

    schedule = Schedule.load(Host)

    # ----------------------------------------------------------------------------------------------------------------
    # run...

    if cmd.set():
        item = ScheduleItem(cmd.name, cmd.interval, cmd.count)

        # if not item.is_valid():
        #     print("Item is not valid: %s" % item)
        #     exit(1)

        schedule.set(item)
        schedule.save(Host)

    if cmd.delete():
        schedule.clear(cmd.name)
        schedule.save(Host)

    print(JSONify.dumps(schedule))
示例#8
0
from scs_core.data.json import JSONify


# --------------------------------------------------------------------------------------------------------------------

print("list...")
for qc in QC.instances():
    print(qc)
print("-")

print("find...")
code = 99
qc = QC.instance(code)
print("code:%s qc:%s" % (code, qc))
print("-")

code = 0
qc = QC.instance(code)
print("code:%s qc:%s" % (code, qc))

jdict = qc.as_json()
print(JSONify.dumps(qc))
print("-")

remade = QC.construct_from_jdict(jdict)
print(remade)

equality = remade == qc
print("remade == qc: %s" % equality)
print("-")
#!/usr/bin/env python3
"""
Created on 27 Oct 2017

@author: Bruno Beloff ([email protected])
"""

from scs_core.data.json import JSONify

from scs_philips_hue.client.rest_client import RESTClient

# --------------------------------------------------------------------------------------------------------------------

client = RESTClient()
print(client)

try:
    client.connect("192.168.1.10", "b8bvymOH-ceugK8gBOpjeNeL0OMhXOEBQZosfsTx")

    response = client.get("/lights")  # config    lights/1

    print(JSONify.dumps(response))

finally:
    client.close()
示例#10
0
        sampler = SampleAverage(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_average: KeyboardInterrupt", file=sys.stderr)

    except Exception as ex:
        print(JSONify.dumps(ExceptionReport.construct(ex)), file=sys.stderr)
示例#11
0
            print("ndir_status: NDIRConf not available.", file=sys.stderr)
            exit(1)

        # NDIR...
        ndir = ndir_conf.ndir(interface, Host)

        if cmd.verbose:
            print("ndir_status: %s" % ndir, file=sys.stderr)
            sys.stderr.flush()

        # ------------------------------------------------------------------------------------------------------------
        # run...

        ndir.power_on()

        status = ndir.status()
        print(JSONify.dumps(status))

    # ----------------------------------------------------------------------------------------------------------------
    # end...

    except NDIRException as ex:
        print(JSONify.dumps(ex), file=sys.stderr)
        exit(1)

    except KeyboardInterrupt:
        print("")

    finally:
        I2C.Sensors.close()
示例#12
0
                for path in datum.paths():
                    if cmd.includes(path):
                        target.append(path, datum.node(path))

            # report...
            if not target:
                continue  # skip empty outputs

            if cmd.sequence:
                for path in cmd.sub_paths:
                    node = target.node(path)

                    try:
                        for item in node:
                            print(JSONify.dumps(item))
                    except TypeError as ex:
                        print(ex)
                        print(JSONify.dumps(node))

            else:
                if cmd.array:
                    if first:
                        print(JSONify.dumps(target), end='')
                        first = False

                    else:
                        print(", %s" % JSONify.dumps(target), end='')

                else:
                    print(JSONify.dumps(target))
示例#13
0

from scs_core.data.json import JSONify
from scs_core.data.timedelta import Timedelta


# --------------------------------------------------------------------------------------------------------------------

td = Timedelta(weeks=1, days=2, hours=3, minutes=4, seconds=5, milliseconds=6, microseconds=7)
print("td: %s" % td)
print("total_seconds: %s" % td.total_seconds())

jdict = td.as_json()
print("jdict: %s" % jdict)

print("jstr: %s" % JSONify.dumps(td))
print("-")

td = Timedelta.construct_from_jdict(jdict)
print("reconstructed: %s" % td)

print("=")

td = Timedelta(weeks=1, days=2, hours=3, minutes=4, seconds=5)
print("td: %s" % td)
print("total_seconds: %s" % td.total_seconds())

jdict = td.as_json()
print("jdict: %s" % jdict)

print("jstr: %s" % JSONify.dumps(td))
示例#14
0
#!/usr/bin/env python3

"""
Created on 18 Sep 2016

@author: Bruno Beloff ([email protected])
"""

from scs_core.data.json import JSONify
from scs_core.data.localized_datetime import LocalizedDatetime

from scs_core.particulate.pmx_datum import PMxDatum


# --------------------------------------------------------------------------------------------------------------------

now = LocalizedDatetime.now()

pmx = PMxDatum(now, 11, 22, 33)
print(pmx)
print("-")

jstr = JSONify.dumps(pmx)
print(jstr)
print("-")
# --------------------------------------------------------------------------------------------------------------------

try:
    I2C.Sensors.open()

    ndir = SPINDIRx1(False, Host.ndir_spi_bus(), Host.ndir_spi_device())
    print(ndir)
    print("-")

    ndir.power_on()

    version = ndir.version()
    print("version: %s" % version)
    print("-")

    jstr = JSONify.dumps(version)
    print(jstr)
    print("-")

    jdict = json.loads(jstr)

    version = NDIRVersion.construct_from_jdict(jdict)
    print("version: %s" % version)
    print("-")

    jstr = JSONify.dumps(version)
    print(jstr)
    print("-")

except ValueError as ex:
    print("ValueError: %s" % ex)
示例#16
0
    # ----------------------------------------------------------------------------------------------------------------
    # cmd...

    cmd = CmdAFEBaseline()

    if cmd.verbose:
        print(cmd, file=sys.stderr)
        sys.stderr.flush()


    # ----------------------------------------------------------------------------------------------------------------
    # resources...

    baseline = AFEBaseline.load(Host)


    # ----------------------------------------------------------------------------------------------------------------
    # run...

    if cmd.set():
        now = LocalizedDatetime.now()

        for i, offset in cmd.offsets.items():
            if offset is not None:
                baseline.set_sensor_baseline(i, SensorBaseline(now, offset))

        baseline.save(Host)

    print(JSONify.dumps(baseline))
示例#17
0
localised = now.localize(timezone)
print("localised: %s" % localised)
print("=")
print("")
print("")

print("AQCSVDatetime without zone...")
utc_aqcsv = AQCSVDatetime(now.datetime)
print("utc_aqcsv: %s" % utc_aqcsv)
print("filename_prefix: %s" % utc_aqcsv.filename_prefix())
print("-")

print("utc_aqcsv localised: %s" % utc_aqcsv.localised())
print("-")

code = JSONify.dumps(utc_aqcsv).strip('"')
print(code)

utc_aqcsv = AQCSVDatetime.construct_from_code(code)
print("utc_aqcsv: %s" % utc_aqcsv)
print("-")

jstr = JSONify.dumps(utc_aqcsv).strip('"')
print(jstr)
print("=")
print("")
print("")

print("AQCSVDatetime with zone...")
local_aqcsv = AQCSVDatetime(localised.datetime, timezone)
print("local_aqcsv: %s" % local_aqcsv)
示例#18
0
from scs_core.data.json import JSONify

from scs_host.sys.host import Host

from scs_psu.psu.psu import PSU

# --------------------------------------------------------------------------------------------------------------------

psu = PSU(Host.psu_device())
print(psu)
print("-")

version = psu.version()
print(version)
print(JSONify.dumps(version))
print("-")

status = psu.status()
print(status)
print(JSONify.dumps(status))
print("-")

uptime = psu.uptime()
print(uptime)
print(JSONify.dumps(uptime))
print("-")

touch = psu.watchdog_touch()
print(touch)
print("-")
示例#19
0
            name = topic.name if cmd.name is None else cmd.name
            description = topic.description if cmd.description is None else cmd.description

            info = TopicInfo(
                TopicInfo.FORMAT_JSON) if topic.info is None else topic.info

            # update Topic...
            updated = Topic(None, name, description, topic.is_public, info,
                            None, None)

            manager.update(topic.path, updated)

            topic = manager.find(topic.path)

        else:
            if not cmd.is_complete():
                print(
                    "topic: All fields required for topic creation must be provided.",
                    file=sys.stderr)
                cmd.print_help(sys.stderr)
                exit(1)

            info = TopicInfo(TopicInfo.FORMAT_JSON)

            # create Topic...
            topic = Topic(cmd.path, cmd.name, cmd.description, True, info,
                          True, cmd.schema_id)
            manager.create(topic)

    print(JSONify.dumps(topic))
示例#20
0
            print(sht_datum, file=sys.stderr)

        # Pt1000 initial...
        pt1000_datum = afe.sample_temp()

        if cmd.set:
            # Pt1000 correction...
            v20 = pt1000_datum.v20(sht_datum.temp)

            pt1000_calib = Pt1000Calib(None, v20)
            pt1000_calib.save(Host)

        # calibrated...
        pt1000_calib = Pt1000Calib.load(Host)

        print(JSONify.dumps(pt1000_calib))

        if cmd.verbose:
            afe = afe_conf.afe(Host)
            pt1000_datum = afe.sample_temp()

            print(pt1000_datum, file=sys.stderr)

    # ----------------------------------------------------------------------------------------------------------------
    # end...

    except Exception as ex:
        print(JSONify.dumps(ExceptionReport.construct(ex)), file=sys.stderr)

    finally:
        I2C.close()
    # ----------------------------------------------------------------------------------------------------------------
    # resources...

    # APIAuth...
    auth = APIAuth.load(Host)

    # ----------------------------------------------------------------------------------------------------------------
    # run...

    if cmd.set():
        if auth is None and not cmd.is_complete():
            print(
                "aws_api_auth: No configuration is stored - you must therefore set all fields.",
                file=sys.stderr)
            cmd.print_help(sys.stderr)
            exit(2)

        endpoint = cmd.endpoint if cmd.endpoint else auth.endpoint
        api_key = cmd.api_key if cmd.api_key else auth.api_key

        auth = APIAuth(endpoint, api_key)
        auth.save(Host)

    if cmd.delete:
        auth.delete(Host)
        auth = None

    if auth:
        print(JSONify.dumps(auth))
示例#22
0
# --------------------------------------------------------------------------------------------------------------------

try:
    I2C.Sensors.open()

    ndir = SPINDIRx1(False, Host.ndir_spi_bus(), Host.ndir_spi_device())
    print(ndir)
    print("-")

    ndir.power_on()

    status = ndir.status()
    print("status: %s" % status)
    print("-")

    jstr = JSONify.dumps(status)
    print(jstr)
    print("-")

    ndir.reset()
    print("NDIR RESET")
    print("-")

    status = ndir.status()
    print("status: %s" % status)
    print("-")

    jstr = JSONify.dumps(status)
    print(jstr)
    print("-")
示例#23
0
print(task3)
print("-")


tasks = AirNowMappingTaskList({})
tasks.insert(task1)
print(tasks)

tasks.insert(task2)
print(tasks)

tasks.insert(task3)
print(tasks)
print("-")

jstr = JSONify.dumps(tasks)
print(jstr)
print("-")

tasks.save(Host)
tasks = AirNowMappingTaskList.load(Host)
print(tasks)
print("-")

remade = AirNowMappingTaskList.construct_from_jdict(json.loads(jstr))
print("-")
print("-")

print(tasks)
print("-")
示例#24
0
@author: Bruno Beloff ([email protected])
"""

import json

from scs_core.data.json import JSONify

from scs_philips_hue.data.client.client_description import ClientDescription
from scs_philips_hue.data.client.device_description import DeviceDescription

# --------------------------------------------------------------------------------------------------------------------

client = ClientDescription(ClientDescription.APP, 'bruno.local')
print(client)

print(JSONify.dumps(client.as_json()))

print("-")
device = DeviceDescription(client)
print(device)

print("-")
jdict = device.as_json()
print(jdict)

print("-")
jstr = JSONify.dumps(jdict)
print(jstr)

print("-")
jdict = json.loads(jstr)
示例#25
0
    if cmd.verbose:
        print("rtc: system time: %s" % now, file=sys.stderr)

    # ----------------------------------------------------------------------------------------------------------------
    # run...

    try:
        I2C.open(Host.I2C_SENSORS)

        if cmd.initialise:
            DS1338.init()

        if cmd.set:
            rtc_datetime = RTCDatetime.construct_from_localized_datetime(now)
            DS1338.set_time(rtc_datetime)

        # get current...
        rtc_datetime = DS1338.get_time()
        localized_datetime = rtc_datetime.as_localized_datetime(
            tzlocal.get_localzone())

        if cmd.verbose:
            print("rtc: datetime: %s" % localized_datetime, file=sys.stderr)
            sys.stderr.flush()

        print(JSONify.dumps(localized_datetime))

    finally:
        I2C.close()
示例#26
0
            if cmd.user_id:
                print("osio_client_auth: Device owner-id cannot be updated.", file=sys.stderr)
                exit(1)

            # update Device...
            updated = ProjectClient.update(device, cmd.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 = ProjectClient.create(Host.name(), api_auth, cmd.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(device, file=sys.stderr)

    print(JSONify.dumps(client_auth))
示例#27
0
            ah = round(AbsoluteHumidity.from_rh_t(rh, t), 1)

            target = PathDict()

            # copy...
            for path in paths:
                if path == cmd.rh_path:
                    target.append(path + '.rH', rh)
                    target.append(path + '.aH', ah)

                else:
                    target.append(path, datum.node(path))

            # report...
            print(JSONify.dumps(target.node()))
            sys.stdout.flush()

            processed_count += 1


    # ----------------------------------------------------------------------------------------------------------------
    # end...

    except KeyboardInterrupt:
        if cmd.verbose:
            print("sample_ah: KeyboardInterrupt", file=sys.stderr)

    finally:
        if cmd.verbose:
            print("sample_ah: documents: %d processed: %d" % (document_count, processed_count), file=sys.stderr)
示例#28
0
"""

import json

from scs_core.data.json import JSONify

from scs_psu.psu.oslo_v1.psu_status import PSUStatus

# --------------------------------------------------------------------------------------------------------------------

jstr = '{"rst": "FT", "standby": false, "chgr": "TFTF", "batt-flt": false, "host-3v3": 3.3, "pwr-in": 13.0, ' \
       '"prot-batt": 0.0}'
print(jstr)
print("-")

jdict = json.loads(jstr)
print(jdict)
print("-")

status = PSUStatus.construct_from_jdict(jdict)
print(status)
print("-")

jdict = status.as_json()
print(jdict)
print("-")

jstr = JSONify.dumps(jdict)
print(jstr)
print("-")
示例#29
0
    # check for existing document...
    system_id = SystemID.load(Host)


    # ----------------------------------------------------------------------------------------------------------------
    # run...

    if cmd.set():
        if system_id is None and not cmd.is_complete():
            print("system_id: No ID is present. You must therefore set all fields:", file=sys.stderr)
            cmd.print_help(sys.stderr)
            exit(1)

        vendor_id = system_id.vendor_id if cmd.vendor_id is None else cmd.vendor_id
        model_id = system_id.model_id if cmd.model_id is None else cmd.model_id
        model_name = system_id.model_name if cmd.model_name is None else cmd.model_name
        configuration = system_id.configuration if cmd.configuration is None else cmd.configuration
        serial_number = system_id.system_serial_number if cmd.serial_number is None else cmd.serial_number

        system_id = SystemID(vendor_id, model_id, model_name, configuration, serial_number)
        system_id.save(Host)

    if system_id:
        print(JSONify.dumps(system_id))

    if cmd.verbose:
        print("-", file=sys.stderr)
        print("box:   %s" % system_id.box_label(), file=sys.stderr)
        print("topic: %s" % system_id.topic_label(), file=sys.stderr)
        print("tag:   %s" % system_id.message_tag(), file=sys.stderr)
# --------------------------------------------------------------------------------------------------------------------

try:
    I2C.Sensors.open()

    ndir = SPINDIRx1(False, Host.ndir_spi_bus(), Host.ndir_spi_device())
    print(ndir, file=sys.stderr)
    print("-", file=sys.stderr)

    ndir.power_on()

    start_time = time.time()
    timer = IntervalTimer(3.0)

    for _ in timer.range(4000):
        ndir.get_sample_mode(True)
        rec = LocalizedDatetime.now().utc()
        co2_datum = ndir.sample()

        sample = GasesSample('', rec, co2_datum, None, None)

        print(JSONify.dumps(sample))
        sys.stdout.flush()

except KeyboardInterrupt:
    print("")

finally:
    I2C.Sensors.close()