def test_application(): app = Application({ "modules": ["app_module"], "network": { "ip": "127.0.0.1" } }) app.spine.register_event_handler("appReady", app_ready) app.spine.register_command_handler("signalModuleLoad", module_loaded) assert app.config.application.id == "kervi" assert app.config.modules == ["app_module"] assert app.config.network.ip == "127.0.0.1" app._xrun() process_info = app.spine.send_query("getProcessInfo") time.sleep(5) app.stop(False) assert APP_READY assert MODULE_LOADED == "test_x" assert len(process_info) == 4 processes = [ "application", "plugin_kervi.plugin.ipc.websocket", "plugin_kervi.plugin.ui.web", "app_module" ] for process in process_info: assert process["id"] in processes
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")
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()
if __name__ == '__main__': from kervi.application import Application app = Application() #create sensors from kervi.sensors import Sensor from kervi.devices.sensors.system import CPULoadSensorDeviceDriver from kervi.devices.sensors.system import CPUTempSensorDeviceDriver #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") cpu_load_sensor.link_to_dashboard(type="value", show_sparkline=True, link_to_header=True) cpu_load_sensor.link_to_dashboard(type="chart") #create a senors that uses CPU temp device driver cpu_temp_sensor = Sensor("CPUTempSensor", "CPU temp", CPUTempSensorDeviceDriver()) #link to dashboard cpu_temp_sensor.link_to_dashboard("*", "header_right") cpu_temp_sensor.link_to_dashboard(type="value", show_sparkline=True, link_to_header=True)
if __name__ == '__main__': from kervi.application import Application APP = Application({"network": {"ip": "127.0.0.1"}}) APP.run()
if __name__ == '__main__': import time from kervi.application import Application APP = Application( {"network": { "ip": "127.0.0.1", "ipc_root_address": "127.0.0.1" }}) 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.controllers import Controller from kervi.actions import action, Actions from kervi.values import NumberValue, BooleanValue class GPIOSimulator(Controller): def __init__(self, controller_id="gpio_simulator_controller", name="Gate controller"): super().__init__(controller_id, name) self.gpio1 = self.outputs.add("gpio1", "GPIO1", BooleanValue) self.gpio2 = self.outputs.add("gpio2", "GPIO2", NumberValue) self.gpio2_in = self.inputs.add("gpio2_in", "GPIO2", NumberValue)
# Copyright (c) 2016, Tim Wentzlau # Licensed under MIT 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, }, "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))
""" My kervi application """ from kervi.application import Application import kervi.utility.nethelper as nethelper if __name__ == '__main__': APP = Application({ "application": { "id": "can_bot", "name": "Kervi can bot", "appKey": "", }, "modules": ["sensors", "controllers", "cams"], }) APP.run()
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()
if __name__ == '__main__': from kervi.application import Application APP = Application({ "unit_system": "us-imperial", "network":{ "ip": "127.0.0.1", "ipc_root_address": "127.0.0.1" } }) 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 #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") #link to a panel, show value in panel header and chart in panel body SENSOR_CPU_LOAD.link_to_dashboard(type="value", size=2, link_to_header=True) SENSOR_CPU_LOAD.link_to_dashboard(type="chart", size=2) #build in sensor that measures cpu temperature SENSOR_CPU_TEMP = Sensor("CPUTempSensor", "", DummySensorDeviceDriver(type="temperature", unit="c")) #link to sys area top right SENSOR_CPU_TEMP.link_to_dashboard("*", "sys-header") from kervi.devices.displays.dummy_display_driver import DummyCharDisplayDriver, DummyBitmapDisplayDriver
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")
if __name__ == '__main__': import time from kervi.application import Application APP = Application() from kervi.controllers.steering import MotorSteering from kervi.devices.motors.dummy_motor_driver import DummyMotorBoard motor_board = DummyMotorBoard() steering = MotorSteering() steering.left_speed.link_to(motor_board.dc_motors[0]) steering.right_speed.link_to(motor_board.dc_motors[1])
if __name__ == '__main__': from kervi.application import Application APP = Application({ "application": { "id":"app_4", "name":"Test multi file app", "appKey":"1234", }, "log":{ "file":"kervi-module.log" }, "network":{ "ip": "127.0.0.1", "ip_module_port": 9600, "ipc_root_port": 9700, "ipc_root_address": "127.0.0.1" }, "plugins":{ "kervi.plugin.routing.kervi_io": True#{ # "enabled": True, # "api_user": "******", # "api_password": "******", # "api_channel": "20bddf88a4434e99ba0e014de2b875c7" # } } }) from kervi.sensors import Sensor
if __name__ == '__main__': from kervi.application import Application APP = Application({ "application": { "id": "app_5", "name": "Kervi io app 5", "appKey": "1234", }, "discovery": { "enabled": False }, "log": { "file": "kervi-module.log" }, "network": { "ip": "127.0.0.1", "ip_module_port": 1100, "ipc_root_port": 1200, "ipc_root_address": "127.0.0.1", "ws_port": "9001" }, "plugins": { "kervi.plugin.routing.kervi_io": { "enabled": True, "api_user": "******", "api_password": "******", "api_channel": "20bddf88a4434e99ba0e014de2b875c7" } } }) from kervi.sensors import Sensor
from kervi.application import Application import time if __name__ == '__main__': def module_loaded(module_name): print("module:", module_name) app = Application() app.spine.register_event_handler("moduleLoaded", module_loaded) app._xrun() process_info = app.spine.send_query("getProcessInfo") print("pi", process_info) time.sleep(10) app.stop()
APP = Application({ "development": { "debug_threads": False }, "application": { "id": "app_1", "name": "Test multi file app", "appKey": "1234", }, #"unit_system": "us-imperial", "modules": ["sensors", "controllers", "cams"], "network": { #"ip": "127.0.0.1", #"ipc_root_address": "127.0.0.1", #"ws_port": 9000, }, "texts": { "ui": { "login": "******" } }, "plugins": { "kervi.plugin.authentication.plain": True, "kervi.plugin.messaging.email": { "enabled": False, "smtp": { "sender_name": "Kervi", "sender_address": "*****@*****.**", "server": "localhost", "port": "25", "user": "", "password": "", "tls": False } } }, "plain_users": { "anonymous": { "enabled": True, "groups": [] }, "admin": { "enabled": True, "password": "******", "groups": ["admin"], "name": "Administrator", "addresses": { "email": "*****@*****.**", "phone": "" } } }, "messaging": { "default_channels": ["user_log"] } })