def __init__(self): Sensor.__init__(self, "mySensor", "My sensor x", DummySensorDeviceDriver(unit="c")) self.value_type = "temperature" self.add_error_range((0, 10), "l error message", channels=["user_log", "email"]) self.add_warning_range((10, 20), "l warning message") self.add_normal_range((20, 80), "normal", channels=["user_log", "email"]) self.add_warning_range((80, 90), "h warning message", channels=["user_log", "email"]) self.add_error_range((90, 100), "h error message", channels=["user_log", "email"]) self.link_to_dashboard("app", "sensors", type="radial_gauge") self.link_to_dashboard("app", "sensors", type="value", show_sparkline=True)
def test_single_sensor(): spine = MockupSpine() device = MockupSensorDeviceDriver() device.value = 10 sensor = Sensor("test_id", "Test sensor", device, spine=spine, configuration = get_test_config()) assert sensor.device == device assert sensor.value_type == "temperature" assert sensor.value_unit == "C" spine.simulate_app_start() sensor_thread = MockupSensorThread(sensor) sensor_thread.step() assert sensor.value == 10
def test_multi_sensor(): spine = MockupSpine() device = MockupMultiDimSensorDeviceDriver() device.value1 = 10 device.value2 = 20 device.value3 = 30 sensor = Sensor("test_id", "Test sensor", device, spine=spine, configuration = get_test_config()) assert sensor.device == device assert sensor.value_type == "position" assert sensor.value_unit == "degree" spine.simulate_app_start() sensor_thread = MockupSensorThread(sensor) sensor_thread.step() assert sensor[0].value == 10 assert sensor[1].value == 20 assert sensor[2].value == 30
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()
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
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() #add dashboard and panel from kervi.sensors import Sensor from kervi.devices.sensors.VL6180X import VL6180XDistanceDeviceDriver, VL6180XLuxDeviceDriver sensor = Sensor("vl6180x_distnace", "Distance", VL6180XDistanceDeviceDriver()) sensor.link_to_dashboard() sensor1 = Sensor("vl6180x_lux", "lux", VL6180XLuxDeviceDriver()) sensor1.link_to_dashboard() APP.run()
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()
"h warning message", channels=["user_log", "email"]) self.add_error_range((90, 100), "h error message", channels=["user_log", "email"]) self.link_to_dashboard("app", "sensors", type="radial_gauge") self.link_to_dashboard("app", "sensors", type="value", 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"
if __name__ == '__main__': from kervi.application import Application APP = Application() from kervi.sensors import Sensor from kervi.devices.sensors.CW2015 import CW2015VoltageDeviceDriver, CW2015CapacityDeviceDriver sensor = Sensor("CW2015_voltage", "CW2015 voltage", CW2015VoltageDeviceDriver()) sensor.link_to_dashboard() sensor1 = Sensor("CW2015_capacity", "CW2015 capacity", CW2015CapacityDeviceDriver()) sensor1.link_to_dashboard() APP.actions.shutdown.link_to(sensor1, trigger_value=lambda x: x < 50) APP.run()
"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 from kervi.streams import stream_images, stream_observer from kervi.vision.region import region_observer, Region, Regions import datetime import time
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()
if __name__ == '__main__': from kervi.application import Application APP = Application() #add dashboard and panel from kervi.dashboards import Dashboard, DashboardPanel from kervi.sensors import Sensor from kervi.devices.sensors.TSL2561 import TSL2561DeviceDriver SENSOR = Sensor("TSL2561", "Light", TSL2561DeviceDriver()) SENSOR.link_to_dashboard() APP.run()
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 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",
}) #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)
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()
#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()) #link to dashboard
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 from kervi.devices.displays.SSD1306 import SSD1306DeviceDriver from kervi.displays import Display, DisplayPage
# 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)
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()
"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") #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
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()
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( {"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 SENSOR_1 = Sensor("app_CPULoadSensor", "App CPU", CPULoadSensorDeviceDriver()) SENSOR_1.link_to_dashboard(type="value", link_to_header=True) SENSOR_1.link_to_dashboard(type="chart") APP.actions.shutdown.link_to_dashboard("*", "header_right", inline=True, label=None, button_text="App shutdown") APP.run()