Skip to content

Various

Name Input Params Return Data Description
resiot_sendemail String, String, String Boolean Send an e-mail to a given E-mail address list with a Subject and a Message using the first Media Notification conifuration available
resiot_sendemailtxt String, String, String Boolean Send an e-mail to a given E-mail address list with a Subject and a Message using the first Media Notification conifuration available
resiot_sleep Integer Empty Sleep for N Milliseconds
resiot_runscene String, ... Boolean, String Start another Scene alongside this one
resiot_runscenewithcallback String, String, String String, String Starts another Scene with an input parameter and waits for it to return a value.
resiot_setreturnvalue String String If you're running a scene from api or via other methods, you might want your scene to return a value, this is how you set it
resiot_time Integer Integer, Integer, Integer, Integer, Integer, Integer Get the actual date of your organization
resiot_alert String, String Boolean, String Send an Alert message to a member of your organization or to your entire organization
resiot_importantmessage String, String Boolean, String Send an Important message to a member of your organization or to your entire organization
resiot_raiseevent String, String, String String Trigger the input Event of a Node
resiot_regex String, String, Integer String Check if the string val respect the regex pattern
resiot_subregex String, String, Integer, Integer String Check if the string val respect the regex pattern
resiot_getsunrise String, String Integer Get the time of sunrise, in minutes, of a node
resiot_getsunset String, String Integer Get the time of sunset, in minutes, of a node
resiot_telegram String, String String Send a telegram message using media
resiot_dayoftheweek Integer String Get the day of the week of a date
resiot_curl String String, String Send a HTTP request via web server APIs
resiot_getram String, String Get the used percentage of RAM used by the system
resiot_getcpu String, String Get the used percentage of CPU used by the system
resiot_certvalidity Integer, String Get the number of hours of validity of your webserver SSL certificate
resiot_distance Float, Float, Float, Float Float Calculates the great-circle distance in meters between two gps coordinates

resiot_sendemail(String, String, String)

Send an e-mail to a given E-mail address list with a Subject and a Message using the first Media Notification configuration available. The email body will be encapsulated in a premade layout and set as HTML.
Example
AllWorked = resiot_sendemail(E-mail, SUbject, Message)
Input Parameters
 - E-mail (String): * The e-mail of the recipient. Can contain up to 10 email addresses, separated by a ;(semicolon) without spaces.
 - Subject (String): * The subject of the e-mail.

 - Message (String): * The message of the e-mail.
Returns
 - AllWorked (Boolean): * The functions returns true if the assignment worked.

Email = "email@email.com"       -- The e-mail of the recipient
Subject = "Subject"             -- The subject of the e-mail
Message = "Message"             -- The message of the e-mail
AllWorked = resiot_sendemail(Email, Subject, Message)
resiot_debug(AllWorked)
-- 
-- If there aren't any errors:
-- 
-- AllWorked = true
-- 
-- Else:
-- 
-- AllWorked = false
-- 

Return to index


resiot_sendemailtxt(String, String, String)

Send an e-mail to a given E-mail address list with a Subject and a Message using the first Media Notification configuration available. Unlike resiot_sendemailtxt, this function will be sent as plain text.
Example
AllWorked = resiot_sendemailtxt(E-mail, SUbject, Message)
Input Parameters
 - E-mail (String): * The e-mail of the recipient. Can contain up to 10 email addresses, separated by a ;(semicolon) without spaces.
 - Subject (String): * The subject of the e-mail.

 - Message (String): * The message of the e-mail.
Returns
 - AllWorked (Boolean): * The functions returns true if the assignment worked.

Email = "email@email.com"       -- The e-mail of the recipient
Subject = "Subject"             -- The subject of the e-mail
Message = "Message"             -- The message of the e-mail
AllWorked = resiot_sendemailtxt(Email, Subject, Message)
resiot_debug(AllWorked)
-- 
-- If there aren't any errors:
-- 
-- AllWorked = true
-- 
-- Else:
-- 
-- AllWorked = false
-- 

Return to index


resiot_sleep(Integer)

Sleep for N Milliseconds.
Example
resiot_sleep(Milliseconds)
Input Parameters
 - Milliseconds (Integer): * The time in milliseconds.
Returns
 - * The function doesn't have nothing to return.

Milliseconds = 1000         -- The time in milliseconds
resiot_sleep(Milliseconds)
-- 
-- In This case:
-- 
-- The scene sleep for 1000 milliseconds, or 1 second
-- 

Return to index


resiot_runscene(String, ...)

Start another Scene alongside this one. The Scene is identified by his Hexadecimal ID and the parameters that are needed are written next to the ID
Example
AllWorked, Error = resiot_runscene(HexID)
Input Parameters
 - HexID (String): * The Hexadecimal ID that identify the scene.
 - Parameters (String/Integer/Float): * If the scene that need some parameters to run, then thery are insert here, each separated by a comma.

Returns
 - AllWorked (Bool): * "true" if the scene started successfully, and "false" in the other case.
 - Error (String): * If the Result is false, it return the error.

HexID = "69643d31"      -- The Hexadecimal ID that identify the scene
Parameters = 12         -- If the scene needs some parameters to run, then thery are insert here, each separated by a comma
AllWorked, Error = resiot_runscene(HexID,Parameters)
resiot_debug(AllWorked)
-- 
-- Result Example:
-- 
-- If there aren't any errors:
-- 
-- AllWorked = true
-- Error = ""
-- 
-- Else:
-- 
-- AllWorked = false
-- Error = "Error Description"
-- 

Return to index


resiot_runscenewithcallback(String, String, String)

Starts another Scene with an input parameter and waits for it to return a value.... The Scene is identified by its Hexadecimal ID or its Tag. If both are declared and valid, the HexID will be used.
Example
ret, Error = resiot_runscenewithcallback("abcdef", "", "")
Input Parameters
 - HexID (String): * The Hexadecimal ID that identifies the scene to be run.
 - Tag (String): * The scene Tag of that identifies the scene to be run.

 - Input (String): * An input parameter that can be retrieved in the scene you want to run. Use a json along with json functions if you need to pass complex data.
Returns
 - ReturnValue (String): * the returned value from the scene you're running.

 - Error (String): * If the scene failed to run, the reason will be reported here. *

HexID = "69643d31"          -- The Hexadecimal ID that identifies the scene to be run
Tag = ""                    -- The scene Tag of that identifies the scene to be run
Input = "aninputparameter"  -- An input parameter that can be retrieved in the scene you want to run
ret, err = resiot_runscenewithcallback(HexID, Tag, Input)
if err ~= "" then
  resiot_debug(err)
else
  resiot_debug(ret)
end

-- 
-- Result Example:
-- 
-- If there aren't any errors:
-- 
-- err = ""
-- 
-- Else:
-- 
-- err = "Error Description"
-- 

Return to index


resiot_setreturnvalue(String)

If you're running a scene with a mechanism that's going to read the output of your scene, you will need this function to set this value.
Please notice this is not the equivalent of a return in standard programming languages, this is a non-blocking method.
Example
resiot_setreturnvalue("done")
Input Parameters
 - Input (String): * There are no limits in terms of length, your returned text (usually a json) can be as long as you want *

resiot_setreturnvale("I'm finally done!")
resiot_debug("hey! I'm still alive") -- this part of code WILL be reached

Return to index


resiot_time(Integer)

Get the actual date of your organization.
Example
Year, Month, Day, Hour, Minute, Second = resiot_time(YearFormat)
Input Parameters
 - YearFormat (Integer): * The type of the year that is returned, 0 will return the year in a 4 digit format (2017), 1 will return the year in a 2 digit format (17).
Returns
 - Year (Integer): * The year in a 4 or 2 digit format.

 - Month (Integer): * The number of the month (1-12).
 - Day (Integer): * The number of the day of the month (1-31).

 - Hour (Integer): * The number of the hour (0-23).
 - Minute (Integer): * The number of the minute (0-59).

 - Second (Integer): * The number of the second (0-59). *

YearFormat = 1      -- The type of the year that is returned, 0 will be in a 4 digit format (2017), 1 will be in a 2 digit format (17)
Year, Month, Day, Hour, Minute, Second = resiot_time(YearFormat)
resiot_debug(Year.."/"..Month.."/"Day.." "..Hour..":"..Minute..":"..Second)
-- 
-- Result Example:
-- 
-- If YearFormat is 1:
-- 
-- Year = 17
-- 
-- Else:
-- 
-- Year = 2017
-- 
-- Month = 4
-- Day = 20
-- Hour = 16
-- Minute = 3
-- Second = 26
-- 

Return to index


resiot_alert(String, String)

Send an Alert message to a member of your organization or to your entire organization.
Example
AllWorked, Error = resiot_alert(ToWho, Message)
Input Parameters
 - ToWho (String): * This string contain the e-mail or the Hexadecimal ID of the user that will receive the message. If you leave the string empty, the message will be sent to the whole organization.
 - Message (String): * The message that will be sent to the receiver.

Returns
 - AllWorked (Boolean): * The functions returns true if the assignment worked.
 - Error (String): * If the Result is false, here is wrote the error.

ToWho = "e-mail@e-mail.com"     -- This string contain the e-mail or the Hexadecimal ID of the user that will receive the message. If empty, the message will be sent to the whole organization
Message = "The Message"         -- The message that will be sent to the receiver
AllWorked, Error = resiot_alert(ToWho, Message)
resiot_debug(AllWorked)
-- 
-- Result Example:
-- 
-- If there aren't any errors:
-- 
-- AllWorked = true 
-- Error = ""
-- 
-- Else:
-- 
-- AllWorked = true 
-- Error = "Error Description"
-- 

Return to index


resiot_importantmessage(String, String)

Send an Important message to a member of your organization or to your entire organization.
Example
AllWorked, Error = resiot_importantmessage(ToWho, Message)
Input Parameters
 - ToWho (String): * This string contain the e-mail or the Hexadecimal ID of the user that will receive the message. If you leave the string empty, the message will be sent to the whole organization.
 - Message (String): * The message that will be sent to the receiver.

Returns
 - AllWorked (Boolean): * The functions returns true if the assignment worked.
 - Error (String): * If the Result is false, here is wrote the error.

ToWho = "e-mail@e-mail.com"     -- This string contain the e-mail or the Hexadecimal ID of the user that will receive the message
Message = "The Message"         -- The message that will be sent to the receiver
AllWorked, Error = resiot_importantmessage(ToWho, Message)
resiot_debug(AllWorked)
-- 
-- Result Example:
-- 
-- If there aren't any errors:
-- 
-- AllWorked = true 
-- Error = ""
-- 
-- Else:
-- 
-- AllWorked = true 
-- Error = "Error Description"
-- 

Return to index


resiot_raiseevent(String, String)

Trigger the input Event of a Node.
Example
Error = resiot_raiseevent(AppEUI, DevEUI, EventName)
Input Parameters
 - AppEUI (String): * The AppEUI of the Node.
 - DevEUI (String): * The DevEUI of the Node.

 - EventName (String): * The designed Event.
Returns
 - Error (String): * The occurred error.

AppEUI = "8811abbc8271fbAF"     -- The AppEUI of the Node
DevEUI = "aa32131bc12afcb2"     -- The DevEUI of the Node
EventName = "Start_cleanup"     -- The designed Event
Error = resiot_raiseevent(AppEUI, DevEUI, EventName)
resiot_debug(Error)
-- 
-- Result Example:
-- 
-- If there aren't any errors:
-- 
-- Error = ""
-- 
-- Else:
-- 
-- Error = "Error Description"
-- 

Return to index


resiot_regex(String, String, Integer)

Check if the string val respect the regex pattern.
If Index is bigger than 0, you'll have in return the string that is specified in the parenthesis.
Example
Variable = resiot_regex(Pattern, Value, Index)
Input Parameters
 - Pattern (String): * The pattern that the string must comply to. It must be written in golang language.
 - Value (String): * The string that is checked.

 - Index (Integer): * If 0, return all the string; meanwhile if it is bigger than 0, it return the section of the string specified by the Index.
Returns
 - Variable (String): * It return the whole string if index is 0; elsewhere it return a determined section of the same string specified by the Index.

Pattern = "^([a-zA-Z0-9]+)@([a-zA-Z0-9]+\\.[a-zA-Z]+)$"     -- The pattern that the string must comply to. It must be written in golang language
-- ([a-zA-Z0-9]+) is returned with index 1
-- ([a-zA-Z]+\\.[a-zA-Z]+) is returned with index 2
Value = "email@email.com"       -- The string that is checked
-- 
-- Examples:
-- 
Index = 0       -- It return the whole string if index is 0; elsewhere it return a determined section of the same string specified by the Index
Variable = resiot_regex(Pattern, Value, Index)
resiot_debug(Variable)
-- Variable = "email@email.com"
-- 
Index = 1
Variable = resiot_regex(Pattern, Value, Index)
resiot_debug(Variable)
-- Variable = "email"
-- 
Index = 2
Variable = resiot_regex(Pattern, Value, Index)
resiot_debug(Variable)
-- Variable = "email.com"
-- 

Return to index


resiot_subregex(String, String, Integer, Integer)

Check if the string val respect the regex pattern.
If Index is bigger than 0, you'll have in return the string that is specified in the parenthesis.
Example
Variable = resiot_subregex(Pattern, Value, Index1, Index2)
Input Parameters
 - Pattern (String): * The pattern that the string must comply to. It must be written in golang language.
 - Value (String): * The string that is checked.

 - Index1 (Integer): * Select the match which you want to retrive the data.
 - Index2 (Integer): * If 0, return all the match; meanwhile if it is bigger than 0, it return the section of the string specified by the Index.

Returns
 - Variable (String): * It return the whole string if index is 0; elsewhere it return a determined section of the same string specified by the Index. *

Pattern = "([a-zA-Z0-9]+)@([a-zA-Z0-9]+\\.[a-zA-Z]+)"   -- The pattern that the string must comply to. It must be written in golang language
-- ([a-zA-Z0-9]+) is returned with index2 1
-- ([a-zA-Z]+\\.[a-zA-Z]+) is returned with index2 2
Value = "email1@email1.com email2@email2.com"           -- The string that is checked
-- 
-- Examples:
-- 
Index1 = 0      -- Select the match which you want to retrive the data
-- 
Index2 = 0      -- If 0, return all the match; meanwhile if it is bigger than 0, it return the section of the string specified by the Index
Variable = resiot_subregex(Pattern,Value,Index1,Index2)
resiot_debug(Variable)
-- Variable = "email1@email1.com"
-- 
Index2 = 1
Variable = resiot_subregex(Pattern,Value,Index1,Index2)
resiot_debug(Variable)
-- Variable = "email1"
-- 
Index1 = 1
-- 
Index2 = 0
Variable = resiot_subregex(Pattern,Value,Index1,Index2)
resiot_debug(Variable)
-- Variable = "email2@email2.com"
-- 
Index2 = 2
Variable = resiot_subregex(Pattern,Value,Index1,Index2)
resiot_debug(Variable)
-- Variable = "email2.com"
-- 

Return to index


resiot_getsunrise(String, String)

Get the time of sunrise, in minutes, of a node.
The output are the minutes of sunrise after the midnight.
Example
Sunrise = resiot_getsunrise(AppEUI, DevEUI)
Input Parameters
 - AppEUI (String): * The AppEUI of the Node.
 - DevEUI (String): * The DevEUI of the Node.

Returns
 - Sunrise (Integer): * It return the minutes from midnight to the sunrise of the current day. *

AppEUI = "8811abbc8271fbAF"     -- The AppEUI of the Node
DevEUI = "aa32131bc12afcb2"     -- The DevEUI of the Node
Sunrise = resiot_getsunrise(AppEUI, DevEUI)
resiot_debug(Sunrise)
-- 
-- Result Example:
-- 
-- If there aren't any errors:
-- 
-- Sunrise = 336    It return the minutes from midnight to the sunrise of the current day
-- 
-- Else:
-- 
-- Sunrise = -1
-- 

Return to index


resiot_getsunset(String, String)

Get the time of sunset, in minutes, of a node.
The output are the minutes of sunset before the midnight.
Example
Sunset = resiot_getsunrise(AppEUI, DevEUI)
Input Parameters
 - AppEUI (String): * The AppEUI of the Node.
 - DevEUI (String): * The DevEUI of the Node.

Returns
 - Sunset (Integer): * It return the minutes from the sunset of the current day, to midnight. *

AppEUI = "8811abbc8271fbAF"     -- The AppEUI of the Node
DevEUI = "aa32131bc12afcb2"     -- The DevEUI of the Node
Sunset = resiot_getsunset(AppEUI, DevEUI)
resiot_debug(Sunset)
-- 
-- Result Example:
-- 
-- If there aren't any errors:
-- 
-- Sunset = 188     It return the minutes from the sunset of the current day, to midnight
-- 
-- Else:
-- 
-- Sunset = -1
-- 

Return to index


resiot_telegram(String, String)

Send a telegram message using media.
Example
Error = resiot_telegram(Message, HexID)
Input Parameters
 - Message (String): * The body of the message.
 - HexID (String): * The Hexadecimal Id that identify the media to use. If left empty it pick the first available.

Returns
 - Error (String): * It return the error if there is one, otherwise i is empty. *

Message = "Hello World!"    -- The body of the message
HexID = "6d656433"          -- The Hexadecimal Id that identify the media to use. If left empty it pick the first available
Error = resiot_telegram(Message, HexID)
resiot_debug(Error)
-- 
-- Result Example:
-- 
-- If there aren't any errors:
-- 
-- Error = ""
-- 
-- Else:
-- 
-- Error = "Error Description"
-- 

Return to index


resiot_dayoftheweek(Integer)

Get the day of the week of a date.
Example
Day = resiot_dayoftheweek(Date)
Input Parameters
 - Date (Integer): * The date in seconds.
Returns
 - Day (String): * It return the name of the day of the date.

Date = os.time()        -- The date in seconds
Day = resiot_dayoftheweek(Date)
resiot_debug(Day)
-- 
-- Result Example:
-- 
-- Day = "Tuesday"
-- 

Return to index


resiot_curl(String)

Send a HTTP request via web server APIs.
The curl need a json string as imput, the fields are "method", "url", "headers", "data", "login", "pw".
Field "method" is get or post, the "url" is the url of the page you want to request with the curl, "headers" are custom headers that can be added for the selection of specific parts of the page, the headers have two sub-field "name" and "value", these are used to specify what type of header you are searching and the value that you want, "data" contains the data that are sent to the page in POST mode like a form submit, "login" & "pw" contains the eventual login and password for the website page you are trying to request via curl.
Example
CurlData = '{"method": "get","url" : "http://www.google.com/robots.txt", "headers":[{"name": "", "value": ""}], "data": "", "login": "", "pw": ""}'
Json = resiot_curl(CurlData)

Input Parameters
 - CurlData (String) : * The body of the HTTP request.
Returns
 - Json (String) : * It return the response of the curl in a Json valid format.

CurlData = '{"method": "get","url" : "http://www.google.com/robots.txt", "headers":[{"name": "", "value": ""}], "data": "", "login": "", "pw": ""}'
        -- The body of the HTTP request
Json, err = resiot_curl(CurlData)
resiot_debug(Json)
-- 
-- Result Example:
-- 
--  Json = "User-agent: * Disallow: /search Allow: /search/about Allow: /search/howsearchworks Disallow: /sdch Disallow: /groups Disallow: /index.html..."
-- 
--  err = ""
-- 
CurlData = '{"method": "post","url" : "https://api.digitalocean.com/v2/domains/example.com/records", "headers":[{"name":"Content-Type", "value": "application/json"}, {"name":"Authorization", "value": "Bearer b7d03a6947b217efb6f3ec3bd3504582"}], "data":"{\\"type\\":\\"A\\",\\"name\\":\\"www\\",\\"data\\":\\"162.10.66.0\\",\\"priority\\":null,\\"port\\":null,\\"weight\\":null}\\"}", "login": "", "pw": ""}'
Json, err = resiot_curl(CurlData)
resiot_debug(Json)
-- 
-- Result Example: 
-- 
-- Json = "{"id": "unauthorized", "message": "Unable to authenticate you." }"
-- 
-- err = ""
-- 

Return to index


resiot_getram()

Get the ram usage.
Example
ram = resiot_getram()
Returns
 - Ram (String): * It returns the ram usage. *

r, err = resiot_getram()
if err ~= "" then
  resiot_debugf("error: %%v"..err)
else
  resiot_debugf("Used ram: %%v percent!", r)
end 
-- 
-- Output Example: "Used ram: 60.02 percent!"
-- 

Return to index


resiot_getcpu()

Get the cpu usage.
Example
cpu = resiot_getcpu()
Returns
 - Day (String): * It returns the cpu usage. *

r, err = resiot_getcpu()
if err ~= "" then
  resiot_debugf("error: %%v"..err)
else
  resiot_debugf("Used CPU: %%v percent!", r)
end 
-- 
-- Output Example: "Used CPU: 60.02 percent!"
-- 

Return to index


resiot_certvalidity()

Get the number of hours of validity of your webserver SSL certificate.
Only the platform admins have access to this function which will eventually return an error if you do not have admin rights.
Example
hours, err = resiot_certvalidity()
Returns
 - Hours (Integer): * The number of hours until your SSL expires. Please note this can be negative if your certificate has expired already.
 - Err (String): * A non empty string if something went wrong.

r, err = resiot_certvalidity()
if err ~= "" then
  resiot_debugf("Error: %%v"..err)
else
  resiot_debugf("Validity: %%v hours!", r)
end 

Return to index


resiot_distance(Float,Float,Float,Float)

Calculates the great-circle distance in meters between two gps coordinates using the []Haversine formula](https://en.wikipedia.org/wiki/Haversine_formula)
Example
distance = resiot_distance(Lat1,Lon2,Lat2,Lon2)
Input Parameters
 - Lat1 (Float): * The latitude of the first coordinate.
 - Lon2 (Float): * The longitude of the first coordinate.

 - Lat2 (Float): * The latitude of the second coordinate.
 - Lon2 (Float): * The longitude of the second coordinate.

Returns
 - Hours (Float): * The distance in meters between the two coordinates considering Earth's curvature *

lat1 = 45.534060    -- The coordinates of the two points
lon1 = 10.011074
lat2 = 45.555812
lon2 = 10.075685

resiot_debug(resiot_distance(lat1, lon1, lat2, lon2))

Return to index