예제 #1
0
def start_app(app_config: SystemConfig, device: BaseDevice):
    """ Start application

        app_config: system skaben config object
        device: end device for user interactions
        event_context: device events controller

    """

    app_config.update({'device': device
                       })  # update config for easy access to device instance
    router = Router(app_config)  # initialize router for internal events
    mqtt_client = None
    standalone = app_config.get("standalone")

    try:
        if not standalone:
            mqtt_client = MQTTClient(
                app_config)  # initialize MQTT client for talking with server
            mqtt_client.start()
        router.start()
        device.run()
    except KeyboardInterrupt:
        raise SystemExit('Catch keyboard interrupt. Exiting')
    except Exception:
        raise
    finally:
        router.join(.5)
        if mqtt_client:
            mqtt_client.join(.5)
예제 #2
0
 def __init__(self, config: SystemConfig):
     super().__init__()
     self.daemon = True
     self.running = False
     self.queue_int = config.get("q_int")
     self.queue_ext = config.get("q_ext")
     self.queue_log = config.get("q_log")
     self.logger = config.logger_instance
     # passing to contexts
     self.config = config
예제 #3
0
 def __init__(self, system_config: SystemConfig, device_config: LockConfig):
     super().__init__(system_config, device_config)
     self.port = None
     self.keypad_thread = None
     self.keypad_data_queue = Queue()
     self.timers = {}
     # set config values (without gorillas, bananas and jungles)
     self.pin = system_config.get('pin')
     self.alert = system_config.get('alert')
     self.preferred_serial = system_config.get('comport', '/dev/ttyS1')
     # set sound
     self.snd = self._snd_init(system_config.get('sound_dir'))
     self.logger.debug(f'{self.config.get("acl")}')
예제 #4
0
 def __init__(self, app_config: SystemConfig, device_config: DeviceConfig):
     if not isinstance(app_config, SystemConfig):
         raise Exception(
             f'app_config is not a SystemConfig, but {type(app_config)} instead'
         )
     if not isinstance(device_config, self.config_class):
         raise Exception(
             f'device_config is not a {self.config_class}, but {type(device_config)} instead'
         )
     # assign system config
     self.system = app_config
     self.q_int = app_config.get('q_int')
     self.uid = app_config.get('uid')
     self.logger = app_config.logger()
     # assign device ingame config
     self.config = device_config
     self.config.load()  # load and update current running conf
예제 #5
0
    def __init__(self, config: SystemConfig):
        super().__init__()

        self.event = dict()
        self.daemon = True
        self.client = None
        self.logger = config.logger()

        # Queues
        self.q_int = config.get('q_int')
        self.q_ext = config.get('q_ext')

        # Device
        self.skip_until = 0
        self.pub = config.get('pub')
        self.sub = config.get('sub')

        # MQTT broker
        self.broker_ip = config.get('broker_ip')
        self.broker_port = config.get('broker_port', 1883)
        self.username = config.get('username')
        self.password = config.get('password')
        self.client_id = f"{config.get('topic')}_{config.get('uid')}"

        if not self.broker_ip:
            self.logger.error(
                '[!] cannot configure client, broker ip missing. exiting...')
            return
예제 #6
0
from device import BoilerplateDevice
from config import BoilerplateConfig

root = os.path.abspath(os.path.dirname(__file__))

sys_config_path = os.path.join(root, 'conf', 'system.yml')
dev_config_path = os.path.join(root, 'conf', 'device.yml')

if __name__ == "__main__":
    #
    # DO NOT FORGET TO RUN ./pre-run.sh install BEFORE FIRST START
    #

    # setting system config (immutable)
    app_config = SystemConfig(sys_config_path, root=root)
    # making device config (mutable, in-game)
    dev_config = BoilerplateConfig(dev_config_path)
    # <-- perform specific device config operations
    # which should be run once before main program
    # like making asset paths if you using DeviceConfigExtendede
    # dev_config.make_asset_paths()

    # instantiating device
    device = BoilerplateDevice(app_config, dev_config)
    # <-- perform specific device operations
    # which should be run once before main program
    # like device.gpio_setup() for lock device

    # start application
    start_app(app_config=app_config, device=device)
예제 #7
0
파일: app.py 프로젝트: skaben/device_lock
import os

from skabenclient.config import SystemConfig
from skabenclient.main import start_app

from device import LockDevice
from config import LockConfig

root = os.path.abspath(os.path.dirname(__file__))

sys_config_path = os.path.join(root, 'conf', 'system.yml')
dev_config_path = os.path.join(root, 'conf', 'device.yml')

if __name__ == "__main__":
    # setting up system configuration and logger
    app_config = SystemConfig(sys_config_path)
    dev_config = LockConfig(dev_config_path)
    device = LockDevice(app_config, dev_config)
    device.gpio_setup()  # pins for laser control and serial interface for keypads
    start_app(app_config=app_config,
              device=device)
예제 #8
0
파일: app.py 프로젝트: skaben/device_shield
from skabenclient.config import SystemConfig
from skabenclient.helpers import get_mac
from skabenclient.main import start_app

from dotenv import load_dotenv

from device import BoilerplateDevice
from config import BoilerplateConfig

root = os.path.abspath(os.path.dirname(__file__))

sys_config_path = os.path.join(root, 'conf', 'system.yml')
dev_config_path = os.path.join(root, 'conf', 'device.yml')

log_path = os.path.join(root, 'local.log')

if __name__ == "__main__":
    #
    # DO NOT FORGET TO RUN ./pre-run.sh install BEFORE FIRST START
    #

    # setting system configuration and logger
    app_config = SystemConfig(sys_config_path, root=root)
    app_config.logger(file_path=log_path)
    # inject arguments into system configuration
    dev_config = BoilerplateConfig(dev_config_path)
    # instantiating device
    device = BoilerplateDevice(app_config, dev_config)
    # start application
    start_app(app_config=app_config, device=device)