Common
api.ledControl(state)
- Overview
- Arguments
- Example
Turns ON or OFF the on board LED. It can be also used for debugging purposes.
- state (integer) - sets LED state (1=ON, 0=OFF)
--turns on blue LED
api.ledControl(1)
api.randInt(min, max)
- Overview
- Arguments
- Return
- Example
Generate random number within given range.
- min (integer) - beginning number of the interval
- max (integer) - end number of the interval
- number (Integer)
-- generates random number within interval from 5 to 20
ran=api.randInt(5, 20)
api.getBatteryVoltage()
- Overview
- Return
- Example
Get curent battery voltage in mV.
- voltage (Integer)
--get battery voltage value in mV
mv = api.getBatteryVoltage()
api.dumpArray(str)
- Overview
- Arguments
- Example
Prints contents of variable as hexadecimal string (dumps array into console)
- str (string) - variable to print
--print string "123ef" as hexadecimal
api.dumpArray("123ef")
--OUTPUT 00 : 31 32 33 65 66
api.float(op,form,arg1,arg2)
- Overview
- Arguments
- Return
- Example #1
- Example #2
Performs operation with given floating point data.
Only if it's allowed by the firmware.
- op (string) - The operation to perform (“add” - addition, “sub” - substraction of arg2 from arg1, “mul” - multiplication, “div” - division of arg1 by arg2, “coerce” - coercion, unary operation using only arg1)
- form (string) - Two or three characters specifying the format of input/output data. - first position is for arg1. - second either specifies the format of arg2 or if last, specifies the format of return data, which are the same - by adding “N” to end of a string it coerces and returns little endian integer (OPTIONAL)
- arg1 (string) - The first operation argument, formated as specified in format.
- arg2 (string) - The second operation argument, formated as specified in format.
- result (string, integer) - Returns result of operation, either 4 bytes little endian IEEE 754 float or string float representation or integer value
-- Multiply IEE 754 float with a floating point constant and return coerced value
-- S - string float representation, e.g. “2.234”
-- B - binary little endian IEEE 754 representation as 4 characters/bytes in a string
ret = api.float("mul", "SSN", "12.8", "1000.0")
print(ret)
-- output = 12800
ret = api.float("mul", "SSS", "12.8", "1000.0")
print(ret)
-- output = 12800.0000
-- hexadecimal interpretation of a number 12.8 is 0x414CCCCD (IEE 754)
x=string.char(0xCD,0xCC,0x4C,0x41)
ret = api.float("mul", "BSS", x, "1000.0")
print(ret)
-- output = 12800.0000
api.setVar(index, value)
- Overview
- Arguments
- Example
Saves a persistent variable value, can be used between different wake up iterations.
- index (integer) - Index of the variable to write, 0 to 15 is available for RAM variables (lost on reset), 16 to 47 for High Endurance EEPROM (HEE) variables (6.4M writes) and 48 to 1071 is available for variables stored in EEPROM (100k writes).
- value (integer) - Value to store at index
--set persistent variable value from index 1000 to value of 3424
--can be used to send different data between wake-ups
--for variables persistent between device reset,
--use indexes 48 to 1071
api.setVar(1000, 3424)
api.getVar(index)
- Overview
- Arguments
- Returns
- Example
Returns persistent variable value, can be used between different wake up iterations.
- index (integer) - Index of the variable to read, 0 to 15 is available for RAM variables (lost on reset), 16 to 47 for High Endurance EEPROM (HEE) variables (6.4M writes) and 48 to 1071 is available for variables stored in EEPROM (100k writes).
- value (integer) - Value of the 32bit variable
--get persistent variable value from index 1000
--can be used to send different data between wake-ups
--for variables persistent between device reset,
--use indexes 48 to 1071
slotNumber = api.getVar(1000)