TCW241_R4.17
–
October 2022
Page 36
8.2.
HTTP API
8.2.1.
HTTP Post
TCW241 can execute HTTP/HTTPS Post to upload XML/JSON file to a dedicated server.
This functionality is very useful if the controller is behind the router without public IP address or
the user don’t h
ave access to router configuration. The server should have a public IP address.
The typical monitoring application is shown in the picture below:
HTTP/HTTPS post can be sent periodically or periodically plus on an alarm condition. As an answer,
the server can send HTTP Get with appropriate command
–
see
8.2.3. HTTP commands
To test HTTP/HTTPS Post follow the steps below:
•
Save following code like post.php:
<?php
define("FILENAME", 'status.xml');
define("FOLDER", '');
define("SEPARATOR", '');
define("STR_SUCCESS", 'set FIN');
define("STR_ERROR", 'error');
if($_SERVER['REQUEST_METHOD'] == 'POST'){
$datePrefix = date('YmdHis', strtotime('now'));
$pathname = FOLDER.SEPARATOR.$datePrefix.'_'.FILENAME;
$postdata = file_get_contents("php://input");
$handle = fopen($pathname, 'w+');
$content = var_export($postdata, true);
fwrite($handle, substr($content, 1, strlen($content)-2));
fclose($handle);
echo (($handle === false) ? STR_ERROR : STR_SUCCESS)."\r\n";
}
else {
echo "The PHP script is working!";
}
?>
•
Copy the post.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/post.php )
in your web browser. If all is OK, a web
page with “The PHP script is working!”
will be
shown.
•
Set the controller to send HTTP/HTTPS POST to your web server. Enter the address
(yourserverURL.com/post.php
) in the URL field. Click on “Test
HTTP Post
” button.
•
If the HTTP/HTTPS POST is received and processed,
“OK” will be shown close to the button.
Along with this, an XML file will be created in the same directory, where post.php is
located. The file name will contain time information and looks like
20151120103318_status.xml.
Summary of Contents for TCW241
Page 1: ...smtp...
Page 16: ...TCW241_R4 17 October 2022 Page 16...
Page 55: ...TCW241_R4 17 October 2022 Page 55 Appendix A Fig 1 Fig 2...