Global

Methods

__status(status)

Get system status
Parameters:
Name Type Description
status Object System Status Object
Example
let status = __status();
                    status = // {"uid":897946130,"fw_v":85,"cfg_v":139,"adc_sps":8002}

chargecontrollers(Index) → {Object}

Get Morningstar Charge Controller Status and Readings
Parameters:
Name Type Description
Index Number Morningstar charger index
Returns:
Object containing the readings from the charge controller
Type
Object
Example
let ms0 = chargecontrollers(0); // Get first morningstar charger
 print('Battery Voltage: ',ms0.batteryVoltage);
 print(JSON.stringify(ms0));  // Print all possible object values

datetime() → {Object}

Get Date TIme
Returns:
Object Date and Time Information
Type
Object
Example
setEnv('sys.utc_offset',-8); // Set UTC offset

 let dateTime = datetime();
 // dateTime = {"valid":true,"uptime":1437.058175,"epoch":1589247811,"year":2020,"month":5,"monthDay":12,"weekDay":2,"hour":1,"minute":43,"second":31}

getBit(VALUE, BIT) → {Number}

Get a single bit from a interger number
Parameters:
Name Type Description
VALUE Number input value
BIT Number bit number
Returns:
bit value, true or false
Type
Number

getFeed(ID) → {Number}

Get Custom Feed Value
Parameters:
Name Type Description
ID Number Custom Feed ID
Returns:
Value Custom Feed Value
Type
Number
Example
let value = getFeed(0); // Get the value of feed 0 and place it into a variable named value

getUptime() → {Number}

Get device uptime in seconds
Returns:
Uptime in seconds
Type
Number
Example
let uptime = getUptime(); // Uptime = 34322.3231

inputs(Channel) → {Object}

Get analog input value
Parameters:
Name Type Description
Channel Number Analog Input Channel #
Returns:
Object containing all of the channels current values
Type
Object
Example
let input1 = inputs(1);
 // input1 = {"ripple":0.001878,"state":false,"max":0.001997,"min":-0.000126,"inst":0.001106,"avg":0.000976}

mbConnect(host, PORT, ID) → {Number}

Connect to modbus tcp device
Parameters:
Name Type Description
host String Modbus TCP device host, IP or Hostname
PORT Number Modbus TCP Port, Usually 502
ID Number Modbus TCP Unit ID
Returns:
Connection Status, 0 = Success otherwise the response code indicates the connection error.
Type
Number
Example
//Connect to the Tristar
   let err = mbConnect('192.168.1.2', 502, 1);
     if (err === 0) {
        // Perform modbus operations
         mbDisconnect(); // Only disconnect after a sucessful connect
     } else {
       print("Failed to connect to connect to TS device..",err);
       return false;
     }

mbGetReg(REGISTER, FORMAT) → {Number}

Read a Modbus register on a remote device
Parameters:
Name Type Description
REGISTER Number Modbus TCP Register
FORMAT String Format describes the byte order and datatype
Returns:
Operation Status, 0 = Success otherwise the response code indicates the error.
Type
Number
Example
// Run after connection to the remote host



  if(mbGetReg(5,'F32BADC') === 0){ // Get register 5 with type F32
  let value = mbResult(); // mbResult() returns the value of the last modbus operation
  } else {
    print("Error reading modbus register");
  }



   This example demonstrates reading the registers on a remote modbus TCP device
   In our case we set register 3 of type F32 (32 bit IEE Floating point number) with byte order BADC to the value of 2.342

   Valid modbus register type examples include

   	U16 Unsigned 16bit register
   	S16 Signed 16bit register
   	U32 Unsigned 32bit register
   	S32 Signed 32bit register
   	F32 32Bit IEE Floating Point register
    F16 16Bit Half Float register
    COIL coil register
    DISC Discrete Input Register

   Host byte order is set by the letters follwing the data type i.e. S16AB or S32ABCD or F32BACD
   for COIL and DISC type reads and writes use the number of inputs (bits) after the command
   e.g. DISC16 to read 16 discrete inputs. the getBit and setBit functions can then be used to query
   individual bits (inputs, coils etc) in the mbResult
   e.g. getBit(mbResult(),4)); to get bit 4 in the result.

   using DISC1 or COIL1 will return a value of true or false depending on bit 0 of the DISCRETE or COIL input being read

   After executing mbConnect, mbSetReg and mbGetReg return the status of the command, a value of 0
   indicates a successful transaction, any other value indicates the error code.

mbSetReg(REGISTER, FORMAT, VALUE) → {Number}

Set a Modbus register on a remote device
Parameters:
Name Type Description
REGISTER Number Modbus TCP Register
FORMAT String Format describes the byte order and datatype
VALUE Number Value to set the register to
Returns:
Operation Status, 0 = Success otherwise the response code indicates the error.
Type
Number
Example
// Run after connection to the remote host



 if(mbSetReg(3,'F32BADC',2.342) === 0){
     print('Register set successfully');
   } else {
     print("Error setting modbus register");
   }




   This example demonstrates setting the registers on a remote modbus TCP device
   In our case we set register 3 of type F32 (32 bit IEE Floating point number) with byte order BADC to the value of 2.342

   Valid modbus register type examples include

   	U16 Unsigned 16bit register
   	S16 Signed 16bit register
   	U32 Unsigned 32bit register
   	S32 Signed 32bit register
   	F32 32Bit IEE Floating Point register
    F16 16Bit Half Float register
    COIL coil register
    DISC Discrete Input Register

   Host byte order is set by the letters follwing the data type i.e. S16AB or S32ABCD or F32BACD
   for COIL and DISC type reads and writes use the number of inputs (bits) after the command
   e.g. DISC16 to read 16 discrete inputs. the getBit and setBit functions can then be used to query
   individual bits (inputs, coils etc) in the mbResult
   e.g. getBit(mbResult(),4)); to get bit 4 in the result.

   using DISC1 or COIL1 will return a value of true or false depending on bit 0 of the DISCRETE or COIL input being read

   After executing mbConnect, mbSetReg and mbGetReg return the status of the command, a value of 0
   indicates a successful transaction, any other value indicates the error code.

pingprobes(Index) → {Object}

Get Ping Probe Status
Parameters:
Name Type Description
Index Number Ping Probe Index #
Returns:
Object containing all of the power metrics calculated values
Type
Object
Example
let pingProbe0 = pingprobes(0); // Get power metric 0, call it line
 // pingProbe0 = {"latency":19,"lastReachable":0}

powermetrics(Index) → {Object}

Get Power Metric measurements
Parameters:
Name Type Description
Index Number Power Metric Index #
Returns:
Object containing all of the power metrics calculated values
Type
Object
Example
let phaseA = powermetrics(0); // Get power metric 0, call it line
// phaseA = {"thd":3.2,"pf":0.95,"freq":59.8,"voltage":225.34,"current":1.2,"realpower":230.4}

relays(Channel) → {Object}

Get Relay State, Current etc
Parameters:
Name Type Description
Channel Number Relay Channel #
Returns:
Object containing all of the relays current values
Type
Object
Example
let relay1 = relays(1);

 // relay1={"lvd":false,"hvd":false,"fuse":false,"state":false}

run() → {Boolean}

Check script execution flag
Returns:
True or False if the script should continue execution
Type
Boolean
Example
// binding the loop to the run() function allows the Flexs Q5 to stop the script during configuration updates,prevents unexpected behaviour
 while(run()){

   // do stuff
 }

sdAppend(filename, text)

Append Write to a file on the SD Card
Parameters:
Name Type Description
filename String Filename to write to
text String Text to append
Example
// Log channel 3 value
sdAppend('log.txt',JSON.stringify(datetime().epoch) +  ":    ch3: " + JSON.stringify(inputs(3)) + "\n");

setBit(VALUE, BIT, BITVALUE) → {Number}

Set a single bit in a interger number
Parameters:
Name Type Description
VALUE Number input value
BIT Number bit number
BITVALUE Boolean value to set the bit to, TRUE or FALSE
Returns:
new interger value
Type
Number

setEnv(variable, value)

Set Q5 Environment Variable
Parameters:
Name Type Description
variable String System Variable Name
value New value
Example
setEnv('sys.utc_offset',8); // Set UTC offset

setFeed(ID, Value)

Set Custom Feed Value
Parameters:
Name Type Description
ID Number Custom Feed ID
Value Number Value to set the feed to
Example
setFeed(0,3.23); //  Set feed 0 to 3.23

tempsenors(Index) → {Object}

Get Temp Readings
Parameters:
Name Type Description
Index Number Sensor Index # or Sensor UID
Returns:
Object containing the temperature and sensor status
Type
Object
Example
let temp0 = tempsensors(0); // Get Temp sensor index 0, can also request by UID , if no sensors are registered id 0 returns the first connected sensor and id 1 the second etc...
 //temp0 =  {"temp":26.250000,"lastUpdated":4,"avg":26.250000,"inst":26.250000}

waitMS(mS)

Pause script execution
Parameters:
Name Type Description
mS Number Number of mS to wait before continuting code execution
Example
// toggle relay 1 true and false for one second
      setRelay(1,true);
      waitMS(1000);
      setRelay(1,false);
      waitMS(1000);