Shell Execution

Pierre Kil edited this page Jan 19, 2017 · 2 revisions
Clone this wiki locally

The Execute Shell command protocol can be used to execute any command on the machine on which the OpenRemote controller is running.

##OpenRemote Online Designer

The Online Designer already supports the "Shell execution protocol", so all you need is an account to log in and start creating your commands.

The first example creates a button that runs the command "/opt/bin/test.sh" which needs three parameter "param1", "param2" and "param3".

Also, the latest version supports to use the ShellExe protocol to return status information to be passed to OpenRemote sensors. And a really unique feature of this protocol in the moment is also, the possibilty to read values into multiple sensors with only one call. For this to work your called shell command needs to return multiple values which can be parsed via a regular expression.

The second example creates a call to a "status.sh" script which returns the information for 3 switches at once.

###Create new Device In "Building Modeler", create new device (New>New Device)

Shell Execution - 1.png

###Create command to call "test.sh" Still in "Building Modeler", select the device that was created in step 1 and click on New>New Command Specify a name and select "Shell execution protocol" as protocol.

Shell Execution - 2

Protocol specific settings:

  • Full path to executable - Enter the full path to the executable
  • Additional command parameter - Additional parameter to add when starting the executable
  • Polling interval - Only needed for status calls
  • RegularExpression - Only needed for status calls
  • Sensor names - Only needed for status calls

Click on "Submit". Now we have the first ShellExe command

Shell Execution - 3

###Create status command for sensors Now we want to create a command which can be used to populate the three sensors "sensor1", "sensor2" and "sensor3". All sensors will be switch sensors and therefore we need a result of "on" or "off" for each sensor.

Still in "Building Modeler", again select the device that was created in step 1 and click on New>New Command

Specify a name and select "Shell execution protocol" as protocol.

Shell Execution - 5

Protocol specific settings:

  • Full path to executable - Enter the full path to the executable which returns the status
  • Additional command parameter - Additional parameter to add when starting the executable
  • Polling interval - What interval should be used to request the status (500, 1s, 2m)
  • RegularExpression - The regular expression is used to split the result in the needed single values for multiple sensors
  • Sensor names - A semicolon seperated list of sensor names. The order has to fit to the order on how the regular expression is splitting the result.

The example in this picture expects a result of the called executable like this "On Off Off". This will be split in three seperate values "On", "Off" and "Off" and passed to the three sensors "sensor1", "sensor2" and "sensor3".

Click on "Submit". Now we have 2 ShellExe commands. One to execute some action and one to request status information for 3 sensors.

Shell Execution - 6

If you leave the "RegularExpression" field empty all sensors given in the "Sensor names" field will be populated with the same result which is the return value of the executed command. You have to give at least one sensor name if you want to collect the return value of the command.

###Create sensors

Now we need to create the 3 sensors "sensor1", "sensor2" and "sensor3" which are used in the status command we created in the previous step. Make sure your sensor names are the same as used in the command attribute "Sensor names".

Shell Execution - 7

The sensors can now be used to display status information or in combination with switch objects to turn something on and off.

###Use commands in UI Designer

Now we switch to the UI Designer and create a panel which will be our remote. The panel will contain one button which is linked to our new command.

Shell Execution - 4