Skip to content

Files

Working with files requires you to be the administrator of the platform. This is to avoid users to do damage to your system. All the following functions will return an error if you are not allowed to run them.

If you're confident enough and want to allow every user access to the following functions, edit your config.json file and add field "ALLCANSHELL", set its value to true and restart the server.

Name Input Params Return Data Description
resiot_shell String, String... String, String Runs a binary at the given location with the given parameters
resiot_readfile String String, String Reads the content of a file at a given location
resiot_writefile String, String String Writes the given content into a file at the given location
resiot_deletefile String String Deletes the file at the given location

resiot_shell(String, String...)

Runs a binary at the given location with the given parameters
Example
output, err = resiot_shell("/opt/resiot/resiot", "--debug")
Input Parameters
 - Path (String): * The path of the binary you want to run.
 - Args (String...): * An optional number of arguments to pass to your binary.

Returns
 - Output (String): * If the call was successful, this will contain the output of your binary
 - Error (String): * Empty if the call was successful, otherwise contains the reason of the error

output, err = resiot_shell("notepad", "C:\\test\\test.txt")
if err ~= "" then
  resiot_debug(err) -- output is an the error in case running your binary failed for some reason
else
  resiot_debug(output) -- empty in the case of notepad, anything printed to the standard out of your binary will be contained in this string variable
end

Return to index


resiot_readfile(String)

Reads the content of a file at a given location
Example
output, err = resiot_readfile("/opt/test/config.json")
Input Parameters
 - Path (String): * The path of the file you want to read.
Returns
 - Output (String): * If the call was successful, this will contain the content of your file

 - Error (String): * Empty if the call was successful, otherwise contains the reason of the error *

output, err = resiot_readfile("/opt/test/config.json")
if err ~= "" then
  resiot_debug(err) -- output is an the error in case running your binary failed for some reason
else
  -- the content of your file
  resiot_debug(output) -- {}
end

Return to index


resiot_writefile(String, String)

Writes the given content into a file at the given location
Example
err = resiot_writefile("/opt/test/config.json", "{}")
Input Parameters
 - Path (String): * The path of the file you want to write.
 - Content (String): * The content to write into your file.

Returns
 - Error (String): * Empty if the call was successful, otherwise contains the reason of the error *

err = resiot_writefile("/opt/test/config.json", "{}")
if err ~= "" then
  --writing failed
else
  --writing succeeded
end

Return to index


resiot_deletefile(String)

Deletes the file at the given location
Example
err = resiot_deletefile("/opt/test/config.json")
Input Parameters
 - Path (String): * The path of the file you wish to delete.
Returns
 - Error (String): * Empty if the call was successful, otherwise contains the reason of the error

err = resiot_deletefile("/opt/test/config.json")
if err ~= "" then
  --delete failed
else
  --delete succeeded
end

Return to index