We use cookies to personalise content and ads, to provide social media features and to analyse our traffic. We also share information about your use of our site with our social media, advertising and analytics partners who may combine it with other information that you've provided to them or that they've collected from your use of their services.

PHP redirection

One of the ways to circumvent the limitation of the single-domain rule is to direct all the communication through a PHP file placed at a web server.  The script presented below has been proposed by Janus, who uses it successfully to launch his visualizations.  Here is the content of the wago.php file:

<?php
IF ($_REQUEST['TYPE']=='READPI') {
	$url = "http://192.168.1.1/READPI?ADR=" . $_REQUEST['ADR'] ."&FORMAT=" . $_REQUEST['FORMAT'] ;
};

IF ($_REQUEST['TYPE']=='WRITEPI') {
	$url = "http://192.168.1.1/WRITEPI?ADR1=" . $_REQUEST['ADR1'] .
	"&VALUE1=" . $_REQUEST['VALUE1'] . "&FORMAT1=" . $_REQUEST['FORMAT1'] ;
};

$handle = fopen($url,"r") ;
$contents = stream_get_contents($handle) ;
fclose($handle) ;
echo $contents;
?>

The only thing, which needs to be updated is the PLC’ IP number (here: 192.168.1.1). I also expect, but it was not tested, that in case you intend to place the php and html pages on a remote server, which has no direct access to your home network, that you can enter the name and the port of a ddns domain (like dyndns, etc), at which the PLC is available to the external network.

You also need to modify my jQuery plugin. In the $.fn.WriteValue function you need to replace:

var AjaxObj = $.ajax({
	type: 'POST',
	url: ServerName+"WRITEPI",
	data: {ADR1: options.address, VALUE1: options.value, FORMAT1: options.format},
	(…)

with:

var AjaxObj = $.ajax({
	type: 'POST',
	url: ServerName,
	data: {TYPE: 'WRITEPI', ADR1: options.address, VALUE1: options.value, FORMAT1: options.format},
	(...)

Also in the $.fn.ReadValue you need to replace:

var AjaxObj = $.ajax({
	type: 'POST',
	url: ServerName+"READPI",
	data: {ADR: options.address, FORMAT: options.format}

with:

var AjaxObj = $.ajax({
	type: 'POST',
	url: ServerName,
	data: {TYPE: "READPI", ADR: options.address, FORMAT: options.format}

Additionally, in your html file you should change the value of the ServerName from what I show in the examples:

var ServerName='http://192.168.1.3/';

to:

var ServerName='http://www.yourserver.com/wago.php';

All the above-described steps allow to put all the ajax request executed by the html page through a PHP file, which redirect them to the PLC.  If both the PHP and HTML files are put on the same serve, they should work in all the browsers (with the exception of IE….)