Common
This category contains functions that are used for all the devices.
- Overview
- Arguments
- Example
Turns ON or OFF the on board LED.
It can be also used for debugging purposes.
- state (integer) -
1
for ON,0
for OFF
--turns on blue LED
api.ledControl(1)
- Overview
- Arguments
- Examples
Pauses the execution for ms milliseconds.
api.delayms(ms, mode)
- ms (integer) - The number of milliseconds to delay (in range from
0
to2147483647
) - mode (integer, optional) - use sleep in longer intervals:
1
- if the interval ms is longer than 10 ms, sleep2
- sleep for defined amount of milliseconds
api.delayms(1000) --delay one second
api.ledControl(1) -- turn on blue LED
api.delayms(1000) -- wait 1 second
api.ledControl(0) -- turn off blue LED
api.delayms(1000,2) -- sleep for one second, then continue in the process
- Overview
- Arguments
- Return
- Example
Generates random number within given range.
Available only for LoRaWAN devices (function uses it's module to generate random number)
- min (integer) - beginning number of the interval (in range from
0
to2147483647
) - max (integer) - end number of the interval (in range from
0
to2147483647
)
- number (Integer) - Random number within the interval
-- generates random number within interval from 5 to 20
ran=api.randInt(5, 20)
- Overview
- Return
- Example
Generates unique number.
Function increases uint32_t variable by one every time this function is called then it returns it's value. It's in range (in range from 0
to 2^32
)*
- num (integer) - Unique number (in range from
0
to2^32
)*
--get an unique number
num = api.getUniqueNumber()
- Overview
- Return
- Example
Retrieves the current voltage level of the battery in mV.
- voltage (Integer) - Battery voltage level in mV
--get battery voltage value in mV
mv = api.getBatteryVoltage()
- Overview
- Arguments
- Return
- Example
Returns current number of milliseconds since startup.
Counts up to 2^32
and then restarts from 0
. By default it's using RTC derived tick which is incremented during sleep, but it's possible to explicitly select systick, which is not.
api.getTick(clock, reset)
- clock (integer, optional)
3
to use systick, which returns seconds and ms2
to use RTC derived tick and return value in seconds1
to use RTC derived tick and return value in ms (default)0
to use systick (value in ms)
- reset (integer, optional) (if first argument is 0)
1
- reset systick value to 00
- do not reset the systick (default)
- tick (integer) - Value according to argument (in seconds / milliseconds)
--get a timestamp, can be used for timing
timestamp = api.getTick()
-- to show the amount of milliseconds you can use print() function
print(timestamp)
--get a timestamp in ms
ms = api.getTick(1)
--get a timestamp in seconds and ms
seconds, ms = api.getTick(3)
- Overview
- Arguments
- Example
Prints contents of variable as hexadecimal string (dumps array into console).
api.dumpArray(str, opt)
- str (string) - variable to print
- opt (string, optional) - optional argument defining type of print
- "normal" - printing method used by default
- "raw" - prints only the raw values
- "return" - returns the hex string
--print string "123ef" as hexadecimal
api.dumpArray("123ef")
-- output
-- 00 : 31 32 33 65 66
--print string "123ef" as hexadecimal raw
api.dumpArray("123ef","raw")
-- output
-- 31 32 33 65 66
--return string "123ef" as hexadecimal string
ret = api.dump("123ef","return")
- Overview
- Operations
- Arguments
- Return
- Examples
Performs operation with given floating point data.
Only available if it's allowed by the firmware.
- "add" - addition
- "sub" - substraction of
arg2
fromarg1
- "mul" - multiplication
- "div" - division of
arg1
byarg2
- "coerce" - coercion, unary operation using only
arg1
- "convert" - conversion of integer to float, unary operation using only
arg1
- op (string) - The operation to perform
- form (string) - Two or three characters specifying the format of input/output data:
"B"
- binary,"S"
- string,"I"
- integer,"N"
- little endian integer- first position is for
arg1
- second parameter either specifies the format of
arg2
or if it is the last parameter, specifies the format of the return data, as both share the same format - by adding
“N”
to end of a string it coerces and returns little endian integer (optional)
- first position is for
- 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/big endian (depends on form parameter) 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
-- Convert integer to IEE 754 float
-- N - Input in little endian integer(for convert only)/Returns ouput as little endian integer
-- I - Binary little endian integer representation as 4 characters/bytes in a string(for convert only).
-- B - binary little endian IEEE 754 representation as 4 characters/bytes in a string
-- > - returns result as big endian, if used as output IEEE 754 representation as 4 characters/bytes in a string
-- < - returns result as little endian, if used as output IEEE 754 representation as 4 characters/bytes in a string (default value)
y=string.char(0xCD,0xCC,0x4C,0x42)
ret = api.float("convert", "IB", y)
api.dumpArray(ret)
-- output = 9A 99 84 4E
y=125
ret = api.float("convert", "NB>", y)
api.dumpArray(ret)
-- output = 42 FA 00 00
- Overview
- Arguments
- Examples
Saves a persistent variable value.
Can be used between different wake up iterations.
api.setVar(index, value, bool)
- index (integer) - Index of the variable to write, index
0
to15
is available for RAM variables (lost on reset), index16
to47
for High Endurance EEPROM (HEE) variables (6.4M writes) and index48
to1071
is available for variables stored in EEPROM (100k writes). - value (integer) - Value to store at index (in range from
0
to2147483647
) - bool (boolean, optional) - Optional argument, which stores bitwise negation of stored value into address higher by one
api.setVar(index, mode, value)
- index (integer) - Index of the variable to write, index
0
to15
is available for RAM variables (lost on reset), index16
to47
for High Endurance EEPROM (HEE) variables (6.4M writes) and index48
to1071
is available for variables stored in EEPROM (100k writes). - mode (string) - Explicit memory mode, currently
"bytes"
mode supported - value (string) - String array buffer to write
--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)
myVariable = "This is some string to store to eeprom"
api.setVar(29, #myVariable) -- save the length for later readout
api.setVar(30, "bytes", myVariable) -- consumes in total ceil(#myVariable / 4) 32-bit indexes in EEPROM/RAM/HEE
- Overview
- Arguments
- Returns
- Examples
Returns persistent variable value.
Can be used between different wake up iterations.
api.getVar(index, default)
- index (integer) - Index of the variable to read,
0
to15
is available for RAM variables (lost on reset),16
to47
for High Endurance EEPROM (HEE) variables (6.4M writes) and48
to1071
is available for variables stored in EEPROM (100k writes). - default (integer, optional) - Default value, which is returned if value stored in the address is same as bitwise negation of value stored in address higher by one
api.getVar(index, mode, length)
- index (integer) - Index of the variable to read,
0
to15
is available for RAM variables (lost on reset),16
to47
for High Endurance EEPROM (HEE) variables (6.4M writes) and48
to1071
is available for variables stored in EEPROM (100k writes). - mode (string) - Mode to use, currently supported
"bytes"
- length (integer) - Length in bytes to read
- value (integer)(string) - Value of the 32bit variable, or string.
--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)
stringLength = api.getVar(29)
myReadout = api.getVar(30, "bytes", stringLength)
print(myReadout) -- should print "myVariable" content!
- Overview
- Arguments
- Return
- Example
Schedules the next wake up event of the device to provided day
of month, hour
, minute
and second
.
The provided wake up date is therefore absolute and not relative as in api.wakeUpIn()
.
api.wakeUpAt(day, hour, minute, second, resetOnFail)
- day (integer) - Day of month, range from
1
to31
- hour (integer) - Hour, range from
0
to23
- minute (integer) - Minute, range from
0
to59
- second (integer) - Second, range from
0
to59
- resetOnFail (integer, optional) - Reboot device when setting of wake-up event failed:
1
- true,0
or nothing - false
- status (integer) - Execution status, zero for success and
-1
for error
--schedules next wake up to the 25th, 2:22:58
status = api.wakeUpAt(25, 2, 22, 58)
- Overview
- Arguments
- Return
- Example
Schedules the next wake up event of the device after specified time interval.
The provided wake up date is therefore relative and not absolute as in api.wakeUpAt()
.
The input arguments are not limited, but the total period specified must not exceed 31 days. (e.g. hour
= 40, days
= 2 gives a period of 3 days and 16 hours).
- day (integer) - Day, range from
0
to31
- hour (integer) - Hour, range (in range from
0
to2147483647
) - minute (integer) - Minute, range (in range from
0
to2147483647
) - second (integer) - Second, range (in range from
0
to2147483647
) - resetOnFail (integer, optional) - Reboot device when setting of wake-up event failed:
1
- true,0
or nothing - false - millisecond (integer, optional) - Millisecond, range (in range from
0
to2147483647
)
- status (integer) - Execution status,
0
for success and-1
for error
--schedules next wake up in 1 day and 122 minutes
status = api.wakeUpIn(1, 0, 122, 0)
- Overview
- Return
- Example
Returns current date and time set on this device.
The time can be synchronized over LoRa, or when uploading LUA script using LUA scripting interface.
api.getTimeDate(timezone)
- timezone (integer, optional) - Return time zone shift:
1
- ON,0
- OFF
- year (integer) - Current year
- month (integer) - Current month
- day (integer) - Current day of month
- hour (integer) - Current hour
- minute (integer) - Current minute
- second (integer) - Current second
- time zone shift (integer, optional) - Time zone shift in minutes
--read current date and time
y,M,d,h,m,s = api.getTimeDate()
- Overview
- Arguments
- Example
Set date and time on this device, or calculate the difference and synchronize the date and time.
api.setTimeDate(year, month, day, hour, minute, second, subsecond, timezone)
- year (integer) - Range from
2016
to any value greater than2016
- month (integer) - Range from
1
to12
- day (integer) - Range from
1
to31
- hour (integer) - Range from
0
to23
- minute (integer) - Range from
0
to59
- second (integer) - Range from
0
to59
- subsecond (integer, optional)
- timezone (integer, optional) - Time zone shift in minutes
api.setTimeDate("DIFF", day, hour, minute, second)
- day (integer) - Range from
1
to31
- hour (integer) - Range from
0
to23
- minute (integer) - Range from
0
to59
- second (integer) - Range from
0
to59
Calculate and check date based on given values, if there is a difference, synchronize.
--set date and time
api.setTimeDate(2022, 1, 31, 23, 59, 0)