# Copyright (c) 2016, Tim Wentzlau # Licensed under MIT """ Module that defines core cpu sensors """ from kervi.sensors import Sensor from kervi.devices.sensors.system import CPULoadSensorDeviceDriver from kervi.devices.sensors.system import MemoryUseSensorDeviceDriver from kervi.devices.sensors.system import DiskUseSensorDeviceDriver from kervi.devices.sensors.system import CPUTempSensorDeviceDriver CPU_SENSOR = Sensor("CPULoadSensor", "CPU", CPULoadSensorDeviceDriver()) CPU_SENSOR.store_to_db = False CPU_SENSOR.link_to_dashboard("*", "header_right") CPU_SENSOR.link_to_dashboard("system", "cpu", type="value", size=2, link_to_header=True) CPU_SENSOR.link_to_dashboard("app", "sensors", type="value") CPU_SENSOR.link_to_dashboard("system", "cpu", type="chart", size=2) CPU_SENSOR.user_groups = ["admin"] MEM_SENSOR = Sensor("MemLoadSensor", "Memory", MemoryUseSensorDeviceDriver()) MEM_SENSOR.store_to_db = False MEM_SENSOR.link_to_dashboard("*", "header_right") MEM_SENSOR.link_to_dashboard("system", "memory", type="value", size=2, link_to_header=True) MEM_SENSOR.link_to_dashboard("system", "memory", type="chart", size=2)
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) cpu_temp_sensor.link_to_dashboard(type="chart")
if __name__ == '__main__': from kervi.module import Module APP_MODULE = Module() from kervi.sensors import Sensor from kervi.devices.sensors.system import CPULoadSensorDeviceDriver SENSOR_1 = Sensor("module_cpu_load", "Module CPU", CPULoadSensorDeviceDriver()) SENSOR_1.link_to_dashboard(type="value", link_to_header=True) SENSOR_1.link_to_dashboard(type="chart") APP_MODULE.actions.shutdown.link_to_dashboard( "*", "header_right", inline=True, label=None, button_text="Module shutdown") APP_MODULE.run()
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()) #link to dashboard cpu_temp_sensor.link_to_dashboard("layout", "p2", type="radial_gauge") #define a controller
"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 from kervi.streams import stream_images, stream_observer from kervi.vision.region import region_observer, Region, Regions import datetime import time import numpy as np
#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( "dashboard", "number_chart_x", type="chart", chart_grid=False, chart_buttons=False, label=False, #chart_fill=False, chart_point=0)
#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
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() #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()
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()
"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 from kervi.devices.displays.SSD1306 import SSD1306DeviceDriver from kervi.displays import Display, DisplayPage page1 = DisplayPage("p1")
if __name__ == '__main__': from kervi.application import Application APP = Application() #add dashboard and panel from kervi.sensors import Sensor import kervi.devices.sensors.BMP085 as BMP085 SENSOR_TEMP = Sensor( "BMP085_temp", "Temperature", BMP085.BMP085DeviceDriver(BMP085.BMP085_TEMPERATURE_SENSOR)) SENSOR_TEMP.link_to_dashboard() SENSOR_PRESSURE = Sensor( "BMP085_pressure", "Pressure", BMP085.BMP085DeviceDriver(BMP085.BMP085_PRESSURE_SENSOR)) SENSOR_PRESSURE.link_to_dashboard() SENSOR_ALTITUDE = Sensor( "BMP085_altitude", "Altitude", BMP085.BMP085DeviceDriver(BMP085.BMP085_ALTITUDE_SENSOR)) SENSOR_ALTITUDE.link_to_dashboard() APP.run()
show_sparkline=True) MySensor() BATTERY_SENSOR = Sensor("Battery", "Battery", DummySensorDeviceDriver()) BATTERY_SENSOR.set_ui_parameter("value_icon", [{ "range": [0, 5], "icon": "battery-empty" }, { "range": [5, 25], "icon": "battery-quarter" }, { "range": [20, 50], "icon": "battery-half" }, { "range": [5, 75], "icon": "battery-three-quarters" }, { "range": [75, 100], "icon": "battery-full" }]) BATTERY_SENSOR.link_to_dashboard(link_to_header=True, display_unit=False, show_sparkline=False, show_value=False) MULTI_SENSOR = Sensor("MultiSensor", "Multi dimension", DummyMultiDimSensorDeviceDriver()) MULTI_SENSOR.link_to_dashboard(panel_id="sensors", type="value") MULTI_SENSOR.link_to_dashboard()
[ DashboardPanel("cpu-load"), DashboardPanel("cpu-temp") ] ) 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("*", "header_right") #link to a panel, show value in panel header and chart in panel body SENSOR_CPU_LOAD.link_to_dashboard("system", "cpu-load", type="value", link_to_header=True) SENSOR_CPU_LOAD.link_to_dashboard("system", "cpu-load", type="chart") #build in sensor that measures cpu temperature SENSOR_CPU_TEMP = Sensor("CPUTempSensor", "", DummySensorDeviceDriver()) SENSOR_CPU_TEMP.link_to_dashboard("system", "cpu-temp", type="value", link_to_header=True) SENSOR_CPU_TEMP.link_to_dashboard("system", "cpu-temp", type="chart") from kervi.controllers import Controller, NumberValue from kervi.actions import action class FanController(Controller): def __init__(self): Controller.__init__(self, "fan_controller", "Fan")
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 APP_MODULE.run()
#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") #link to a panel, show value in panel header and chart in panel body SENSOR_CPU_LOAD.link_to_dashboard("system", "cpu", type="value", link_to_header=True) SENSOR_CPU_LOAD.link_to_dashboard("system", "cpu", type="chart") #build in sensor that measures cpu temperature SENSOR_CPU_TEMP = Sensor("CPUTempSensor", "", CPUTempSensorDeviceDriver()) #link to sys area top right SENSOR_CPU_TEMP.link_to_dashboard("*", "sys-header") #More on sensors https://kervi.github.io/sensors.html #define a light controller
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 cpu_sensor.link_to_dashboard("*", "header_right", show_sparkline=True) cpu_sensor.link_to_dashboard("system", "cpu", type="value", link_to_header=True) cpu_sensor.link_to_dashboard("system", "cpu", type="chart") multi_sensor = Sensor("MultiSensor", "multi sensor", DummyMultiDimSensorDeviceDriver()) multi_sensor.store_to_db = False multi_sensor.link_to_dashboard("system", "multi_sensor", type="value") multi_sensor[0].link_to_dashboard("system", "multi_sensor_single", type="value") multi_sensor[1].link_to_dashboard("system",
self.inputs["color"].link_to_dashboard( "dashboard", "color", label="#", ) self.inputs["color"].link_to_dashboard("color", "color_inline", label="#inline", inline=True) self.color_out = self.outputs.add("color_out", "Color out", ColorValue) self.color_out.link_to_dashboard() def input_changed(self, changed_input): Messaging.send_message("input changed:{0} value:{1}".format( changed_input.value_id, changed_input.value)) self.color_out.value = changed_input.value TestController() from kervi.sensors import Sensor from kervi.devices.sensors.dummy_sensor import DummyColorSensorDeviceDriver #from kervi.devices.sensors.TCS34725 import TCS34725DeviceDriver sensor = Sensor("color_sensor", "Color sensor", DummyColorSensorDeviceDriver()) sensor.link_to_dashboard() APP.run()
if __name__ == '__main__': from kervi.application import Application APP = Application() from kervi.hal import GPIO from kervi.sensors import Sensor from kervi.devices.sensors.TCS34725 import TCS34725DeviceDriver SENSOR = Sensor("color", "Color", TCS34725DeviceDriver()) SENSOR.link_to_dashboard() APP.run()