Пример #1
0
    def conduct(self):
        if self.verbose:
            print("EEPROM...", file=sys.stderr)

        # validate...
        if not path.isfile(Host.eep_image()):
            print("error: eeprom image not found", file=sys.stderr)
            exit(1)

        try:
            # resources...
            Host.enable_eeprom_access()

            I2C.open(Host.I2C_EEPROM)

            eeprom = CAT24C32()

            # test...
            file_image = EEPROMImage.construct_from_file(
                Host.eep_image(), CAT24C32.SIZE)
            eeprom.write(file_image)

            # test criterion...
            return eeprom.image == file_image

        finally:
            I2C.close()
Пример #2
0
    def conduct(self):
        if self.verbose:
            print("OPC...", file=sys.stderr)

        opc = None

        try:
            I2C.open(Host.I2C_SENSORS)

            # resources...
            opc = OPCN2(Host.opc_spi_bus(), Host.opc_spi_device())

            opc.power_on()
            opc.operations_on()

            # test...
            self.datum = opc.firmware()

            if self.verbose:
                print(self.datum, file=sys.stderr)

            # test criterion...
            return len(self.datum) > 0 and self.datum.startswith('OPC')

        finally:
            if opc:
                opc.operations_off()
                opc.power_off()

            I2C.close()
 def init(cls):
     """
     Establish the /run/lock/southcoastscience root.
     Should be invoked on class load.
     """
     try:
         os.mkdir(Host.lock_dir())
         os.chmod(Host.lock_dir(), 0o777)      # TODO: why does the mod not work on mkdir?
     except FileExistsError:
         pass
Пример #4
0
    def conduct(self):
        if self.verbose:
            print("GPS...", file=sys.stderr)

        gps = None

        try:
            I2C.open(Host.I2C_SENSORS)

            # GPS...
            gps = PAM7Q(Host.gps_device())

            gps.power_on()
            gps.open()

            # test...
            self.datum = gps.report(GPRMC)

            if self.verbose:
                print(self.datum, file=sys.stderr)

            # criterion...
            return self.datum is not None

        finally:
            if gps:
                gps.close()
                gps.power_off()

            I2C.close()
Пример #5
0
    def update(self):
        # time...
        display_datetime = self.__show_time and Host.time_is_synchronized()
        datetime = LocalizedDatetime.now() if display_datetime else None

        # network...
        nmcli = NMCLi.find()
        homes = {} if nmcli is None else nmcli.connections

        # message...
        message = self.__status_message

        # PSU...
        if self.__psu_report_filename:
            psu_report = self.__psu_report_class.load(
                self.__psu_report_filename)
            batt_percent = None if psu_report is None else psu_report.batt_percent
        else:
            batt_percent = None

        # MQTT queue...
        if self.__queue_report_filename:
            queue_report = QueueReport.load(self.__queue_report_filename)
            queue_message = self.__QUEUE_STATE[queue_report.queue_state()]

            message += ':' + queue_message

        # GPS quality...
        if self.__gps_report_filename:
            gps_report = GPSDatum.load(self.__gps_report_filename)
            gps_quality = gps_report.quality

            message += '  GPS:' + str(gps_quality)

        return self.render(datetime, BattDisplay(batt_percent), homes, message)
Пример #6
0
#!/usr/bin/env python3
"""
Created on 30 Apr 2021

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

from scs_host.sys.host import Host

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

connection = Host.modem_conn()
print(connection)
#!/usr/bin/env python3
"""
Created on 29 Apr 2018

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

from scs_host.sys.host import Host

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

home_path = Host.home_path()
print("home_path: %s" % home_path)

du = Host.disk_usage(home_path)
print("du: %s" % du)
#!/usr/bin/env python3

"""
Created on 30 Apr 2021

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

from scs_host.sys.host import Host


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

modem = Host.modem()
print(modem)
#!/usr/bin/env python3
"""
Created on 2 Mar 2018

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

from scs_host.sys.host import Host

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

home_path = Host.home_path()
print("home_path: %s" % home_path)

print("-")

try:
    lock_dir = Host.lock_dir()
    print("lock_dir: %s" % lock_dir)
except NotImplementedError:
    print("lock_dir: None")

try:
    tmp_dir = Host.tmp_dir()
    print("tmp_dir: %s" % tmp_dir)
except NotImplementedError:
    print("tmp_dir: None")

try:
    command_path = Host.command_path()
    print("command_path: %s" % command_path)
Пример #10
0
#!/usr/bin/env python3
"""
Created on 2 Mar 2018

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

from scs_host.sys.host import Host

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

home_dir = Host.home_dir()
print("home_dir: %s" % home_dir)

print("-")

try:
    lock_dir = Host.lock_dir()
    print("lock_dir: %s" % lock_dir)
except NotImplementedError:
    print("lock_dir: None")

try:
    tmp_dir = Host.tmp_dir()
    print("tmp_dir: %s" % tmp_dir)
except NotImplementedError:
    print("tmp_dir: None")

try:
    command_dir = Host.command_dir()
    print("command_dir: %s" % command_dir)
Пример #11
0
#!/usr/bin/env python3
"""
Created on 10 Aug 2017

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

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)
Пример #12
0
import sys

from scs_core.sys.eeprom_image import EEPROMImage

from scs_dfe.board.cat24c32 import CAT24C32

from scs_host.bus.i2c import I2C
from scs_host.sys.host import Host

from scs_mfr.cmd.cmd_eeprom_write import CmdEEPROMWrite


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

Host.enable_eeprom_access()


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

if __name__ == '__main__':

    try:
        I2C.open(Host.I2C_EEPROM)


        # ------------------------------------------------------------------------------------------------------------
        # cmd...

        cmd = CmdEEPROMWrite()
Пример #13
0
    # Interface...
    interface_conf = InterfaceConf.load(Host)

    if interface_conf is None:
        print("InterfaceConf not available.")
        exit(1)

    interface = interface_conf.interface()
    print(interface)

    # NDIR...
    conf = NDIRConf("t1f1", 5)
    print("conf: %s" % conf)

    ndir = SPINDIRt1f1(interface, Host.ndir_spi_bus(), Host.ndir_spi_device())
    print("ndir: %s" % ndir)
    print("-")

    ndir.power_on()

    monitor = NDIRMonitor(ndir, conf)
    print("monitor: %s" % monitor)

    firmware = monitor.firmware()
    print("firmware: %s" % firmware)
    print("-")

    monitor.start()

    for i in range(10):
Пример #14
0
        else:
            for i in range(len(bridges)):
                print("%d: %s" % ((i + 1), bridges[i]))

            index = StdIO.prompt("Bridge (1 - %d) ?: " % len(bridges))
            bridge = bridges[int(index) - 1]

        if cmd.verbose:
            print("join: %s" % bridge, file=sys.stderr)

        # manager...
        bridge_manager = BridgeManager(bridge.ip_address, None)

        # device...
        client = ClientDescription(ClientDescription.APP, Host.name())
        device = DeviceDescription(client)

        if cmd.verbose:
            print("join: %s" % device, file=sys.stderr)

        sys.stderr.flush()

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

        # join...
        response = None

        try:
            response = bridge_manager.register(device)
Пример #15
0
            print("osio_mqtt_control: Topic not available: %s" % cmd.device_topic, file=sys.stderr)
            exit(1)

        # responder...
        handler = OSIOMQTTControlHandler()
        subscriber = MQTTSubscriber(cmd.device_topic, handler.handle)

        # client...
        client = MQTTClient(subscriber)

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

        # tag...
        tag = Host.name()


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

        client.connect(ClientAuth.MQTT_HOST, client_auth.client_id, client_auth.user_id, client_auth.client_password)

        while True:
            # cmd...
            if cmd.interactive:
                line = StdIO.prompt(cmd.device_tag + ' > ')
                cmd_tokens = line.split() if len(line) > 0 else None

            else:
                cmd_tokens = cmd.cmd_tokens
Пример #16
0
#!/usr/bin/env python3
"""
Created on 2 Mar 2020

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

import sys
import time

from scs_host.sys.host import Host

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

ip = Host.ipv4_address()
print("ipv4 address: %s" % str(ip))

start_time = time.time()

for dot_decimal in Host.scan_accessible_subnets():
    print("found: %s" % dot_decimal)
    sys.stdout.flush()

elapsed_time = time.time() - start_time

print("elapsed: %0.3f" % elapsed_time)
Пример #17
0
#!/usr/bin/env python3

"""
Created on 24 Mar 2021

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

from scs_host.sys.host import Host


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

report = Host.software_update_report()
print("report: %s" % report)

 def __name_dir(cls, name):
     return os.path.join(Host.lock_dir(), name)
#!/usr/bin/env python3
"""
Created on 24 Mar 2021

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

from scs_host.sys.host import Host

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

sim = Host.sim()
print(sim)
Пример #20
0
#!/usr/bin/env python3

"""
Created on 28 Nov 2018

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

from scs_host.sys.host import Host


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

spi_location = '48030000'
spi_device = 0

bus = Host.spi_bus(spi_location, spi_device)

print("bus:%d" % bus)
Пример #21
0
        if cmd.verbose:
            print("aws_mqtt_control: %s" % auth, file=sys.stderr)

        # responder...
        handler = AWSMQTTControlHandler()
        subscriber = MQTTSubscriber(topic, handler.handle)

        # client...
        client = MQTTClient(subscriber)

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

        # tag...
        host_tag = Host.name()


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

        client.connect(auth)

        while True:
            # cmd...
            if cmd.interactive:
                line = StdIO.prompt(device_tag + ' > ')
                cmd_tokens = line.split() if len(line) > 0 else None

            else:
                cmd_tokens = cmd.cmd_tokens
Пример #22
0
from scs_core.position.gpgsv import GPGSV
from scs_core.position.gprmc import GPRMC
from scs_core.position.gpvtg import GPVTG

from scs_core.position.gps_location import GPSLocation

from scs_dfe.gps.pam7q import PAM7Q

from scs_host.bus.i2c import I2C
from scs_host.sys.host import Host

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

I2C.open(Host.I2C_SENSORS)

gps = PAM7Q(Host.gps_device())
print(gps)
print("-")

try:
    # ----------------------------------------------------------------------------------------------------------------

    print("power up...")
    gps.power_on()

    print("open...")
    gps.open()
    print(gps)
    print("=")

    # ----------------------------------------------------------------------------------------------------------------
Пример #23
0
Created on 16 Apr 2017

@author: Bruno Beloff ([email protected])

WARNING: for Raspberry Pi, the host ID appears to be derrived from the MAC address of the active interface.

Act III of III: Deployment workflow:

  > 1: ./host_id.py
    2: ./system_id.py -d VENDOR_ID -m MODEL_ID -n MODEL_NAME -c CONFIG -s SYSTEM_SERIAL_NUMBER -v
    3: ./osio_api_auth.py -s ORG_ID API_KEY
(   4: ./osio_host_organisation.py -o ORG_ID -n NAME -w WEB -d DESCRIPTION -e EMAIL -v )
    5: ./osio_host_client.py -u USER_ID -l LAT LNG POSTCODE
    6: ./osio_host_project.py -s GROUP LOCATION_ID
    7: ./timezone.py -v -s ZONE

command line example:
./host_id.py
"""

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))
Пример #24
0
    if cmd.ignore_eeprom:
        reporter.report_ignore("EEPROM")

    else:
        try:
            test = EEPROMTest(cmd.verbose)

            test_ok = test.conduct()
            reporter.report_test("EEPROM", test_ok)

        except Exception as ex:
            reporter.report_exception("EEPROM", ex)

    # ----------------------------------------------------------------------------------------------------------------
    # result...

    if cmd.verbose:
        print(reporter, file=sys.stderr)
        print(reporter.result, file=sys.stderr)
        print("-", file=sys.stderr)

    # ----------------------------------------------------------------------------------------------------------------
    # report...

    recorded = LocalizedDatetime.now()
    datum = DFETestDatum(system_id.message_tag(), recorded,
                         Host.serial_number(), cmd.dfe_serial_number,
                         reporter.subjects, afe_datum, reporter.result)

    print(JSONify.dumps(datum))
Пример #25
0
#!/usr/bin/env python3
"""
Created on 29 Apr 2018

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

from scs_host.sys.host import Host

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

home_dir = Host.home_path()
print("home_dir: %s" % home_dir)

du = Host.disk_usage(home_dir)
print("du: %s" % du)
#!/usr/bin/env python3
"""
Created on 2 May 2021

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

from scs_host.sys.host import Host

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

networks = Host.networks()
print(networks)
Пример #27
0
    if api_auth is None:
        print("osio_client_auth: APIAuth not available.", file=sys.stderr)
        exit(1)

    if cmd.verbose:
        print("osio_client_auth: %s" % api_auth, file=sys.stderr)

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

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

    # check for existing registration...
    device = device_manager.find_for_name(api_auth.org_id, Host.name())

    # check for existing ClientAuth...
    client_auth = ClientAuth.load(Host)


    # ----------------------------------------------------------------------------------------------------------------
    # remove non-matching record...

    if device and client_auth:
        if device.client_id != client_auth.client_id:
            ClientAuth.delete(Host)
            client_auth = None


    # ----------------------------------------------------------------------------------------------------------------
Пример #28
0
#!/usr/bin/env python3
"""
Created on 15 Apr 2017

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

from scs_host.sys.host import Host

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

Host.shutdown()
from scs_core.data.json import JSONify

from scs_core.gas.ndir.ndir_version import NDIRVersion

from scs_host.bus.i2c import I2C
from scs_host.sys.host import Host

from scs_ndir.gas.ndir.spi_ndir_x1.spi_ndir_x1 import SPINDIRx1

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

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)
from scs_core.osio.client.client_auth import ClientAuth
from scs_core.osio.config.project_source import ProjectSource
from scs_core.osio.manager.device_manager import DeviceManager
from scs_core.osio.manager.user_manager import UserManager

from scs_core.sys.system_id import SystemID

from scs_host.sys.host import Host

from scs_philips_hue.cmd.cmd_osio_client_auth import CmdOSIOClientAuth

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

if __name__ == '__main__':

    system_id = SystemID('scs', 'phi', 'Hue Interface', 'RPi', Host.name())

    description = 'South Coast Science - Philips Hue Bridge'
    tags = ['scs', 'philips-hue']

    # ----------------------------------------------------------------------------------------------------------------
    # cmd...

    cmd = CmdOSIOClientAuth()

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

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