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