Skip to content

model.createSensor

since 1.5.5

Create a sensor.

model.createSensor()

Parameters

None.

Returns

the source of the created sensor

Examples

From the official Ethos documentation
local sensor1 = model.createSensor({type=SENSOR_TYPE_SPORT, appId=0x0100, physId=0x10}) -- S.Port "Altitude" sensor
local sensor2 = model.createSensor({type=SENSOR_TYPE_CRSF, crsfId=0x14, subId=0}) -- CRSF "Tx RSSI" sensor
local sensor3 = model.createSensor({type=SENSOR_TYPE_DIY}) -- DIY sensor
sensor3:name("My sensor")
sensor3:unit(UNIT_KILOMETER)
sensor3:decimals(3)
sensor3:appId(0x0110)
sensor3:physId(0x10)
sensor3:value(100)

Real-world usage

Called 8 times across 5 open-source Ethos Lua projects. A few short excerpts:
sensor = model.createSensor({type = SENSOR_TYPE_DIY})

src/rfsuite/sensors/providers/msp.lua:201

local s = model.createSensor({type = SENSOR_TYPE_DIY})

src/inav-dashboard/sensors/telemetry.lua:249

local sensor = model.createSensor({type = SENSOR_TYPE_DIY})

src/dashx/lib/sensors.lua:96