Scripts
From eedomus - Documentation
Contents |
HTTP Script on the box eedomus
This element of eedomus SDK allows you to host and run your own script on the box eedomus .
You must first be logged into your account on http://secure.eedomus.com .
Then go to: http://ip_of_your_eedomus_box/script/
Usage
Users created scripts can be called by different means :
- Manually to test : Clicking Run on your page scripts eedomus
- Manually: by entering a URL like http://ip_of_your_eedomus_box/script/?exec=myscript.php from a browser or other software or hardware capable of performing HTTP requests
- Via a HTTP sensor eedomus: it can be updated at regular intervals or through a rule.
- Via a HTTP actuator: you can operate manually or via a rule.
Limitations
To avoid the risk of overflow Scripts eedomus , the following limitations apply:
- The size of each script is 50KB
- The period of execution of scripts is limited to 30 seconds
- The memory footprint of scripts is limited
Scripting language
The syntax used by the scripts is derived from PHP language. Scripts must end with the extension ".php" .
The definition of the variable is done so in the form:
$ pi = 3.145916 ; / * Declaration of my variable "Pi" * /
The following structures are permitted: for while if switch foreach
Creating tables is allowed: array
The following functions are enabled : abs acos addslashes array asin atan ceil cos count date die echo empty exp explode floor fmod implode in-array isset log md5 microtime mktime ord printf rand round sin sizeof streplace stripslashes strlen strpos strrchr strtolower strtotime strtoupper substr tan time trim urlencode var-dump
Specific functions
getArg($var, $mandatory = true, $default = ' ')
- Retrieves an argument $ _GET [ $ var ] and displays an error message if the argument is not specified .
httpQuery($url, $action = 'GET' /*GET,POST,PUT,DELETE*/, $post = NULL)
- Executes an HTTP / HTTPS request and returns the result as a character string .
- Arguments $ and Action $ post may be omitted , they can be used in the case of queries as an advanced POST .
saveVariable ( $variable_name $variable_content )
- Saves the contents of a variable , which makes it reusable in a future script (via loadVariable ) .
- Note: The variables with the same name are not visible between different scripts.
loadVariable ( $variable_name )
- Loads the contents of a previously saved with saveVariable (variable)
- Note: The variables with the same name are not visible between different scripts.
jsonToXML($json)
- Converts a string in JSON to XML ( Useful for achieving treatment xpath () thereafter)
xpath ($xml, $path )
- These are the same accessors xpath / xquery for the [ [ Capteurs_HTTP | HTTP sensors eedomus ]]
- The xpath validator can be used for test:
- http://doc.eedomus.com/xpath/
setValue($periph_id /*API code*/, $value)
- Operates a device through its API Code
setmacro ($ periph_id / * API code * / $ macro_id / * Macro Code API * / $ dynamic_value = 0)
- Operates a device through its API code and API code of its macro.
- The argument $ dynamic_value can be omitted, it allows you to define the length of a macro variable as appropriate.
getValue($periph_id /*API code*/)
- Returns an array containing the value of a device via its [ [ API Code | API ] code].
- The table is of type array ( [ "value" ] => xx [ "change" ] => 'YYYY -MM -DD HH: MM: SS' )
sdk_json_decode($json)
- Returns an array containing the decoded JSON ( similar to the json_decode function () PHP
httpQuery($url, $action = 'GET' /*GET,POST,PUT,DELETE*/, $post = NULL)
- Customize the header of the HTTP response from the script. Only $ content_type = ' text / xml' is supported for now.
netSend($ip, $port, $data)
- Send data to a network device using telnet like protocol (experimental)
- Give back the answer of the device if any
- Available only on eedomus+
Find these specific functions in some examples at your disposal
User Functions
You can define your own user-defined function , provided by the prefix sdk_:
For example: sdk_add function ($ a , $ b ) {return $ a + $ b; }