- Home
- Documentation
- Lua
- Fields
SatVUE Portal - LUA Fields
Lua/SatVUE Device Field Examples
Copy data from other SatVUE device
To copy a field from one SatVUE device to the current one, just return the lastest value from that device as the field's calculation Lua:
return getLatestValueFromDevice('AnotherSatVUE', 'Barometric')
Non-Vented Hydrostatic Water Level Sensor
In this example we calculate a device field value by subtracting the barometric pressure which provided as a previously calculated field and then calculate the water level from this pressure, from this pressure value. Pressures are in hPa, water level is in meters.
return (message_data['Hydrostatic'] - message_data['Barometric']) * 0.0101971621298
Or if the barometric pressure was provided by another SatVUE device.
local barometric = getLatestValueFromDevice('AnotherSatVUE', 'Barometric') return (message_data['Hydrostatic'] - barometric) * 0.0101971621298
Set a Digital Output
Turn on a pump by setting a digital output (on port 2) on this device, if the water level is too high:
if message_data['WaterLevel'] > 10 then setDigitalOutput(2, true) end
Set a Digital Output on Another SatVUE
Turn on a remote pump by setting a digital output (on port 2) on the Pump SatVUE device, if the water level is too high:
if message_data['WaterLevel'] > 10 then setDigitalOutputOnDevice('PumpSatVUE', 2, true) end
Using Previous Samples
Some calculations need to a set of data points in order to perform the calculation. To acheive this calling the function getPreviousValues() will retreive this data.
-- get the last 5 values of the Water Level field local values = getPreviousValues('Water Level', 5) for i,record in ipairs(values) do local epochTimestamp = record.timestamp local waterLevel = record.value -- if the sample was less than an hour ago if ((getEpochUTC() - epochTimestamp) < 3600) then -- return this water level as the value for this field return waterLevel end end -- No recent data was found, so return nil to drop the value return nil