Skip to content

Byte and String Handling

Name Input Params Return Data Description
resiot_appbyte BYTE [ ], BYTE BYTE [ ] Appends a byte at the end of a byte array
resiot_apps2ba BYTE [ ], String BYTE [ ] Appends a string at the end of a byte array
resiot_b2str BYTE String Convert a single byte into a String
resiot_ba2str BYTE [ ] String Convert array bytes into String
resiot_base64encode BYTE [ ] base64 String Encode array bytes into a base64 encoded String
resiot_base64decode base64 String BYTE [ ], String Decode an input base64 encoded String into a Byte array
resiot_base64decode_ascii base64 String String, String Decode an input base64 encoded String into a clear String
resiot_baslice BYTE [ ], Integer, Integer BYTE [ ] Slice the array bytes from a starting index Start to an ending index End
resiot_byarrlen BYTE [ ] Integer Calculate the array bytes length
resiot_bytearrayconcat BYTE [ ], BYTE [ ]... BYTE [ ] Concatenate all the extra Bytes and Bytes arrays with the main one MainBytes
resiot_crc1145 BYTE [ ] BYTE [ ] Calculate the Checksum of the bytes array
resiot_hexencode BYTE [ ] Hex String Convert an input bytes array into a Hexadecimal string
resiot_hexdecode Hex String BYTE [ ], String Decode an Hexadecimal string into a Byte array
resiot_hexdecode_ascii Hex String String, String Decode an Hexadecimal string into a clear String
resiot_i2nbl Integer, Integer BYTE [ ] Convert an Integer value into a byte of length n
resiot_int2byte Integer BYTE [ ] Convert an Integer value
resiot_ba2intBE16 BYTE [ ] Integer Convert an input bytes array into an Integer
resiot_ba2sintBE16 BYTE [ ] Integer Convert an input bytes array into a signed Integer
resiot_ba2intBE32 BYTE [ ] Integer Convert an input bytes array into an Integer
resiot_ba2intLE16 BYTE [ ] Integer Convert an input bytes array into an Integer
resiot_ba2intLE32 BYTE [ ] Integer Convert an input bytes array into an Integer
resiot_readbit BYTE, Integer Boolean Check if the Byte at Index is 0 or 1
resiot_and BYTE, BYTE BYTE Execute the AND operation between two Bytes
resiot_and64 Integer, Integer Integer Execute the AND operation between two int64 numbers
resiot_andnot BYTE, BYTE BYTE Filter and use only the bit at 1 of the first Byte
resiot_or BYTE, BYTE BYTE Execute the OR operation between two Bytes
resiot_or64 Integer, Integer Integer Execute the OR operation between two int64 numbers
resiot_xor BYTE, BYTE BYTE Execute the XOR operation between two Bytes
resiot_float322baBE Float BYTE [ ] Convert a Float value into a bytes array
resiot_float322baLE Float BYTE [ ] Convert a Float value into a bytes array
resiot_float642baBE Float BYTE [ ] Convert a Float value into a bytes array
resiot_float642baLE Float BYTE [ ] Convert a Float value into a bytes array
resiot_ba2float64BE BYTE [ ] Float Convert an input bytes array into a Float
resiot_ba2float64LE BYTE [ ] Float Convert an input bytes array into a Float
resiot_ba2float32BE BYTE [ ] Float Convert an input bytes array into a Float
resiot_ba2float32LE BYTE [ ] Float Convert an input bytes array into a Float
resiot_ba2float16BE BYTE [ ] Float Convert an input bytes array into a half-precision Float
resiot_ba2float16LE BYTE [ ] Float Convert an input bytes array into a half-precision Float
resiot_ba2int8 BYTE Integer Convert an input byte into a Integer
resiot_int32 Integer Integer Convert an Unsigned Int32 into a Signed Int32
resiot_int16 Integer Integer Convert an Unsigned Int16 into a Signed Int16
resiot_sprintf String, String... String Formats a string with the given parameters
resiot_encrypt String, String, String, String, String String, String Encrypts hex encoded data with the provided cipher/cipher mode and keys
resiot_encryptraw String, String, String, String, String String, String Encrypts data with the provided cipher/cipher mode and keys
resiot_split String, String String [ ] Slices the string into all substrings separated by separator and returns a slice of the substrings between those separators

resiot_appbyte(BYTE [ ], BYTE)

Appends a byte at the end of a byte array.
Example
ArrReturn = resiot_appbyte(ArrByte, Byte)
Input Parameters
 - ArrByte (BYTE [ ]): * The original byte array.
 - Byte (BYTE): * A byte to append at the end of ArrByte.

Returns
 - ArrReturn (BYTE [ ]): * A new array with Byte appended to ArrByte. *

ArrByte = {0xB3, 0xC2, 0xFF}    -- The original byte array
Byte = 0xC5                     -- A byte to append at the end of ArrByte
ArrReturn = resiot_appbyte(ArrByte, Byte)
resiot_debug(ArrReturn)
-- 
-- In This case:
-- 
-- ArrReturn = {0xB3, 0xC2, 0xFF, 0xC5}
-- 

Return to index


resiot_apps2ba (BYTE [ ], String)

Appends a string at the end of a byte array.
Example
ArrReturn = resiot_apps2ba(ArrByte, String)
Input Parameters
 - ArrByte (BYTE [ ]): * The original byte array.
 - String (String): * A string to append at the end of ArrByte.

Returns
 - ArrReturn (BYTE [ ]): * The function returns a new array with String appended to ArrByte. *

ArrByte = {0xB3, 0xC2, 0xFF}    -- The original byte array
String = "d"                    -- A string to append, "d" = 0x64
ArrReturn = resiot_apps2ba(ArrByte, String)
resiot_debug(ArrReturn)
-- 
-- In This case:
-- 
-- ArrReturn = {0xB3, 0xC2, 0xFF, 0x64}
-- 

Return to index


resiot_b2str(BYTE)

Convert a single byte into a String.
Example
String = resiot_b2str(Byte)
Input Parameters
 - Byte (BYTE): * The byte to convert.
Returns
 - String (String): * The function returns the single byte converted into a String.

Byte = 0x64             -- The byte to convert
String = resiot_b2str(Byte)
resiot_debug(String)
-- 
-- In This case:
-- 
-- String = "d"
-- 

Return to index


resiot_ba2str(BYTE [ ])

Convert an array of bytes into String.
Example
String = resiot_ba2str(ArrByte)
Input Parameters
 - ArrByte (BYTE [ ]): * The bytes to convert.
Returns
 - String (String): * The function returns the array of bytes converted into String.

ArrByte = {0x50, 0x52, 0x55}        -- The bytes to convert
String = resiot_ba2str(ArrByte)
resiot_debug(String)
-- 
-- In This case:
-- 
-- String = "PRU"
-- 

Return to index


resiot_base64encode(BYTE [ ])

Encode array bytes into a base64 String.
Example
EncodedString = resiot_base64encode(ArrByte)
Input Parameters
 - ArrByte (BYTE [ ]): * The bytes to encode. * Returns
 - EncodedString (String): * The function returns the array bytes encoded into a base64 String. *

ArrByte = {0x50, 0x52, 0x55}            -- The bytes to encode
EncodedString = resiot_base64encode(ArrByte)
resiot_debug(EncodedString)
-- 
-- In This case:
-- 
-- EncodedString = {"UFJV"}
-- 

Return to index


resiot_base64decode(String)

Decode an input base64 encoded String into a Byte array.
Example
ArrByte, Error = resiot_base64decode(EncodedString)
Input Parameters
 - EncodedString (String): * The string to decode.
Returns
 - ArrByte (BYTE [ ]): * The function returns the encoded string decoded into a Byte array.

 - Error (String): * The error if it occurs. *

EncodedString = "SGVsbG8gd29ybGQh"      -- The string to decode
ArrByte, Error = resiot_base64decode(EncodedString)
if Error ~= "" then
    -- error 
    resiot_debug(Error)
else
    -- value read correctly
    resiot_debug(ArrByte)
end

Return to index


resiot_base64decode_ascii(String)

Decode an input base64 encoded String into a clear String.
Example
Response, Error = resiot_base64decode_ascii(EncodedString)
Input Parameters
 - EncodedString (String): * The string to decode.
Returns
 - Response (String): * The function returns the encoded string decoded into a clear string.

 - Error (String): * The error if it occurs. *

EncodedString = "SGVsbG8gd29ybGQh"      -- The string to decode
Response, Error = resiot_base64decode_ascii(EncodedString)
if Error ~= "" then
    -- error 
    resiot_debug(Error)
else
    -- value read correctly
    resiot_debug(Response)
end

Return to index


resiot_baslice(BYTE [ ], Integer, Integer)

Slice the array bytes from a starting index Start to an ending index End.
Example
ArrReturn = resiot_baslice(ArrByte, Start, End)
Input Parameters
 - ArrByte (BYTE [ ]): * The bytes array to slice.
 - Start (Integer): * The int index where the slice start.

 - End (Integer): * The int index where the slice end.
Returns
 - ArrReturn (BYTE [ ]): * The function returns the array bytes sliced from Start to End.

ArrByte = {0x50, 0x52, 0x55, 0x33, 0x97, 0x85}  -- The bytes array to slice
Start = 1                                       -- The int index where the slice start
End = 3                                         -- The int index where the slice end
ArrReturn = resiot_baslice(ArrByte, Start, End)
resiot_debug(ArrReturn)
-- 
-- In This case:
-- 
-- ArrReturn = {0x52, 0x55}
-- 

Return to index


resiot_byarrlen(BYTE [ ])

Calculate the array bytes length.
Example
Length = resiot_byarrlen(ArrByte)
Input Parameters
 - ArrByte (BYTE [ ]): * The bytes array.
Returns
 - Length (Integer): * The function returns the array bytes length as int.

ArrByte = {0x50, 0x43, 0x31}    -- The bytes array
Length = resiot_byarrlen(ArrByte)
resiot_debug(Length)
-- 
-- In This case:
-- 
-- Length = 3
-- 

Return to index


resiot_bytearrayconcat(BYTE [ ], BYTE [ ]...)

Concatenate all the extra Bytes and Bytes arrays with the main one MainBytes.
Example
ArrReturn = resiot_bytearrayconcat(MainByte, ByteN...)
Input Parameters
 - MainBytes (BYTE [ ]): * The main bytes array.
 - ByteN (BYTE [ ]): * All the bytes arrays passed in.

Returns
 - ArrReturn (BYTE [ ]): * The function returns the concatenation of all the bytes arrays passed in ByteN with the main bytes array MainBytes as an array of bytes. *

MainByte = {0x50}       -- The main bytes array
Byte1 = {0x54}          -- All the bytes arrays passed in
Byte2 = {0x12}
Byte3 = {0x76}
ArrReturn = resiot_bytearrayconcat(MainByte, Byte1, Byte2, Byte3)
resiot_debug(ArrReturn)
-- 
-- In This case:
-- 
-- ArrReturn = {0x50, 0x54, 0x12, 0x76}
-- 

Return to index


resiot_crc1145(BYTE [ ])

Calculate the Checksum of the bytes array.
Example
Checksum = resiot_crc1145(Bytes)
Input Parameters
 - Bytes (BYTE [ ]): * The bytes array.
Returns
 - Checksum (BYTE [ ]): * The function returns the Checksum of the bytes array passed in Byte as a RFC 1145 standard in a bytes array.

Bytes = {0x43}              -- The bytes array
Checksum = resiot_crc1145(Bytes)
resiot_debug(Checksum)
-- 
-- In This case:
-- 
-- Checksum = {0x79 0x43}
-- 

Return to index


resiot_hexencode(BYTE [ ])

Convert an input bytes array into a Hexadecimal string.
Example
EncodedString = resiot_hexencode(ArrByte)
Input Parameters
 - ArrByte (BYTE [ ]): * The bytes array to convert.
Returns
 - EncodedString (String): * The function returns the input bytes array ArrByte converted into a hexadecimal string.

ArrByte = {0x21, 0x54, 0x87}        -- The bytes array to convert
EncodedString = resiot_hexencode(ArrByte)
resiot_debug(EncodedString)
-- 
-- In This case:
-- 
-- EncodedString = "215487"
-- 

Return to index


resiot_hexdecode(String)

Decode an Hexadecimal string into a Byte array.
Example
ArrByte, Error = resiot_hexdecode(EncodedString)
Input Parameters
 - EncodedString (String): * The string to decode.
Returns
 - ArrByte (BYTE [ ]): * The function returns string decoded into a Byte array.

 - Error (String): * The error if it occurs. *

EncodedString = "48656C6C6F20776F726C6421"      -- The string to decode
ArrByte, Error = resiot_hexdecode(EncodedString)
if Error ~= "" then
    -- error 
    resiot_debug(Error)
else
    -- value read correctly
    resiot_debug(ArrByte)
end

Return to index


resiot_hexdecode_ascii(String)

Decode an Hexadecimal string into a clear String.
Example
Response, Error = resiot_hexdecode_ascii(EncodedString)
Input Parameters
 - EncodedString (String): * The string to decode.
Returns
 - Response (String): * The function returns string decoded into a clear String.

 - Error (String): * The error if it occurs. *

EncodedString = "48656C6C6F20776F726C6421"      -- The string to decode
Response, Error = resiot_hexdecode_ascii(EncodedString)
if Error ~= "" then
    -- error 
    resiot_debug(Error)
else
    -- value read correctly
    resiot_debug(Response)
end

Return to index


resiot_i2nbl(Integer, Integer)

Convert an Integer value into a byte of length n.
Example
ArrByte = resiot_i2nbl(Value, Length)
Input Parameters
 - Value (Integer): * The Integer value.
 - Length (Integer): * The length of the byte.

Returns
 - ArrByte (BYTE [ ]): * The value of Int convert into a byte of length n. *

Value = 246         -- The Integer value
Length = 2          -- The length of the byte
ArrByte = resiot_i2nbl(Value, Length)
resiot_debug(ArrByte)
-- 
-- In This case:
-- 
-- ArrByte = {0x00, 0xF6}
-- 

Return to index


resiot_int2byte(Integer)

Convert an Integer value.
Example
Byte = resiot_int2byte(Value)
Input Parameters
 - Value (Integer): * The Integer value.
Returns
 - Byte (BYTE [ ]): * The value of Int convert into a byte.

Value = 179         -- The Integer value
Byte = resiot_int2byte(Value)
resiot_debug(Byte)
-- 
-- In This case:
-- 
-- Byte = {0xB3}
-- 

Return to index


resiot_ba2intBE16(BYTE [ ])

Convert an input bytes array into an Integer.
Need an input of 2 Bytes in format Big Endian.
Example
Value = resiot_ba2intBE16(ArrByte)
Input Parameters
 - ArrByte (BYTE [ ]): * The bytes array to convert.
Returns
 - Value (Integer): * The value of ArrByte convert into an Integer.

ArrByte = {0x00, 0xFF}      -- The bytes array to convert
Value = resiot_ba2intBE16(ArrByte)
resiot_debug(Value)
-- 
-- In This case:
-- 
-- Value = 255
-- 

Return to index


resiot_ba2sintBE16(BYTE [ ])

Convert an input bytes array into a signed Integer.
Need an input of 2 Bytes in format Big Endian.
Example
Value = resiot_ba2sintBE16(ArrByte)
Input Parameters
 - ArrByte (BYTE [ ]): * The bytes array to convert.
Returns
 - Value (Integer): * The value of ArrByte convert into an Integer.

ArrByte = {0x00, 0xFF}      -- The bytes array to convert
Value = resiot_ba2sintBE16(ArrByte)
resiot_debug(Value)
-- 
-- In This case:
-- 
-- Value = 255
-- 

Return to index


resiot_ba2intBE32(BYTE [ ])

Convert an input bytes array into an Integer.
Need an input of 4 Bytes in format Big Endian.
Example
Value = resiot_ba2intBE32(ArrByte)
Input Parameters
 - ArrByte (BYTE [ ]): * The bytes array to convert.
Returns
 - Value (Integer): * The value of ArrByte convert into an Integer.

ArrByte = {0x00, 0x02, 0x32, 0XFF}      -- The bytes array to convert
Value = resiot_ba2intBE32(ArrByte)
resiot_debug(Value)
-- 
-- In This case:
-- 
-- Value = 144127
-- 

Return to index


resiot_ba2intLE16(BYTE [ ])

Convert an input bytes array into an Integer
Need an input of 2 Bytes in format Little Endian
Example
Value = resiot_ba2intLE16(ArrByte)
Input Parameters
 - ArrByte (BYTE [ ]): the bytes array to convert
Returns
 - Value (Integer): The value of ArrByte convert into an Integer

ArrByte = {0xFF, 0x00}          -- The bytes array to convert
Value = resiot_ba2intLE16(ArrByte)
resiot_debug(Value)
-- 
-- In This case:
-- 
-- Value = 255
-- 

Return to index


resiot_ba2intLE32(BYTE [ ])

Convert an input bytes array into an Integer.
Need an input of 4 Bytes in format Little Endian.
Example
Value = resiot_ba2intLE32(ArrByte)
Input Parameters
 - ArrByte (BYTE [ ]): * The bytes array to convert.
Returns
 - Value (Integer): * The value of ArrByte convert into an Integer.

ArrByte = {0XFF, 0x32, 0x02, 0x00}      -- The bytes array to convert
Value = resiot_ba2intLE32(ArrByte)
resiot_debug(Value)
-- 
-- In This case:
-- 
-- Value = 144127
-- 

Return to index


resiot_readbit(BYTE, Integer)

Check if the Bit at Index is 0 or 1.
Example
ReturnBit = resiot_readbit(Byte, Index)
Input Parameters
 - Byte (BYTE): * The byte.
 - Index (Integer): * The index of the byte to check It must be between 0 and 7.

Returns
 - ReturnBit (Boolean): * The function returns true if the checked byte is 1 or false if it is 0. *

Byte = 0xb3     -- The byte
Index = 2       -- The index of the bit to check. It must be between 0 and 7
ReturnBit = resiot_readbit(Byte, Index)
resiot_debug(ReturnBit)
-- 
-- In This case:
-- 
-- 0xb3 = 1 0 1 1 0 0 1 1
--        0 1 2 3 4 5 6 7
-- 
-- The Bit at index 2 is 1, so:
-- 
-- ReturnBit = true
-- 

Return to index


resiot_and(BYTE, BYTE)

Execute the AND operation between two Bytes.
Example
ReturnByte = resiot_and(Byte1, Byte2)
Input Parameters
 - Byte1, Byte2 (BYTE): * The two bytes.
Returns
 - ReturnByte (BYTE): * The function returns the Byte that result by doing the AND operation between the two given Bytes.

local Byte1 = 0x24      -- The two bytes
local Byte2 = 0x21
ReturnByte = resiot_and(Byte1, Byte2)
resiot_debug(ReturnByte)
-- 
-- In This case:
-- 
-- Byte1        = 0 0 1 0 0 1 0 0 = 0x24
-- Byte2        = 0 0 1 0 0 0 0 1 = 0x21
-- 
-- So:          ------------------------
-- 
-- ReturnByte   = 0 0 1 0 0 0 0 0 = 0x20
-- 

Return to index


resiot_and64(Integer, Integer)

Execute the AND operation between two int64 numbers.
Example
ReturnNum = resiot_and64(Num1, Num2)
Input Parameters
 - Num1, Num2 (Integer): * The two numbers.
Returns
 - ReturnNum (Integer): * The function returns the Int that results by doing the AND operation between the two given numbers.

local Num1 = 0x24EF309A     -- The two numbers
local Num2 = 0x21DEAE44
ReturnNum = resiot_and64(Num1, Num2)
resiot_debug(ReturnNum)

Return to index


resiot_andnot(BYTE, BYTE)

Filter and use only the bit at 1 of the first Byte.
Example
ReturnByte = resiot_andnot(Byte1, Byte2)
Input Parameters
 - Byte1, Byte2 (BYTE): * The two bytes.
Returns
 - ReturnByte (BYTE): * The function returns a Byte with the bits at 1 only when the first Byte is the only one that has those bits at 1.

local Byte1 = 0x24      -- The two bytes
local Byte2 = 0x21
ReturnByte = resiot_andnot(Byte1, Byte2)
resiot_debug(ReturnByte)
-- 
-- In This case:
-- 
-- Byte1        = 0 0 1 0 0 1 0 0 = 0x24
-- Byte2        = 0 0 1 0 0 0 0 1 = 0x21
-- 
-- So:          ------------------------
-- 
-- ReturnByte   = 0 0 0 0 0 1 0 0 = 0x04
-- 

Return to index


resiot_or(BYTE, BYTE)

Execute the OR operation between two Bytes.
Example
ReturnByte = resiot_or(Byte1, Byte2)
Input Parameters
 - Byte1, Byte2 (BYTE): * The two bytes.
Returns
 - ReturnByte (BYTE): * The function returns the Byte that result by doing the OR operation between the two given Bytes.

local Byte1 = 0x24      -- The two bytes
local Byte2 = 0x21
ReturnByte = resiot_or(Byte1, Byte2)
resiot_debug(ReturnByte)
-- 
-- In This case:
-- 
-- Byte1        = 0 0 1 0 0 1 0 0 = 0x24
-- Byte2        = 0 0 1 0 0 0 0 1 = 0x21
-- 
-- So:          ------------------------
-- 
-- ReturnByte   = 0 0 1 0 0 1 0 1 = 0x25
-- 

Return to index


resiot_or64(Integer, Integer)

Execute the OR operation between two int64 numbers.
Example
ReturnInt = resiot_or64(Num1, Num2)
Input Parameters
 - Num1, Num2 (Integer): * The two numbers.
Returns
 - ReturnInt (Integer): * The function returns the Int that results by doing the OR operation between the two given numbers.

local Num1 = 0x24EF309A     -- The two numbers
local Num2 = 0x21DEAE44
ReturnInt = resiot_or64(Num1, Num2)
resiot_debug(ReturnInt)

Return to index


resiot_xor(BYTE, BYTE)

Execute the XOR operation between two Bytes.
Example
ReturnByte = resiot_xor(Byte1, Byte2)
Input Parameters
 - Byte1, Byte2 (BYTE): * The two bytes.
Returns
 - ReturnByte (BYTE): * The function returns the Byte that result by doing the XOR operation between the two given Bytes.

local Byte1 = 0x24      -- The two bytes
local Byte2 = 0x21
ReturnByte = resiot_xor(Byte1, Byte2)
resiot_debug(ReturnByte)
-- 
-- In This case:
-- 
-- Byte1        = 0 0 1 0 0 1 0 0 = 0x24
-- Byte2        = 0 0 1 0 0 0 0 1 = 0x21
-- 
-- So:          ------------------------
-- 
-- ReturnByte   = 0 0 0 0 0 1 0 1 = 0x05
-- 

Return to index


resiot_float322baBE(Float)

Convert a Float value into a bytes array.
It gives back a Byte Array with the Big Endian format.
Example
ArrByte = resiot_float322baBE(Float)
Input Parameters
 - Float (Float): * The Float number to convert.
Returns
 - ArrByte (BYTE [ ]): * The value of Float convert into a Byte Array in Big Endian format.

Float = 1.5     -- The Float number to convert
ArrByte = resiot_float322baBE(Float)
resiot_debug(ArrByte)
-- 
-- In This case:
-- 
-- ArrByte = {0x3F, 0xC0, 0x00, 0x00}
-- 

Return to index


resiot_float322baLE(Float)

Convert a Float value into a bytes array.
It gives back a Byte Array with the Little Endian format.
Example
ArrByte = resiot_float322baLE(Float)
Input Parameters
 - Float (Float): * The Float number to convert.
Returns
 - ArrByte (BYTE [ ]): * The value of Float convert into a Byte Array in Little Endian format.

Float = 1.5     -- The Float number to convert
ArrByte = resiot_float322baLE(Float)
resiot_debug(ArrByte)
-- 
-- In This case:
-- 
-- ArrByte = {0x00, 0x00, 0xC0, 0x3F}
-- 

Return to index


resiot_float642baBE(Float)

Convert a Float value into a bytes array.
It gives back a Byte Array with the Big Endian format.
Example
ArrByte = resiot_float642baBE(Float)
Input Parameters
 - Float (Float): * The Float number to convert.
Returns
 - ArrByte (BYTE [ ]): * The value of Float convert into a Byte Array in Big Endian format.

Float = 1.5     -- The Float number to convert
ArrByte = resiot_float642baBE(Float)
resiot_debug(ArrByte)
-- 
-- In This case:
-- 
-- ArrByte = {0x3F, 0xF8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
-- 

Return to index


resiot_float642baLE(Float)

Convert a Float value into a bytes array.
It gives back a Byte Array with the Little Endian format.
Example
ArrByte = resiot_float642baLE(Float)
Input Parameters
 - Float (Float): * The Float number to convert.
Returns
 - ArrByte (BYTE [ ]): * The value of Float convert into a Byte Array in Little Endian format.

Float = 1.5     -- The Float number to convert
ArrByte = resiot_float642baLE(Float)
resiot_debug(ArrByte)
-- 
-- In This case:
-- 
-- ArrByte = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF8, 0x3F}
-- 

Return to index


resiot_ba2float64BE(BYTE [ ])

Convert an input bytes array into a Float.
Needs in input an Array of Bytes with the Big Endian format.
Example
Value = resiot_ba2float64BE(ArrByte)
Input Parameters
 - ArrByte (BYTE [ ]): * The bytes array to convert.
Returns
 - Value (Float): * The value of ArrByte convert into a Float.

ArrByte = {0x3F, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}      -- The bytes array to convert
Value = resiot_ba2float64BE(ArrByte)
resiot_debug(Value)
-- 
-- In This case:
-- 
-- Value = 1.5
-- 

Return to index


resiot_ba2float64LE(BYTE [ ])

Convert an input bytes array into a Float.
Needs in input an Array of Bytes with the Big Endian format.
Example
Value = resiot_ba2float64LE(ArrByte)
Input Parameters
 - ArrByte (BYTE [ ]): * The bytes array to convert.
Returns
 - Value (Float): * The value of ArrByte convert into a Float.

ArrByte = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0x3F}      -- The bytes array to convert
Value = resiot_ba2float64LE(ArrByte)
resiot_debug(Value)
-- 
-- In This case:
-- 
-- Value = 1.5
-- 

Return to index


resiot_ba2float32BE(BYTE [ ])

Convert an input bytes array into a Float.
Needs in input an Array of Bytes with the Big Endian format.
Example
Value = resiot_ba2float32BE(ArrByte)
Input Parameters
 - ArrByte (BYTE [ ]): * The bytes array to convert.
Returns
 - Value (Float): * The value of ArrByte convert into a Float.

ArrByte = {0x3F, 0xC0, 0x00, 0x00}      -- The bytes array to convert
Value = resiot_ba2float32BE(ArrByte)
resiot_debug(Value)
-- 
-- In This case:
-- 
-- Value = 1.5
-- 

Return to index


resiot_ba2float32LE(BYTE [ ])

Convert an input bytes array into a Float.
Needs in input an Array of Bytes with the Little Endian format.
Example
Value = resiot_ba2float32LE(ArrByte)
Input Parameters
 - ArrByte (BYTE [ ]): * The bytes array to convert.
Returns
 - Value (Float): * The value of ArrByte convert into a Float.

ArrByte = {0x00, 0x00, 0xC0, 0x3F}      -- The bytes array to convert
Value = resiot_ba2float32LE(ArrByte)
resiot_debug(Value)
-- 
-- In This case:
-- 
-- Value = 1.5
-- 

Return to index


resiot_ba2float16BE(BYTE [ ])

Convert an input bytes array into a half-precision Float.
Needs in input an Array of Bytes with the Big Endian format.
Example
Value = resiot_ba2float16BE(ArrByte)
Input Parameters
 - ArrByte (BYTE [ ]): * The bytes array to convert.
Returns
 - Value (Float): * The value of ArrByte converted into a half-precision Float.

ArrByte = {0x3C,0xFF}       -- The bytes array to convert
Value = resiot_ba2float16BE(ArrByte)
resiot_debug(Value)
-- 
-- In This case:
-- 
-- Value = 1.2490234375
-- 

Return to index


resiot_ba2float16LE(BYTE [ ])

Convert an input bytes array into a half-precision Float.
Needs in input an Array of Bytes with the Little Endian format.
Example
Value = resiot_ba2float16LE(ArrByte)
Input Parameters
 - ArrByte (BYTE [ ]): * The bytes array to convert.
Returns
 - Value (Float): * The value of ArrByte converted into a half-precision Float.

ArrByte = {0xFF,0x3C}       -- The bytes array to convert
Value = resiot_ba2float16LE(ArrByte)
resiot_debug(Value)
-- 
-- In This case:
-- 
-- Value = 1.2490234375
-- 

Return to index


resiot_ba2int8(BYTE)

Convert an input byte into a Integer.
Needs in input a Byte.
Example
Value = resiot_ba2int8(Byte)
Input Parameters
 - Byte (BYTE): * The byte to convert.
Returns
 - Value (Integer): * The value of the Byte convert into a Integer.

Byte = 0x0F     -- The byte to convert
Value = resiot_ba2int8(Byte)
resiot_debug(Value)
-- 
-- In This case:
-- 
-- Value = 15
-- 

Return to index


resiot_int32(Integer)

Convert an input Unsigned Int32 into a Signed Int32.
Example
Value = resiot_int32(UInt32)
Input Parameters
 - UInt32 (Integer): * The Unsigned Int32 to convert.
Returns
 - Value (Integer): * The value of the Unsigned Int32 convert into a Signed Int32.

UInt32 = 3.192006165e+09        -- The Unsigned Int32 to convert
Value = resiot_int32(UInt32)
resiot_debug(Value)
-- 
-- In This case:
-- 
-- Value = -1.102961131e+09
-- 

Return to index


resiot_int16(Integer)

Convert an input Unsigned Int16 into a Signed Int16.
Example
Value = resiot_int16(UInt16)
Input Parameters
 - UInt16 (Integer): * The Unsigned Int16 to convert.
Returns
 - Value (Integer): * The value of the Unsigned Int16 convert into a Signed Int16.

UInt16 = 3.192006165e+09        -- The Unsigned Int16 to convert
Value = resiot_int16(UInt16)
resiot_debug(Value)
-- 
-- In This case:
-- 
-- Value = -1.102961131e+09
-- 

Return to index


resiot_sprintf (String, Various...)

Formats a string with the given arguments.
This function is based on Golang's string formatting, see more here.
Example
No return values | resiot_debugf(String)
Input Parameters
 - String (String): * The string to format.
 - Various... (Various): * The arguments to be used in the formatting.

Returns
 - Value (String): * The formatted string. *

test = "hey"
a = resiot_sprintf("%v", test) -- a = "hey"
a = resiot_sprintf("%s", "Hello World!") -- a = "Hello World!"
a = resiot_sprintf("%v %v", "Lorem Ipsum", 25) -- a = "Lorem Ipsum 25"
a = resiot_sprintf("%.4f", 25.252525252525) -- a = "25.2525"

Return to index


resiot_encrypt (String, String, String, String, String)

Encrypts an hex encoded message with the provided cipher, cipher mode algorithm. All the provided data needs to be hex encoded.
Currently, only AES CMAC is supported
Input Parameters
 - String (String): * The cipher to use.
 - String (String): * The cipher mode to use.

 - String (String): * The hex encoded message to encrypt.
 - String (String): * The hex encoded IV to encrypt the message.

 - String (String): * The hex encoded KEY to encrypt the message.
Returns
 - String (String): * The hex encoded encrypted data

 - String (String): * If not empty, the error that occurred during the encryption *

message = "21308618b000d8782000000000000000520011007afc4b5d054ff10a6f196653807e56a3ede329213c9fb0ec9c5983d59f21e5cf"
key = "d9e4e19e5a4aeb410bdf36ba1448ad75"
iv = ""
res, err = resiot_encrypt("aes", "cmac", message, iv, key)
resiot_debug("encrypt: "..res)

Return to index


resiot_encryptraw (String, String, []byte, []byte, []byte)

Encrypts a message with the provided cipher, cipher mode algorithm. This is the same as resiot_encrypt but all the parameters are raw bytes and not hex encoded string.
Currently, only AES CMAC is supported
Input Parameters
 - String (String): * The cipher to use.
 - String (String): * The cipher mode to use.

 - String (String): * The raw message bytes to encrypt.
 - String (String): * The raw IV bytes to encrypt the message.

 - String (String): * The raw KEY bytes to encrypt the message.
Returns
 - []byte ([]byte): * The encrypted data

 - String (String): * If not empty, the error that occurred during the encryption *

messageS = "21308618b000d8782000000000000000520011007afc4b5d054ff10a6f196653807e56a3ede329213c9fb0ec9c5983d59f21e5cf"
keyS = "d9e4e19e5a4aeb410bdf36ba1448ad75"
ivS = ""
message = resiot_hexdecode(messageS)
key = resiot_hexdecode(keyS)
iv = resiot_hexdecode(ivS)
res, err = resiot_encryptraw("aes", "cmac", message, iv, key)
resiot_debug(resiot_hexencode(res))

Return to index


resiot_decrypt (String, String, String, String, String)

Decrypts an hex encoded message with the provided cipher, cipher mode algorithm. All the provided data needs to be hex encoded.
Currently, only AES CTR is supported
Input Parameters
 - String (String): * The cipher to use.
 - String (String): * The cipher mode to use.

 - String (String): * The hex encoded message to decrypt.
 - String (String): * The hex encoded IV to decrypt the message.

 - String (String): * The hex encoded KEY to decrypt the message.
Returns
 - String (String): * The hex encoded encrypted data

 - String (String): * If not empty, the error that occurred during the decryption *

message = "7afc4b5d054ff10a6f196653807e56a3ede329213c9fb0ec9c5983d59f21e5cf"
key = "d9e4e19e5a4aeb410bdf36ba1448ad75"
iv = "21308618b000d8782052110000000000"
res, err = resiot_decrypt("aes", "ctr", message, iv, key)
resiot_debug("decrypt: "..res)

Return to index


resiot_decryptraw (String, String, []byte, []byte, []byte)

Decrypts a message with the provided cipher, cipher mode algorithm. This is the same as resiot_decrypt but all the parameters are raw bytes and not hex encoded string.
Currently, only AES CTR is supported
Input Parameters
 - String (String): * The cipher to use.
 - String (String): * The cipher mode to use.

 - String (String): * The raw message bytes to decrypt.
 - String (String): * The raw IV bytes to decrypt the message.

 - String (String): * The raw KEY bytes to decrypt the message.
Returns
 - []byte ([]byte): * The encrypted data

 - String (String): * If not empty, the error that occurred during the decryption *

messageS = "7afc4b5d054ff10a6f196653807e56a3ede329213c9fb0ec9c5983d59f21e5cf"
keyS = "d9e4e19e5a4aeb410bdf36ba1448ad75"
ivS = "21308618b000d8782052110000000000"
message = resiot_hexdecode(messageS)
key = resiot_hexdecode(keyS)
iv = resiot_hexdecode(ivS)
res, err = resiot_decryptraw("aes", "ctr", message, iv, key)
resiot_debug(resiot_hexencode(res))

Return to index


resiot_split (String, String)

Slices the string into all substrings separated by separator and returns a slice of the substrings between those separators.
Example
stringsArray = resiot_split(StringToSplit, Separator)
Input Parameters
 - StringToSplit (String): * The string to split.
 - Separator (String): * The string separator.

If the string does not contain the separator and the separator is not empty, resiot_split returns a slice of length 1 whose only element is the string.
If the separator is empty, resiot_split splits after each UTF-8 sequence. If both the string and separator are empty, resiot_split returns an empty slice.
Returns
 - stringsArray ([]String): * The splitted strings*

StringToSplit = "abc,de,fghi,jk"
Separator = ","
stringsArray = resiot_split(StringToSplit, Separator)
resiot_debug(stringsArray[1])
resiot_debug(stringsArray[2])
resiot_debug(stringsArray[3])
resiot_debug(stringsArray[4])

Return to index