This document will help you to understand and test the Push mode operation of TCG120 controller.
Push mode description
Push mode is intended for easy integration with client-server monitoring programs. When Push mode is enabled, TCG120 (client) begins to send periodically HTTP request messages (POST method) to the monitoring program (server). These HTTP request messages contain XML data (status.xml) which is sent to the server for processing. The monitoring software (server) answers with HTTP response message. The response messages are used not only for confirmation but also to send a command to the TCG120 controller, for example, set r1=1. Below is a typical communication session between TCG120 and remote server:
1 TCG120 sends HTTP POST request with XML data to the remote server;
2 SERVER returns HTTP response message, which contains “set r1=1” command as a brief text in the message body;
3 TCG120 sends HTTP POST request to confirm receiving of the “set r1=1” command;
4 SERVER sends HTTP response, which includes “set FIN” in the message body. This indicates that there are no pending commands and the session can be closed;
5 TCG120 sends next HTTP POST request to the server in connection with Push period timer;
6 SERVER answers with “set FIN” – there is no pending commands and the session can be closed.
Setting Push mode on TCG120 controller
To enable the Push mode, the following parameters should be set:
- Method – HTTP POST should be selected;
- URL – the URL of the remote server;
- Period – the Push period is set between 1 and 255 minutes.
If the checkbox “Connect on any alarm” is selected, the HTTP POST request will be sent if any alarm condition occurs. The “Key” field value is sent in the XML data and can be used for device identification.
If “Process Answer” option is enabled, the TCG120 controller will be able to process the commands, which are sent from the remote server. The valid commands are described below:
|set r1=1||Turn Relay 1 ON|
|set r1=0||Turn Relay 1 OFF|
|set r2=1||Turn Relay 2 ON|
|set r2=0||Turn Relay 2 OFF|
|set tg1=1||Toggle Relay 1 state|
|set pl1=1||Pulse Relay 1|
|set r1=1&r2=1||Turn both relays ON|
|set r1=0&r2=0||Turn both relays OFF|
|set FIN||No pending command|
The typical monitoring application is shown on the picture below:
Testing the Push mode
One of the easiest ways to test the Push mode operation is to use PHP script. The PHP script below can perform the following tasks:
- save the XML data, which is sent by TCG120 controller using HTTP POST method;
- send a command to TCG120 controller.
To test the Push mode operation, please follow the instructions below:
- Copy the pushtest.php file on a public web server with PHP support. To verify that the script is working properly, you can type the URL ( for example www.yourserverURL.com/pushtest.php ) in your web browser. If the script is working, you will receive a web page with the following content “The PHP script is working!”.
- Set TCG120 to send HTTP POST requests to your web server. Enter the script address (yourserverURL.com/pushtest.php) in the URL field. Click on “Test Push” button.
- Check the result. If the HTTP POST is received and processed, the PHP script will create an XML file called pushtest.xml in the same directory, where pushtest.php is located. The XML file will be available on yourserverURL.com/pushtest.xml. This XML file contains information about the sensors and status of the TCG120 inputs and outputs.
- Send command to TCG120. To send a command you need to modify the script – replace “set FIN” (row 5) with some of the valid commands. If you replace “set FIN” with “set tg1=1”, the Relay 1 output will change in every HTTP response received from the server.