SatVUE Device Lua Documentation

Lua Documentation

This documentation will describe the variables and functions made available by SatVUE Lua engine. This documentation will not describe how to program in Lua, for this information please see Lua 5.1 Documentation.

The Lua extensions on the SatVUE Device allow you perform custom actions and calculations directly on the SatVUE Device. Scripts can be scheduled to be run periodically, or after specific events such as before or after a sample is taken.

SatVUE Object Properties

  • data This is a general purpose variable to for user defined Lua scripts to store data in.
  • sendReport This is a boolean value which if true, will trigger a report message(s) transmission.
  • sendEioBulkReport This is a boolean value which if true, will trigger an EIO Bulk Report message transmission.
  • sendPortReport This is a boolean value which if true, will trigger a EIO Report message transmission.
  • sendModbusReport This is a boolean value which if true, will trigger a Modbus Report message transmission.
  • sendLoggedData This is a table variable, that if set will trigger a Logged Data message transmission.

SatVUE Object Methods

Modbus Register Representation

Due to the way the IDP protocol works, all modbus registers are represented as strings. This greatly simplies the storage requires for the device SIN/PIN values within the IDP, but does add some complexities when using modbus via Lua scripts on the device.

A modbus register representation has 4 parts:

  • The modbus function code
    • 1: Read a single coils
    • 2: Read a single inputs
    • 3: Read a single holding register
    • 4: Read a single input register
    • 5: Write a single coil
    • 6: Write a single holding register
  • The modbus register type
    • u: 16bit unsigned integer
    • s: 16bit signed integer
    • U: 32bit unsigned integer
    • S: 32bit signed integer
    • F: 32bit Floating point number
  • Register endianness
    • b: Big endian, High word first
    • B: Big endian, Low word first
    • l: Little endian, High word first
    • L: Little endian, Low word first
  • The modbus register address

These parts are combined into a string like 3Fb45, where

  • Function Code: Read Holding Register
  • Register Type: 32bit Floating Point
  • Endianness: Big endian, High word first
  • Reg Address: 45

The SatVUE Object

SatVUE defines one table object in the Lua Engine which are made available to the user defined scriptions. This variable exposes some internal functions which can be used to extend the system to suit your needs. This object is named SatVUE.

SatVUE Object Properties

Name Description
data

This is a general purpose variable to for user defined Lua scripts to store data in. This can be useful if you require some peristent data accross multiple invocations of a single Lua script, or for data sharing between multiple scripts.

The following is an example of how to use this variable:

-- initalise the custom data structure
if SatVUE.data == nil then
  SatVUE.data = {last_value = 0, sum_value = 0}
end

-- get the current value
local value = SatVUE.getPortValue(1)

-- only add this value to the sum, if it was larger than the last value
if value > last_value then
  SatVUE.data.sum_value = SatVUE.data.sum_value + value
end

-- if the sum value is larger than the threshold, then send a report
if SatVUE.data.sum_value > 100 then
  SatVUE.sendReport = true
  SatVUE.data.sum_value = 0
end

-- save the last value
SatVUE.data.last_value = value;
sendReport

This is a boolean value which gets initalised to FALSE before a Lua script is run. If the user defined Lua script sets this property to TRUE, then once the user defined script returns control back to the main SatVUE application, the SatVUE will initate a report upload, including all sampled Modbus and Eio data.

The following is an example of how to use this variable:

SatVUE.sendReport = true
sendEioBulkReport

This is a boolean value which gets initalised to FALSE before a Lua script is run. If the user defined Lua script sets this property to TRUE, then once the user defined script returns control back to the main SatVUE application, the SatVUE will initate a report upload, including all Eio sampled data.

The following is an example of how to use this variable:

SatVUE.sendEioBulkReport = true
sendEioReport

This is a boolean value which gets initalised to FALSE before a Lua script is run. If the user defined Lua script sets this property to TRUE, then once the user defined script returns control back to the main SatVUE application, the SatVUE will initate a report upload, including only the current Eio states.

The following is an example of how to use this variable:

SatVUE.sendPortReport = true
sendModbusReport

This is a boolean value which gets initalised to FALSE before a Lua script is run. If the user defined Lua script sets this property to TRUE, then once the user defined script returns control back to the main SatVUE application, the SatVUE will initate a report upload, including all sampled Modbus data.

The following is an example of how to use this variable:

SatVUE.sendModbusReport = true
sendLoggedData

This is a table value which gets initalised to nil before a Lua script is run. If the user defined Lua script sets this property, then once the user defined script returns control back to the main SatVUE application, the SatVUE will initate a report upload, including all data from the specified time range.

The following is an example of how to use this variable:

SatVUE.sendLoggedData = {
  SendHeader    = false,              -- Should the data header property of the return message be populated.
                                      -- If set to false, the portal will work out what data was sent from
                                      -- the devices configuration.
  StartEpochUTC = os.time() - 3600,   -- Start time is 1 hour ago
  EndEpochUTC   = os.time(),          -- Get all records up to now
  MaxRecords    = 10                  -- Send a max of 10 records
}

SatVUE Object Methods

Name Description
getPortValue(port)

Get the last sampled value from an IDP EIO port

Parameters
port: The EIO port on the IDP, 1 - 4.

Return Value

Returns the port value when it was last sampled. Can be 0 or 1 for digital inputs/outputs or a value between 0 - 3000 for an analog input, or a 31 bit unsigned pulse count.

Example
local digitalInput = SatVUE.getPortValue(1)
if digitalInput == 1 then
  print 'The digital input is set'
end
Example Output:
The digital input is set
getModbusValue(slave, register)

Get the last sampled value from a Modbus slave/register.

Parameters
slave: The modbus slave, 1 - 6.
register: The register code, e.g. 3Fb4.

Return Value

The integer or floating point number is returned, or nil if no sample has been taken or the slave/register is invalid.

Example
local pressure = SatVUE.getModbusValue(2, '3Fb45')
if pressure > 1000 then
  SatVUE.sendReport = true;
  print 'High Pressure Alarm, report sent.'
end
Example Output:
High Pressure Alarm, report sent.
getPortValues()

Get the last sampled value from all four IDP EIO ports, as well as all logged data since the last upload.

Return Value

The last sampled port values are returned in a table of the following format:

{
    port1 = 121,                       -- Last sampled value for Port 1
    port2 = 445,                       -- Last sampled value for Port 2
    port3 = 2341,                      -- Last sampled value for Port 3
    port4 = 1,                         -- Last sampled value for Port 4
    values1 = {151, 141, 131, 121},    -- All logged values since last upload for Port 1
    values2 = {1002, 549, 894, 445},   -- All logged values since last upload for Port 2
    values3 = {121, 587, 1432, 2341},  -- All logged values since last upload for Port 3
    values4 = {1, 0, 1, 1}             -- All logged values since last upload for Port 4
}
Example
local portValues = SatVUE.getPortValues()
local sum = 0;
local count = 0;
for i, value in ipairs(portValues.values1) do
  sum = sum + value
  count = count + 1
end
print 'Port #1 Average = '..(sum / count)
Example Output:
Port #1 Average = 136
getModbusValues()

Get all logged modbus data since the last upload. All floating point number are in 32 Integer representation.

Return Value

The logged modbus data registers are returned in the following format

{
  -- Modbus Slave 1
  {
    Samples = {
       { Registers16 = { {Value = 123}, ... }, Registers32 = { {Value = 4534}, .... } }
    }
  },

  -- Modbus Salve 2
  {
    Samples = {
       { Registers16 = { {Value = 123}, ... }, Registers32 = { {Value = 4534}, .... } }
    }
  },

  -- Modbus Salve 3
  ...
}
Example
local modbusValues = SatVUE.getModbusValues()
if modbusValues.values == nil then
  -- Sample the data
  SatVUE.modbusRead()
end

modbusValues = SatVUE.getModbusValues()
local waterLevel = SatVUE.int32ToFloat(modbusValues.values[1].Samples[1].Registers32[1])

if waterLevel > 10 then
  -- Turn the pump on
  SatVUE.eioSetOutput(1, 1)
end
Example Output:

								
modbusRead()

Enable power and sample all configured Modbus devices.

Example
SatVUE.modbusRead()
local waterLevel = (SatVUE.getModbusValue(1, '3Fb2') - 400) * 0.01
if waterLevel > 100 then
  -- Turn the pump on
  SatVUE.eioSetOutput(1, 1)
end
modbusSend(
funcCode, type,
slaveAddr, regAddr,
value, modbusTimeout,
modbusRetries
)

Parameters
funcCode: The Modbus function code: 1, 2, 3, 4, 5, 6, 15, 16
type: The Modbus register type.
slaveAddr: The Modbus device's slave address
regAddr: The Modbus register address
value: For write functions, set the value here, otherwise nil.
timeout: The number of milliseconds to wait for a response
retries: The number of times to retry the request

Return Value

For read commands, the value read from the device is returned on success, nil otherwise

Example
SatVUE.modbusSend(3, 'Fb', 1, 45, nil, 1000, 3)
eioSample()

Enable power and sample all IDP EIO ports.

Example
SatVUE.eioSample()
local waterLevel = (SatVUE.getPortValue(1) - 400) * 0.01
if waterLevel > 100 then
  -- Turn the pump on
  SatVUE.eioSetOutput(1, 1)
end
eioSetOutput(port, value)

Sets or clears an IDP EIO port configured as a digital output.

Parameters
port: The IDP EIO port, 1 - 4.
value: The digital value to set on the port.

Example
if waterLevel > 10 then
  -- Turn the pump on
  SatVUE.eioSetOutput(1, 1)
end
setDigitalOutput(slave, output, value) Sets/clears an output on an IO expansion board within the SatVUE.

Parameters
slave: The modbus slave the IO exapander is on, 1 - 6.
output: The digital output port to set, 1 - 2.
value: True to set the output, or False to clear the output

Return Value

Returns FALSE if the slave/output parameter is invalid, or TRUE if the message was sent.

Example
if setDigitalOutput(1, 1, true) then
  print 'Message has been sent'
end
Example Output:
Message has been sent
sleep(seconds)

Pause the script for a number of seconds

Parameters
seconds: The number of seconds to sleep for before resuming execution.

Example
SatVUE.sensorPowerEnable()
-- wait for sensors to power up
SatVUE.sleep(1)

-- Sample sensors manually
...

SatVUE.sensorPowerDisable()
sensorPowerEnable()

Enables power on the connectors.

Example
SatVUE.sensorPowerEnable()
-- wait for sensors to power up
SatVUE.sleep(1)

-- Sample sensors manually
...

SatVUE.sensorPowerDisable()
sensorPowerDisable()

Disables power on the connectors.

Example
SatVUE.sensorPowerEnable()
-- wait for sensors to power up
SatVUE.sleep(1)

-- Sample sensors manually
...

SatVUE.sensorPowerDisable()
sendReport()

Send a report to the SatVUE portal, include both EIO and Modbus logged data.

Example
if waterLevel > 10 then
  SatVUE.sendReport()
end
sendModbus()

Send a report to the SatVUE portal, only include logged Modbus data.

Example
if waterLevel > 10 then
  SatVUE.sendModbus()
end
sendEio()

Send a report to the SatVUE portal, only include current EIO data.

Example
if waterLevel > 10 then
  SatVUE.sendEio()
end
sendEioBulk()

Send a report to the SatVUE portal, include all logged EIO data.

Example
if waterLevel > 10 then
  SatVUE.sendEioBulk()
end