Web Server

The Web Server feature enables a small, lightweight, embedded web server in TouchControl on your iOS device.  This allows you to render your activities in a web browser, and/or execute buttons via HTTP requests directly from your iOS device, without the need for TouchControl Server (or any other web server).  This effectively turns TouchControl on your iOS device into an automation hub, allowing you to access your TouchControl configuration and control your devices from virtually any interface, in any location.  Since TouchControl on your device is actually executing the buttons/commands, all of your script, feedback, and other automation features of TouchControl are available and processed automatically. 
The Web Server is available as an in-app upgrade, found in the “Upgrade” option within TouchControl settings, and you are encouraged to try it out before you purchase it.  Turning on the Web Server before you purchase the upgrade will allow it to run for three minutes at a time, allowing you to test it with your specific configuration (activities and buttons).  After the three-minute time limit, it can then be re-started after a brief wait.  Purchasing the upgrade will then remove the three-minute limit, allowing it to run indefinitely as needed.  Please see the notes at the bottom of this page regarding designing for and testing the Web Server.

To start the Web Server, open settings and tap on the “Web Server” option.  This will display the Web Server screen, where you can start and stop the Web Server as desired.  Also found on this screen is a running log of the commands executed by the Web Server (activity loads, button executions, etc.).  Once the Web Server is started, this screen will display the URL required to access your activities from a web browser.

 

The Web Server will render the following buttons types in web browsers, and can execute these button types via HTTP requests:

  • IR

  • Command

  • HTTP Request

  • EventTrigger

  • AutoHotKey

  • Global Caché

  • IRTrans

  • Macro

  • Script

  • Link to Activity (browser only)

  • Labels (browser/display only)

  • Group (browser/display only)

 

Note that when a “Link to Activity” button is executed within a browser, the link is executed locally by the browser to load the linked activity, rather than being executed internally on the iOS device.  All other buttons are executed internally within TouchControl on the iOS device.

 

Although by default button script is executed in TouchControl on your device, you can force script to execute locally in the browser by adding the “[web]” flag to the beginning of any script.  You can also then check the “_isWeb” variable to determine if the activity is currently being rendered in a browser, or is being executed normally within TouchControl.  The following is an example of using this flag and variable to conditionally execute script in a browser:

 

[web]

if (_isWeb) {

    document.getElementById('myButton').style.backgroundColor = 'blue';

} else {

    _setBackgroundColor('myButton','blue');

}

 

Note the following:

  • The “[web]” flag must be included in any script that you wish to be evaluated to run in the browser.  Script containing this flag will be executed in the browser when the activity is rendered in a browser, and executed within TouchControl when the activity is loaded within TouchControl.  Any script not containing this flag will only be executed within TouchControl on your device.

  • The “[web]” flag must be found at the beginning of the script, and is internally removed before the script is executed. 

  • When executed in a browser, the condition path where _isWeb is true should contain standard browser-based Javascript.

  • When executed in TouchControl on your device, the condition where _isWeb is false should contain TouchControl-specific Javascript (script you normally use in TouchControl buttons).

  • When rendered in a browser, all buttons are given an HTML ID equal to the button’s name in TouchControl.  The _name variable will be available to your browser script to refer to the name of the button executing the script.

 

When executing buttons via remote HTTP requests, use the following URL scheme:

 

http://192.168.x.x:8822/execbutton?location=Home&activity=Watch%20TV&device=Receiver&name=AllOn

 

Only buttons that have been added to an activity layout are available to execute via HTTP request.  This is because the behavior of buttons can change from activity to activity based on various factors such as custom button properties and activity-specific variables used within script.  The order of the query parameters (location, activity, device, name) does not matter, but they must all be included to execute a button. 

 

Note that the URL shown on the Web Server screen in TouchControl will contain the correct IP address to use when executing remote HTTP requests.  The results of the requests will alse be displayed in the log on the Web Server screen.

 

Scheduled Buttons (iOS 9 and later only)

 

To enable scheduled buttons, while the Web Server is stopped tap the "Enable schedule" button.  This will display a form used to add buttons to the Web Server's schedule, and a list of currently scheduled buttons at the bottom of the screen.  This form has the following required fields:

 

  • Name - This is a unique name you will give the schedule (this does not need to match the name of the button to execute).

  • Schedule for - This is the date/time of the first scheduled execution of the button.

  • Repeat every - The frequency that the button will execute after the initial execution (includes "no repeat")

  • LocationActivityDeviceButton - The specific button the Web Server will execute on the given schedule

 

Use the corresponding buttons on the form to show/hide the selections for each of the above fields.  Once you have completed the form for a given button, an "Add Scheduled Button" button will be available to add the button to the list of scheduled buttons at the bottom of the screen.  This list of scheduled buttons will be displayed at all times while the scheduled is enabled, including while the Web Server is running.  Tap on a currently scheduled button in this list to edit the schedule, or tap the "Edit" button above the list to remove any scheduled button from the list.

 

Once you start the Web Server, you may tap the "Hide" button to send the Web Server to the background while you continue to use TouchControl. The Web Server will continue to service HTTP requests and execute scheduled buttons while TouchControl is in normal use, and reurning to the Web Server screen will show the requests/buttons that were executed while it was in the background.  

 

Important: The first time you start the Web Server after enabling the schedule, TouchControl will prompt you to allow the app to send local notifications. You must answer "YES" to this prompt to allow scheduled buttons to process. If you answer "NO" and later wish to enable scheduled buttons, you must access your iOS device settings, opent the Notifications settings, locate TouchControl in the list, and enable the "Allow Notifications" setting.  Notifications used for executing scheduled buttons will be processed internally by TouchControl, and not visible to you.

 

Note that the TouchControl app must remain in the foreground on your device for the Web Server to continue to function.  If TouchControl is closed, the Web Server will suspend until the app is brought back to the foreground.  Any requests or scheduled buttons that would have executed while the app was in the background will be discarded, and scheduled buttons will start processing again as of the time the app is returned to the foreground.  If TouchControl is stopped/killed, you must restart the Web Server the next time you restart TouchControl.

 

Designing for the Web Server

 

Note that when designing activities for rendering in a browser via the Web Server, only the above-mentioned button types will render.  An attempt has been made to render activities in a browser as closely identical to their rendering within TouchControl as possible, but there may be issues with more complex layouts that cause rendering issues.  Please pass on any issues that you find with basic rendering or that conflict with anything found in this document. 

 

Also For new users, when TouchControl is in "default configuration mode" (i.e. no server was selected when initially setting up the client), the "VoiceControl" activity is the only activity that will render in a browser via the Web Server.  This is because the other activities you will see in TouchControl are more complex and require features not available in a web browser.  The VoiceControl activity was designed to test the VoiceControl feature, resembling a simple TV remote control, and as such the buttons do not actually control anything, but may give you a feel for how activities render in a web browser.  For existing users, this activity is available from the download page on this web site if interested.

 

© 2019 Touch App Technologies, LLC