Beispiel #1
0
        "network": {
            "ip": "127.0.0.1",
            "ipc_root_address": "127.0.0.1",
            "ws_port": 9000,
        },
        "location": {
            # greenwich
            "longitude": 61.563300,
            "latitude": -6.838634,
            "time_zone": 0
        },
    })

    #add dashboard and panel
    from kervi.dashboards import Dashboard, DashboardPanel
    DASHBOARD = Dashboard("system", "Sensor test", is_default=True)
    DASHBOARD.add_panel(DashboardPanel("multi_sensor", title="Multi sensor"))
    DASHBOARD.add_panel(
        DashboardPanel("multi_sensor_single", title="Multi sensor single"))
    DASHBOARD.add_panel(
        DashboardPanel("color_sensor", title="Color sensor single ----xxx---"))
    DASHBOARD.add_panel(DashboardPanel("sun_sensor", title="Sun sensor"))
    DASHBOARD.add_panel(DashboardPanel("gauge", title="Gauge"))
    DASHBOARD.add_panel(DashboardPanel("log", title="Log", user_log=True))

    from kervi.sensors import Sensor
    from kervi.devices.sensors.system import CPULoadSensorDeviceDriver
    from kervi.devices.sensors.dummy_sensor import DummyMultiDimSensorDeviceDriver

    cpu_sensor = Sensor("CPULoadSensor", "CPU", CPULoadSensorDeviceDriver())
    cpu_sensor.store_to_db = False
Beispiel #2
0
from kervi.dashboards import Dashboard, DashboardPanel, DashboardPanelGroup

#Create the dashboards for your Kervi application here.
#Standard dashboard with several panels where sensors are placed.
#Each sensor create links to one or more dashboard panels
APP_DASHBOARD = Dashboard(
    "app",
    "My dashboard", [
        DashboardPanelGroup([
            DashboardPanelGroup([
                DashboardPanelGroup([
                    DashboardPanel("fan", width=70, title="Lightx"),
                    DashboardPanel("sensors", width=30, title="Sensors"),
                ], ),
                DashboardPanelGroup([
                    DashboardPanel("fanx", title="Panel 1"),
                    DashboardPanel("sensorsx", title="Panel 2"),
                    DashboardPanel("logx", title="Panel 3")
                ], ),
            ],
                                width=60,
                                layout="column"),
            DashboardPanel("log", width=40, title="Log", user_log=True)
        ]),
    ],
    is_default=True)
#
SYSTEM_DASHBOARD = Dashboard("system",
                             "System",
                             panels=[
                                 DashboardPanelGroup([
Beispiel #3
0
""" bootstrap your kervi dashboards here """
from kervi.dashboards import Dashboard, DashboardPanel

#Create the dashboards for your Kervi application here.
#Standard dashboard with several panels where sensors are placed.
#Each sensor create links to one or more dashboard panels
Dashboard("app",
          "My dashboard", [
              DashboardPanel("fan", title="Fan"),
              DashboardPanel("sensors", title="Sensors")
          ],
          is_default=True)

Dashboard("system",
          "System", [
              DashboardPanel("cpu"),
              DashboardPanel("memory"),
              DashboardPanel("disk"),
              DashboardPanel("device", title="device"),
              DashboardPanel("log", title="Log", user_log=True)
          ],
          user_groups=["admin"])
Beispiel #4
0
        "info":{
            "id":"module.id",
            "name":"Module name"
        },
        "log":{
            "file":"kervi-module.log"
        },
        "network" : {
            "ipc_root_port": 9500,
            "ipc_root_address": "192.168.0.137"
        }
        
    })

    from kervi.dashboards import Dashboard, DashboardPanel
    DASHBOARD = Dashboard("dashboard.module", "module dashboard", is_default=True)
    DASHBOARD.add_panel(DashboardPanel("panel", columns=2, rows=2, title="Panel dashboard"))

    from kervi.sensors import Sensor
    from kervi.devices.sensors.system import MemoryUseSensorDeviceDriver
    SENSOR_1 = Sensor("MemLoadSensor", "MEM", MemoryUseSensorDeviceDriver())
    #link to sys area top right
    SENSOR_1.link_to_dashboard("*", "sys-header")
    #link to a panel, show value in panel header and chart in panel body
    SENSOR_1.link_to_dashboard("dashboard.module", "panel", type="value", size=2, link_to_header=True)
    SENSOR_1.link_to_dashboard("dashboard.module", "panel", type="chart", size=2)

    APP_MODULE.actions.shutdown.link_to_dashboard("*", "header_right", inline=True, label=None, button_text="Module shutdown")


    from kervi.streams import stream_observer
Beispiel #5
0
    from kervi.application import Application
    APP = Application({
        "network": {
            "ip": "127.0.0.1",
            "ipc_root_address": "127.0.0.1",
            "ws_port": 9000,
        }
    })

    #add dashboard and panel
    from kervi.dashboards import Dashboard, DashboardPanel
    DASHBOARD = Dashboard(
        "dashboard",
        "Controller test",
        [
            #     DashboardPanel("text", title="text Width 0"),
            #     DashboardPanel("text_inline",  title="text inline"),
            #     DashboardPanel("log", title="Log", user_log=True)
        ],
        is_default=True)

    from kervi.controllers import Controller
    from kervi.values import StringValue
    from kervi.messaging import Messaging

    class TestController(Controller):
        def __init__(self):
            Controller.__init__(self, "controller.test", "test")
            self.type = "test"

            self.test_string = self.inputs.add("test_string", "String",
Beispiel #6
0
if __name__ == '__main__':
    from kervi.application import Application
    APP = Application()
    #Important GPIO must be imported after application creation
    from kervi.hal import GPIO

    from kervi.dashboards import Dashboard, DashboardPanel
    Dashboard("app",
              "App", [DashboardPanel("fan", title="CPU fan")],
              is_default=True)

    Dashboard(
        "system", "System",
        [DashboardPanel("cpu"), DashboardPanel("cam")])

    #Create a streaming camera server
    from kervi.vision.camera import CameraStreamer
    CAMERA = CameraStreamer("cam1", "camera 1")
    #link camera as background
    CAMERA.link_to_dashboard("app")
    #link camera to a panel
    CAMERA.link_to_dashboard("system", "cam")

    from kervi.sensors import Sensor
    from kervi.devices.sensors.system import CPULoadSensorDeviceDriver
    from kervi.devices.sensors.system import CPUTempSensorDeviceDriver
    #build in sensor that measures cpu use
    SENSOR_CPU_LOAD = Sensor("CPULoadSensor", "CPU",
                             CPULoadSensorDeviceDriver())
    #link to sys area top right
    SENSOR_CPU_LOAD.link_to_dashboard("*", "sys-header")
Beispiel #7
0
if __name__ == '__main__':
    from kervi.application import Application
    APP = Application()

    #add dashboard and panel
    from kervi.dashboards import Dashboard, DashboardPanel
    DASHBOARD = Dashboard("main", "Controller Buttons", is_default=True)
    DASHBOARD.add_panel(DashboardPanel("gpio", columns=3, rows=3,
                                       title="GPIO"))

    from kervi.hal import GPIO

    GPIO["GPIO1"].define_as_input()
    GPIO["GPIO2"].define_as_output()
    GPIO["GPIO3"].define_as_pwm(60, 0)

    GPIO["GPIO1"].link_to_dashboard("main", "gpio")
    GPIO["GPIO2"].link_to_dashboard("main", "gpio")
    GPIO["GPIO3"].pwm["duty_cycle"].link_to_dashboard("main", "gpio")

    APP.run()
Beispiel #8
0
from kervi.dashboards import Dashboard, DashboardPanel

#Define dashboards and panels
Dashboard("layout",
          "Layout", [
              DashboardPanel("fan", title="CPU fan", width=50),
              DashboardPanel("p1", title="Panel 2", width=25),
              DashboardPanel("p2", title="Panel 3", width=25)
          ],
          is_default=False)

#create sensor
from kervi.sensors import Sensor
from kervi.devices.sensors.system import CPULoadSensorDeviceDriver
from kervi.devices.sensors.system import CPUTempSensorDeviceDriver
from kervi.devices.sensors.dummy_sensor import DummySensorDeviceDriver
#create a senors that uses CPU load device driver
cpu_load_sensor = Sensor("CPULoadSensor", "CPU", CPULoadSensorDeviceDriver())

#link to dashboard
cpu_load_sensor.link_to_dashboard("*", "header_right", show_sparkline=True)
cpu_load_sensor.link_to_dashboard("layout",
                                  "p1",
                                  type="value",
                                  show_sparkline=True,
                                  link_to_header=True)
cpu_load_sensor.link_to_dashboard("layout", "p1", type="chart")
cpu_load_sensor.link_to_dashboard("layout", "p2", type="chart")
#create a senors that uses CPU temp device driver
cpu_temp_sensor = Sensor("CPUTempSensor", "CPU temp",
                         DummySensorDeviceDriver())
Beispiel #9
0
if __name__ == '__main__':
    from kervi.application import Application
    APP = Application()

    #add dashboard and panel
    from kervi.dashboards import Dashboard, DashboardPanel
    DASHBOARD = Dashboard("dashboard", "GPIO", is_default=True)
    DASHBOARD.add_panel(
        DashboardPanel("gpio", columns=2, rows=4, title="GPIO Width 0"))
    DASHBOARD.add_panel(
        DashboardPanel("gpio_inline", columns=3, rows=4,
                       title="button inline"))

    from kervi.hal import GPIO

    GPIO["GPIO1"].define_as_output()
    GPIO["GPIO1"].link_to_dashboard("dashboard", "gpio")

    GPIO["GPIO1"].pwm["duty_cycle"].link_to_dashboard("dashboard", "gpio")
    GPIO["GPIO1"].pwm["active"].link_to_dashboard("dashboard", "gpio")

    GPIO["DAC1"].link_to_dashboard("dashboard", "gpio")

    APP.run()
Beispiel #10
0
import time

if __name__ == '__main__':
    from kervi.application import Application
    APP = Application({
        "modules": ["action_tests"],
        "network": {
            "ip": "127.0.0.1",
            "ip_root_address": "127.0.0.1"
        }
    })

    from kervi.dashboards import Dashboard, DashboardPanel
    DASHBOARD = Dashboard("app",
                          "App", [DashboardPanel("actions", width="200px")],
                          is_default=True)

    from kervi.actions import action, Actions
    interupt_action = False

    @action
    def action_start():
        print("action_start")
        while not interupt_action:
            time.sleep(0.1)
        print("action_start done")

    @action_start.set_interrupt
    def action_interupt():
        global interupt_action
        print("action interupt")
Beispiel #11
0
if __name__ == '__main__':
    from kervi.application import Application
    APP = Application({
        "network":{
            "ip": "127.0.0.1",
            "ipc_root_address": "127.0.0.1",
            "ws_port": 9000,
        }        
    })

    #add dashboard and panel
    from kervi.dashboards import Dashboard, DashboardPanel
    DASHBOARD = Dashboard("dashboard", "Dynamic boolean test", is_default=True)
    DASHBOARD.add_panel(DashboardPanel("boolean", title="Boolean"))
    DASHBOARD.add_panel(DashboardPanel("boolean_inline", title="boolean inline"))
    DASHBOARD.add_panel(DashboardPanel("log", title="Log", user_log=True))

    from kervi.hal import GPIO
    from kervi.controllers import Controller
    from kervi.values import BooleanValue
    from kervi.messaging import Messaging

    class TestController(Controller):
        def __init__(self):
            Controller.__init__(self, "controller.test", "test")
            self.type = "test"

            #define an input and link it to the dashboard panel
            self.inputs.add("boolean", "Boolean", BooleanValue)
            self.inputs["boolean"].link_to_dashboard("dashboard", "boolean")
            self.inputs["boolean"].link_to_dashboard("dashboard", "boolean", label="1", label_icon="bulb", on_text="active", off_text="inactive")
Beispiel #12
0
if __name__ == '__main__':
    from kervi.application import Application
    APP = Application()
    #Important GPIO must be imported after application creation
    from kervi.hal import GPIO

    from kervi.dashboards import Dashboard, DashboardPanel
    DASHBOARD = Dashboard("app", "App", is_default=True)
    DASHBOARD.add_panel(
        DashboardPanel("fan", columns=3, rows=2, title="CPU fan"))

    SYSTEMBOARD = Dashboard("system", "System")
    SYSTEMBOARD.add_panel(DashboardPanel("cpu", columns=2, rows=2))
    SYSTEMBOARD.add_panel(DashboardPanel("cam", columns=2, rows=2))

    #Create a streaming camera server
    from kervi.vision.camera import CameraStreamer
    CAMERA = CameraStreamer("cam1", "camera 1")
    #link camera as background
    CAMERA.link_to_dashboard("app")
    #link camera to a panel
    CAMERA.link_to_dashboard("system", "cam")
    CAMERA.pan.link_to_dashboard("system", "cpu")
    CAMERA.tilt.link_to_dashboard("system", "cpu")

    from kervi.sensors import Sensor
    from kervi.devices.sensors.system import CPULoadSensorDeviceDriver
    from kervi.devices.sensors.system import CPUTempSensorDeviceDriver
    #build in sensor that measures cpu use
    SENSOR_CPU_LOAD = Sensor("CPULoadSensor", "CPU",
                             CPULoadSensorDeviceDriver())
Beispiel #13
0
    def _start(self):
        self.started = True

        try:
            import dashboards
        except ImportError:
            pass

        import kervi.core.utility.process as process
        import kervi.utility.application_helpers as app_helpers

        #if self._as_service:
        signal.signal(signal.SIGINT, handler_stop_signals)
        signal.signal(signal.SIGTERM, handler_stop_signals)

        self.spine.send_command("startThreads", local_only=True)
        time.sleep(.5)
        module_port = self.config.network.ipc_root_port
        pluginManager = PluginManager(self.config, log_queue=self._log_queue)
        self._process_info_lock.acquire()
        plugin_modules = pluginManager.prepare_load()
        for plugin_module in plugin_modules:
            self._process_info.append({
                "id": plugin_module,
                "ready": False,
                "pid": None
            })
        self._process_info_lock.release()

        module_port = pluginManager.load_plugins(module_port + 1)

        for module in self.config.modules:
            self._process_info_lock.acquire()
            self._process_info += [{"id": module, "ready": False, "pid": None}]
            self._process_info_lock.release()

            module_port += 1
            self._module_processes += [
                process._start_process("app-" + self.config.application.id,
                                       module,
                                       self.config,
                                       nethelper.get_free_port([module_port]),
                                       app_helpers._KerviModuleLoader,
                                       log_queue=self._log_queue)
            ]

        #print("wait for ready")
        try:
            while not self.char_list and not self._is_ready():
                #print(self.char_list)
                time.sleep(1)
        except KeyboardInterrupt:
            pass

        #print("pi", self._process_info)

        if not self._in_stop:
            from kervi.dashboards import Dashboard
            Dashboard._add_default()

            self.spine.send_command("kervi_action_app_main")
            ready_message = "Your Kervi application is running"
            self._logger.info(ready_message)

            self._logger.info("Press ctrl + c to stop your application")
            self.spine.trigger_event("appReady", self.config.application.id)

            if self.config.discovery.enabled:
                self._discovery_thread = KerviAppDiscovery(
                    self.config.network.ip,
                    self.config.network.ipc_root_port,
                    self.config.discovery.port,
                    self.config.application.id,
                    self.config.discovery.challenge,
                    self.config.application.name,
                    "http://" + self.config.network.
                    ip  # + ":" + str(self.config.network.http_port)
                )
                self._discovery_thread.start()
            else:
                self._discovery_thread = None
Beispiel #14
0
if __name__ == '__main__':
    from kervi.application import Application
    APP = Application({
        "network": {
            "ip": "127.0.0.1",
            "ipc_root_address": "127.0.0.1",
            "ws_port": 9000,
        }
    })

    #add dashboard and panel
    from kervi.dashboards import Dashboard, DashboardPanel
    DASHBOARD = Dashboard("dashboard", "Dynamic number test", is_default=True)
    DASHBOARD.add_panel(DashboardPanel("number", width=33, title="Number"))
    DASHBOARD.add_panel(DashboardPanel("number_inline", title="number inline"))
    DASHBOARD.add_panel(DashboardPanel("number_gauge", width=20))

    DASHBOARD.add_panel(DashboardPanel("number_chart"))
    DASHBOARD.add_panel(DashboardPanel("number_chart_x", width=100))
    DASHBOARD.add_panel(DashboardPanel("log", title="Log", user_log=True))

    from kervi.sensors import Sensor
    from kervi.devices.sensors.system import CPULoadSensorDeviceDriver
    cpu_sensor = Sensor("CPULoadSensor", "CPU", CPULoadSensorDeviceDriver())
    cpu_sensor.link_to_dashboard("dashboard", "number_chart", type="chart")
    cpu_sensor.link_to_dashboard("dashboard",
                                 "number_chart",
                                 link_to_header=True)
    cpu_sensor.link_to_dashboard("*", "header_right", show_sparkline=True)

    cpu_sensor.link_to_dashboard(
Beispiel #15
0
""" bootstrap your kervi dashboards here """
from kervi.dashboards import Dashboard, DashboardPanel

#Create the dashboards for your Kervi application here.
#Standard dashboard with several panels where sensors are placed.
#Each sensor create links to one or more dashboard panels
APP_DASHBOARD = Dashboard("app", "Main dahsboard", is_default=True)
APP_DASHBOARD.add_panel(DashboardPanel("steering", title="Steering"))
APP_DASHBOARD.add_panel(DashboardPanel("balance_pid", title="Balance PID "))
APP_DASHBOARD.add_panel(DashboardPanel("sensors", title="Sensors"))

SYSTEM_DASHBOARD = Dashboard("system", "System")
SYSTEM_DASHBOARD.add_panel(DashboardPanel("cpu"))
SYSTEM_DASHBOARD.add_panel(DashboardPanel("memory"))
SYSTEM_DASHBOARD.add_panel(DashboardPanel("disk"))
SYSTEM_DASHBOARD.add_panel(DashboardPanel("power", title="Power"))
SYSTEM_DASHBOARD.add_panel(DashboardPanel("log", title="Log", user_log=True))
if __name__ == '__main__':
    from kervi.application import Application
    APP = Application()

    #add dashboard and panel
    from kervi.dashboards import Dashboard, DashboardPanel
    DASHBOARD = Dashboard("dashboard.ctrl",
                          "Adafruit char lcd test",
                          is_default=True)
    DASHBOARD.add_panel(
        DashboardPanel("input", columns=2, rows=4, title="input"))
    DASHBOARD.add_panel(
        DashboardPanel("log", columns=3, rows=4, title="Log", user_log=True))

    #define a light controller
    from kervi.hal import GPIO
    from kervi.controllers import Controller
    from kervi.values import *
    from kervi.devices.displays.HD44780_i2c_PCF8574 import CharLCDDeviceDriver

    class TestController(Controller):
        def __init__(self):
            Controller.__init__(self, "controller.test", "test")
            self.type = "test"

            self.lcd = CharLCDDeviceDriver()
            self.lcd.enable_display(True)
            self.lcd.message("test")
            self.lcd.set_backlight(True)

            self.inputs.add("text", "LCD text", StringValue)
Beispiel #17
0
if __name__ == '__main__':
    from kervi.application import Application
    APP = Application()

    #add dashboard and panel
    from kervi.dashboards import Dashboard, DashboardPanel
    DASHBOARD = Dashboard("dashboard.app", "Test BMP085", is_default=True)
    DASHBOARD.add_panel(DashboardPanel("sensor", columns=2, rows=4,
                                       title=None))

    from kervi.hal import GPIO
    from kervi.sensors import Sensor
    import kervi.devices.sensors as LSM9DS0

    SENSOR_COMPASS = Sensor("compass", "Compass",
                            LSM9DS0.LSM9DS0CompasDeviceDriver())
    SENSOR_COMPASS.link_to_dashboard("dashboard.app", "sensor")

    SENSOR_GRAVITY = Sensor("gravity", "Gravity",
                            LSM9DS0.LSM9DS0GravityDeviceDriver())
    SENSOR_GRAVITY.delta = 0.001
    SENSOR_GRAVITY.link_to_dashboard("dashboard.app", "sensor")

    SENSOR_PR = Sensor("pitch", "Pitch/roll",
                       LSM9DS0.LSM9DS0PitchRollDeviceDriver())
    SENSOR_PR.link_to_dashboard("dashboard.app", "sensor")

    APP.run()
Beispiel #18
0
if __name__ == '__main__':
    import time
    from kervi.application import Application

    APP = Application()

    from kervi.dashboards import Dashboard, DashboardPanel
    Dashboard("app",
              "App", [DashboardPanel("gate", title="Gate")],
              is_default=True)

    Dashboard("settings", "Settings",
              [DashboardPanel("gate", width="200px", title="Gate")])

    from kervi.devices.motors.dummy_motor_driver import DummyMotorBoard

    motor_board = DummyMotorBoard()

    from kervi.hal import GPIO
    hi_end_stop = GPIO["GPIO2"]
    lo_end_stop = GPIO["GPIO3"]

    hi_end_stop.define_as_input()
    lo_end_stop.define_as_input()

    stop_move = False

    from kervi.actions import action

    @action(name="Move gate")
    def move_gate(open=True):
Beispiel #19
0
if __name__ == '__main__':
    from kervi.application import Application
    APP = Application(
        {
            # "network":{
            #     "ip": "127.0.0.1",
            #     "ipc_root_address": "127.0.0.1"
            # }
        }
    )

    #add dashboard and panel
    from kervi.dashboards import Dashboard, DashboardPanel
    DASHBOARD = Dashboard("dashboard.app", "app dashboard", is_default=True)
    DASHBOARD.add_panel(DashboardPanel("cpu", columns=2, rows=4, title=None))


    from kervi.sensors import Sensor
    from kervi.devices.sensors.system import CPULoadSensorDeviceDriver
    SENSOR_1 = Sensor("CPULoadSensor", "CPU", CPULoadSensorDeviceDriver())
    #link to sys area top right
    SENSOR_1.link_to_dashboard("*", "sys-header")
    #link to a panel, show value in panel header and chart in panel body
    SENSOR_1.link_to_dashboard("dashboard.app", "cpu", type="value", size=2, link_to_header=True)
    SENSOR_1.link_to_dashboard("dashboard.app", "cpu", type="chart", size=2)

    APP.actions.shutdown.link_to_dashboard("*", "header_right", inline=True, label=None, button_text="App shutdown")

    
    APP.run()
Beispiel #20
0
if __name__ == '__main__':
    from kervi.application import Application
    APP = Application({
        "network": {
            "ip": "127.0.0.1",
            "ipc_root_address": "127.0.0.1",
            "ws_port": 9000,
        }
    })

    #add dashboard and panel
    from kervi.dashboards import Dashboard, DashboardPanel
    DASHBOARD = Dashboard("dahsboard.ctrl", "Controller test", is_default=True)
    DASHBOARD.add_panel(
        DashboardPanel("textinput", title="date time value", width="50%"))
    DASHBOARD.add_panel(DashboardPanel("text_inline", title="inline"))
    DASHBOARD.add_panel(DashboardPanel("log", title="Log", user_log=True))

    #define a light controller
    from kervi.hal import GPIO
    from kervi.controllers import Controller
    from kervi.values import DateTimeValue
    from kervi.messaging import Messaging

    class TestController(Controller):
        def __init__(self):
            Controller.__init__(self, "controller.test", "test")
            self.type = "test"

            #define an input and link it to the dashboard panel
            self.input1 = self.inputs.add("d1", "DateTime 1", DateTimeValue)
Beispiel #21
0
from kervi.dashboards import Dashboard, DashboardPanel

#Define dashboards and panels
Dashboard("simple", "simple", [], is_default=True)

#create sensor
from kervi.sensors import Sensor
from kervi.devices.sensors.system import CPULoadSensorDeviceDriver
from kervi.devices.sensors.system import CPUTempSensorDeviceDriver
from kervi.devices.sensors.dummy_sensor import DummySensorDeviceDriver

#create a senors that uses CPU temp device driver
cpu_temp_sensor = Sensor("CPUTempSensor", "CPU temp",
                         DummySensorDeviceDriver())

#link to dashboard
cpu_temp_sensor.link_to_dashboard(type="radial_gauge")

#define a controller
from kervi.controllers import Controller
from kervi.values import NumberValue


class FanController(Controller):
    def __init__(self):
        Controller.__init__(self, "fan_controller", "Fan")

        #define an input that is a number
        self.temp = self.inputs.add("temp", "Temperature", NumberValue)
        self.temp.min = 0
        self.temp.max = 150
Beispiel #22
0
if __name__ == '__main__':
    from kervi.application import Application
    APP = Application()

    #add dashboard and panel
    from kervi.dashboards import Dashboard, DashboardPanel
    DASHBOARD = Dashboard("dashboard.app", "Test LSM9DS1.py", is_default=True)
    DASHBOARD.add_panel(DashboardPanel("accl", title="Acceleration"))
    DASHBOARD.add_panel(DashboardPanel("gyro", title="Gyro"))
    DASHBOARD.add_panel(DashboardPanel("magnetic", title="Magnetic"))

    from kervi.hal import GPIO
    from kervi.sensors import Sensor

    import kervi.devices.sensors.LSM9DS1 as LSM9DS1

    SENSOR_ACCL = Sensor("accl", "Acceleration",
                         LSM9DS1.LSM9DS1AccelerationDeviceDriver())
    SENSOR_ACCL.link_to_dashboard("dashboard.app", "accl")

    SENSOR_GYRO = Sensor("gyro", "gyro", LSM9DS1.LSM9DS1GyroDeviceDriver())
    SENSOR_GYRO.link_to_dashboard("dashboard.app", "gyro")

    SENSOR_MAG = Sensor("magnetic", "Magnetic",
                        LSM9DS1.LSM9DS1MagneticDeviceDriver())
    SENSOR_MAG.link_to_dashboard("dashboard.app", "magnetic")

    APP.run()
Beispiel #23
0
if __name__ == '__main__':
    from kervi.module import Module
    APP_MODULE = Module()
    #Important GPIO must be imported after module creation
    from kervi.hal import GPIO

    from kervi.dashboards import Dashboard, DashboardPanel
    Dashboard(
        "module-{id}",
        "{{name}}",
        [
            DashboardPanel("light", title="Light")
        ],
        is_default=True
    )

    from kervi.sensors import Sensor
    from kervi.devices.sensors.system importMemoryUseSensorDeviceDriver
    #build in sensor that measures cpu use
    SENSOR_1 = Sensor("MemUseSensor", "Memory",MemoryUseSensorDeviceDriver())
    #link to sys area top right
    SENSOR_1.link_to_dashboard("*", "sys-header")
    #link to a panel, show value in panel header and chart in panel body
    SENSOR_1.link_to_dashboard("module-{id}", "memory", type="value", link_to_header=True)
    SENSOR_1.link_to_dashboard("module-{id}", "memory", type="chart")


    #More on sensors https://kervi.github.io/sensors.html


    
Beispiel #24
0
if __name__ == '__main__':
    from kervi.application import Application
    APP = Application({
        "network": {
            "ip": "127.0.0.1",
            "ipc_root_address": "127.0.0.1",
            "ws_port": 9000,
        }
    })

    #add dashboard and panel
    from kervi.dashboards import Dashboard, DashboardPanel
    DASHBOARD = Dashboard("dashboard", "colortest", is_default=True)
    DASHBOARD.add_panel(DashboardPanel("color", width=25, title="Color"))
    DASHBOARD.add_panel(DashboardPanel("color_inline", title="Color inline"))
    DASHBOARD.add_panel(DashboardPanel("log", title="Log", user_log=True))

    from kervi.controllers import Controller
    from kervi.values import ColorValue
    from kervi.messaging import Messaging

    class TestController(Controller):
        def __init__(self):
            Controller.__init__(self, "controller.test", "test")
            self.type = "test"

            #define an input and link it to the dashboard panel
            self.color = self.inputs.add("color", "Boolean", ColorValue)
            self.color.value = "#000f00"
            self.color.persist_value = True
            self.color.link_to_dashboard("dashboard", "boolean")
Beispiel #25
0
    def _start(self):
        self.started = True

        try:
            import dashboards
        except ImportError:
            pass

        import kervi.core.utility.process as process
        import kervi.utility.application_helpers as app_helpers

        if self._as_service:
            signal.signal(signal.SIGINT, handler_stop_signals)
            signal.signal(signal.SIGTERM, handler_stop_signals)

        self.spine.send_command("startThreads", local_only=True)
        time.sleep(.5)
        module_port = self.config.network.ipc_root_port

        self._process_info_lock.acquire()
        self._process_info = [{"id": "IPC", "ready": False}]
        self._process_info_lock.release()

        module_port += 1
        self._module_processes += [
            process._start_process("app-" + self.config.application.id, "IPC",
                                   self.config,
                                   nethelper.get_free_port([module_port]),
                                   app_helpers._KerviSocketIPC)
        ]

        for module in self.config.modules:
            self._process_info_lock.acquire()
            self._process_info += [{"id": module, "ready": False}]
            self._process_info_lock.release()

            module_port += 1
            self._module_processes += [
                process._start_process("app-" + self.config.application.id,
                                       module, self.config,
                                       nethelper.get_free_port([module_port]),
                                       app_helpers._KerviModuleLoader)
            ]

        # if self.config.routing.kervi_io.enabled:
        #     module_port += 1
        #     self._module_processes += [
        #         process._start_process(
        #             "app-" + self.config.application.id,
        #             "kervi_io",
        #             self.config,
        #             nethelper.get_free_port([module_port]),
        #             app_helpers._KerviIORouterProcess
        #         )
        #     ]

        while not self._is_ready():
            time.sleep(1)

        #self._module_processes += app_helpers.load_plugins(self.config, module_port)

        from kervi.dashboards import Dashboard
        Dashboard._add_default()

        import platform
        if platform.system() != "Windows":
            print("\033[92mYour Kervi application is ready at http://" +
                  self.config.network.ip + ":" +
                  str(self.config.network.http_port) + "\033[0m")
        else:
            print("Your Kervi application is ready at http://" +
                  self.config.network.ip + ":" +
                  str(self.config.network.http_port))
        print("Press ctrl + c to stop your application")
        import kervi.ui.webserver as webserver
        webserver.start(self.config.network.ip, self.config.network.http_port,
                        self.config.network.ws_port)
        self.spine.trigger_event("appReady", self.config.application.id)
        self.spine.send_command("startWebSocket")
        self.spine.send_command("kervi_action_app_main")