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_telegram String, String String Send messages by telegram
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_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 Exectute the AND operation between two Bytes
resiot_andnot BYTE, BYTE BYTE Filter and use only the bit at 1 of the first Byte
resiot_or BYTE, BYTE BYTE Exectute the OR operation between two Bytes
resiot_xor BYTE, BYTE BYTE Exectute 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_ba2float32BE BYTE [ ] Float Convert an input bytes array into a Float
resiot_ba2float32LE BYTE [ ] Float Convert an input bytes array into a 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_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)
resiot_debug(ArrByte)
-- 
-- In This case:
-- 
-- ArrByte = {0x48 0x65 0x6c 0x6c 0x6f 0x20 0x77 0x6f 0x72 0x6c 0x64 0x21} = "Hello world!"
-- Error = ""
-- 
-- In case of an error has occurred:
-- 
-- ArrByte = {}
-- Error = "Error Description"
-- 

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)
resiot_debug(Response)
-- 
-- In This case:
-- 
-- Response = "Hello world!"
-- Error = ""
-- 
-- In case of an error has occurred:
-- 
-- Response = ""
-- Error = "Error Description"
-- 

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_telegram(String, String)

Send messages by telegram.
Example
Error = resiot_telegram(Message, HexID)
Input Parameters
 - Message (String): * The message you want to send.
 - HexID (String): * The Hexadeciamal ID of the telegrm media you want to use.

Returns
 - Error (String): * If an error occurs, it is shown here. *

Message = "Message Text"        -- The message you want to send
HexID = "6d656438"              -- The Hexadeciamal ID of the telegrm media you want to use
Error = resiot_telegram(Message, HexID)
resiot_debug(Error)
-- 
-- In case of an error has occurred:
-- 
-- Error = "Error Description"
-- 
-- Else:
-- 
-- Error = ""
-- 

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)
resiot_debug(ArrByte)
-- 
-- In This case:
-- 
-- ArrByte = {0x48 0x65 0x6c 0x6c 0x6f 0x20 0x77 0x6f 0x72 0x6c 0x64 0x21}
-- Error = ""
-- 
-- In case of an error has occurred:
-- 
-- ArrByte = {}
-- Error = "Error Description"
-- 

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)
resiot_debug(Response)
-- 
-- In This case:
-- 
-- Response = "Hello World!"
-- Error = ""
-- 
-- In case of an error has occurred:
-- 
-- Response = ""
-- Error = "Error Description"
-- 

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_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)

Exectute 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_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)

Exectute 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_xor(BYTE, BYTE)

Exectute 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_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_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