Solar Monitor Lua Library
smlualib.c File Reference

Functions

static int sm_bOp_AND (lua_State *L)
 Returns result of (A & B). More...
 
static int sm_bOp_OR (lua_State *L)
 Returns result of (A | B). More...
 
static int sm_bOp_INV (lua_State *L)
 Returns result of ~A. More...
 
static int sm_GetDeviceState (lua_State *L)
 Returns State of a Device selected by Device ID. 0 = Uninitialized, 1 = OK, 2 = Communication Timeout. More...
 
static int sm_GetDeviceValue (lua_State *L)
 Returns Value from a Device selected by Device ID and Value Name. More...
 
static int sm_SetDeviceValue (lua_State *L)
 Writes to a Value found in a Device selected by Device ID and Value Name. More...
 
static int sm_AddDeviceValue (lua_State *L)
 Adds Value to a Device selected by Device ID. More...
 
static int sm_GetCounterTotal (lua_State *L)
 Finds and returns a value from a Counter selected by Counter ID. More...
 
static int sm_SetCounterTotal (lua_State *L)
 Writes Total value of a Counter selected by Counter ID. More...
 
static int sm_GetBinaryInput (lua_State *L)
 Returns a state of a Binary Input selected by BInput ID. More...
 
static int sm_GetBinaryOutput (lua_State *L)
 Returns a state of a Binary Output selected by BOutput ID. More...
 
static int sm_SetBinaryOutput (lua_State *L)
 Sets a state of a Binary Output selected by BOutput ID. More...
 
static int sm_GetSensorValue (lua_State *L)
 Returns a value of a Sensor selected by Sensor ID. More...
 
static int sm_GetAnalogOutput (lua_State *L)
 Returns a value of a Analog Output selected by AOutput ID. More...
 
static int sm_SetAnalogOutput (lua_State *L)
 Sets a value of a Analog Output selected by AOutput ID. More...
 
static int sm_SetPCMode (lua_State *L)
 Sets Mode by which Power Control is applied (Off, Global, Selective) More...
 
static int sm_SetPCActive (lua_State *L)
 Writes Active Power Limit value to a Power Control. More...
 
static int sm_GetPCActive (lua_State *L)
 Returns Active Power Limit value from a Power Control. More...
 
static int sm_SetPCReactive (lua_State *L)
 Writes Reactive Power (CosPhi) value to a Power Control. More...
 
static int sm_GetPCReactive (lua_State *L)
 Returns Reactive Power (CosPhi) value from a Power Control. More...
 
static int sm_GetPCModuleActive (lua_State *L)
 Returns Active Power Limit value from a connected PC Module. More...
 
static int sm_GetPCModuleReactive (lua_State *L)
 Returns Reactive Power (CosPhi) value from a connected PC Module. More...
 
static int sm_Delay (lua_State *L)
 Pauses Lua Script execution for a specified time delay (ms). More...
 
static int sm_StopScript (lua_State *L)
 Stops Lua Script execution and sets it's state to Idle. More...
 
static int sm_SetScriptCycleTime (lua_State *L)
 Sets Lua Script execution period (minimum 100 ms). More...
 
static int sm_SendEmail (lua_State *L)
 Sends Email from Lua Script. More...
 
static int sm_PIDInit (lua_State *L)
 Initializes PID Controller. More...
 
static int sm_PIDProcess (lua_State *L)
 Takes SetPoint and Feedback parameters and calculates regulated output value based on PID Parameters initialized by sm_PIDInit(). More...
 
static int sm_GetSpotPrice (lua_State *L)
 Returns Energy Spot Price for specified hour, range is from 00:00 of the current day to 00:00 of the next day (48 hours) More...
 
static int sm_GetBatteryPlan (lua_State *L)
 Returns Battery Plan command for specified hour, range is from 00:00 of the current day to 00:00 of the next day (48 hours) More...
 

Function Documentation

◆ sm_AddDeviceValue()

static int sm_AddDeviceValue ( lua_State *  L)
static

Adds Value to a Device selected by Device ID.

Number of parameters depends on a Value Type(1 = Integer, 2 = Enum, 4 = Float, 5 = String).
Example calls:
sm_AddDeviceValue(1, 1, "ValueName", "Unit", 1);
sm_AddDeviceValue(1, 2, "ValueName");
sm_AddDeviceValue(1, 4, "ValueName", "Unit", 1.0);
sm_AddDeviceValue(1, 5, "ValueName", 20);

Parameters
IntegerDevice ID.
IntegerValue Type.
StringName of the value.
String/IntegerUnit of the Value / length if the Value Type is a String.
IntegerMultiplier.
Returns
0 if successful or -1 if any error.

◆ sm_bOp_AND()

static int sm_bOp_AND ( lua_State *  L)
static

Returns result of (A & B).

Parameters
Integer(uint32_t)Operand A.
Integer(uint32_t)Operand B.
Returns
Number(representing uint32_t) or Nil if any error.

◆ sm_bOp_INV()

static int sm_bOp_INV ( lua_State *  L)
static

Returns result of ~A.

Parameters
Integer(uint32_t)Operand A.
Returns
Number(representing uint32_t) or Nil if any error.

◆ sm_bOp_OR()

static int sm_bOp_OR ( lua_State *  L)
static

Returns result of (A | B).

Parameters
Integer(uint32_t)Operand A.
Integer(uint32_t)Operand B.
Returns
Number(representing uint32_t) or Nil if any error.

◆ sm_Delay()

static int sm_Delay ( lua_State *  L)
static

Pauses Lua Script execution for a specified time delay (ms).

Parameters
IntegerDelay in ms.

◆ sm_GetAnalogOutput()

static int sm_GetAnalogOutput ( lua_State *  L)
static

Returns a value of a Analog Output selected by AOutput ID.

Parameters
IntegerAOutput ID.
Returns
Number Analog Output value or Nil if any error.

◆ sm_GetBatteryPlan()

static int sm_GetBatteryPlan ( lua_State *  L)
static

Returns Battery Plan command for specified hour, range is from 00:00 of the current day to 00:00 of the next day (48 hours)

Meaning of the command value for the Battery Plan returned by this function
0 = No action 'Baterie zůstává nezměněna'
1 = Charge from production 'Nabíjení z výroby'
2 = Charge from grid 'Nabíjení ze sítě'
3 = Discharge to consumption 'Vybíjení do spotřeby'
4 = Discharge to grid 'Vybíjení do sítě'
5 = Discharge to consumption and grid 'Vybíjení do spotřeby a do sítě'

Parameters
Integer- Hour
Returns
Number - Battery Plan command or Nil if unavailable/error

◆ sm_GetBinaryInput()

static int sm_GetBinaryInput ( lua_State *  L)
static

Returns a state of a Binary Input selected by BInput ID.

Parameters
IntegerBInput ID.
Returns
Integer State of the Input(0,1) if successful or Nil if any error.

◆ sm_GetBinaryOutput()

static int sm_GetBinaryOutput ( lua_State *  L)
static

Returns a state of a Binary Output selected by BOutput ID.

Parameters
IntegerBOutput ID.
Returns
Integer State of Output(0,1) if successful or Nil if any error.

◆ sm_GetCounterTotal()

static int sm_GetCounterTotal ( lua_State *  L)
static

Finds and returns a value from a Counter selected by Counter ID.

Parameters
IntegerCounter ID.
Returns
Number Counter Total value if successful or Nil if any error.

◆ sm_GetDeviceState()

static int sm_GetDeviceState ( lua_State *  L)
static

Returns State of a Device selected by Device ID. 0 = Uninitialized, 1 = OK, 2 = Communication Timeout.

Parameters
IntegerDevice ID.
Returns
Integer value if successful or Nil if any error.

◆ sm_GetDeviceValue()

static int sm_GetDeviceValue ( lua_State *  L)
static

Returns Value from a Device selected by Device ID and Value Name.

Parameters
IntegerDevice ID.
StringName of the Value.
Returns
Integer/Float/String value if successful or Nil if any error.

◆ sm_GetPCActive()

static int sm_GetPCActive ( lua_State *  L)
static

Returns Active Power Limit value from a Power Control.

Returns
Integer Power Limit value on success or Nil if any error.

◆ sm_GetPCModuleActive()

static int sm_GetPCModuleActive ( lua_State *  L)
static

Returns Active Power Limit value from a connected PC Module.

Returns
Integer Power Limit value on success or Nil if any error.

◆ sm_GetPCModuleReactive()

static int sm_GetPCModuleReactive ( lua_State *  L)
static

Returns Reactive Power (CosPhi) value from a connected PC Module.

Returns
Number CosPhi value on success or Nil if any error.

◆ sm_GetPCReactive()

static int sm_GetPCReactive ( lua_State *  L)
static

Returns Reactive Power (CosPhi) value from a Power Control.

Returns
Number CosPhi value on success or Nil if any error.

◆ sm_GetSensorValue()

static int sm_GetSensorValue ( lua_State *  L)
static

Returns a value of a Sensor selected by Sensor ID.

Parameters
IntegerSensor ID.
Returns
Number value of the sensor or Nil if any error.

◆ sm_GetSpotPrice()

static int sm_GetSpotPrice ( lua_State *  L)
static

Returns Energy Spot Price for specified hour, range is from 00:00 of the current day to 00:00 of the next day (48 hours)

Parameters
Integer- Hour
Integer- optional currency selector (0 = EUR, 1 = CZK, default(undefined parameter) = EUR)
Returns
Number - Spot Price or Nil if unavailable/error

◆ sm_PIDInit()

static int sm_PIDInit ( lua_State *  L)
static

Initializes PID Controller.

Parameters
NumberKp Proportional gain.
NumberKi Integral gain.
NumberKd Derivative gain.
NumberOutput_Max Maximum PID output value.
NumberOutput_Min Minimum PID output value.
NumberKdLPF_Cutoff Kd lowpass filter cutoff frequency in Hz.
NumberTransportDelay Response time of the controlled system(optional, not yet implemented)
NumberPID Controller Instance [0...3] (optional parameter - defaults to 0)
Returns
Integer 0 on success or -1 if any error.

◆ sm_PIDProcess()

static int sm_PIDProcess ( lua_State *  L)
static

Takes SetPoint and Feedback parameters and calculates regulated output value based on PID Parameters initialized by sm_PIDInit().

Parameters
NumberSetPoint (desired output of a system).
NumberFeedback (measured real output of a system)
NumberPID Controller Instance [0...3] (optional parameter - defaults to 0)
Returns
Number PID output value or Nil if any error.

◆ sm_SendEmail()

static int sm_SendEmail ( lua_State *  L)
static

Sends Email from Lua Script.

Parameters
Integer/StringRecipient ID(from Email Settings Page) / Email address.
StringMessage(body).
StringSubject(optional) if not provided then a Subject from the Email settings is applied
Returns
Integer 0 on success or -1 if any error.

◆ sm_SetAnalogOutput()

static int sm_SetAnalogOutput ( lua_State *  L)
static

Sets a value of a Analog Output selected by AOutput ID.

Parameters
IntegerAOutput ID.
Numbervalue.
Returns
Integer 0 on success or -1 if any error.

◆ sm_SetBinaryOutput()

static int sm_SetBinaryOutput ( lua_State *  L)
static

Sets a state of a Binary Output selected by BOutput ID.

Parameters
IntegerBOutput ID.
IntegerState of the Output (1 = ON, 0 = OFF).
Returns
Integer 0 if successful or -1 if any error.

◆ sm_SetCounterTotal()

static int sm_SetCounterTotal ( lua_State *  L)
static

Writes Total value of a Counter selected by Counter ID.

Parameters
IntegerCounter ID.
Numbervalue.
Returns
0 or -1 if any error.

◆ sm_SetDeviceValue()

static int sm_SetDeviceValue ( lua_State *  L)
static

Writes to a Value found in a Device selected by Device ID and Value Name.

Parameters
IntegerDevice ID.
StringName of the Value.
Number/Stringvalue.
Returns
Integer 0 on success or -1 if any error.

◆ sm_SetPCActive()

static int sm_SetPCActive ( lua_State *  L)
static

Writes Active Power Limit value to a Power Control.

Parameters
Integer0 <= PLim <= 100.
IntegerDevice ID (optional depending on Lua Power Control Mode).
Returns
Integer 0 on success or -1 if any error.

◆ sm_SetPCMode()

static int sm_SetPCMode ( lua_State *  L)
static

Sets Mode by which Power Control is applied (Off, Global, Selective)

Mode Description:
Off: Calling functions sm_SetPCActive and sm_SetPCReactive has no effect.
Global: sm_SetPCActive and sm_SetPCReactive functions are executed on all devices.
Selective: sm_SetPCActive and sm_SetPCReactive will require second parameter (Device ID) to which Power Control values will be applied.

Parameters
IntegerMode -> 0 = Off, 1 = Global, 2 = Selective.
Returns
Integer 0 on success or -1 if any error.

◆ sm_SetPCReactive()

static int sm_SetPCReactive ( lua_State *  L)
static

Writes Reactive Power (CosPhi) value to a Power Control.

Parameters
NumberCosPhi. -1.0 <= CosPhi <= 1.0
IntegerDevice ID (optional depending on Lua Power Control Mode).
Returns
Integer 0 on success or -1 if any error.

◆ sm_SetScriptCycleTime()

static int sm_SetScriptCycleTime ( lua_State *  L)
static

Sets Lua Script execution period (minimum 100 ms).

Parameters
IntegerPeriod in ms.

◆ sm_StopScript()

static int sm_StopScript ( lua_State *  L)
static

Stops Lua Script execution and sets it's state to Idle.