I like where you're going with this. If you want the server to be on your side of the router then we don't care about ports, just IP addresses just like you said.
forlotto wrote:So here is the idea to turn my ACUnit on:
This is sent from remote host first
http://serverip/prTGs21zw=0 "On for my ac"
http://serverip/prTGs21zw=1 "Off for my ac"
http://serverip/prTGs21zw=r "Read Status Of My AC"
The server will receive this and translate it to:
http://192.168.1.133/msg?pin=1stat=0 "on for ac"
http://192.168.1.133/msg?pin=1stat=1 "off for ac"
http://192.168.1.133/msg?stat=r "read ac status"
So I modified the previous code to do what you're suggesting (although I think you've malformed the requests to the ESPs. I think that ...msg?pin=1stat=1 should be ...msg?pin=1&stat=1).
$dev=array(
array('name'=>'Gdoor', 'esp_ip'=>'192.168.1.133', 'pin'=>3 ),
array('name'=>'ACunit', 'esp_ip'=>'192.168.1.133', 'pin'=>1 ),
array('name'=>'Light1', 'esp_ip'=>'192.168.1.134', 'pin'=>1 )
);
foreach ($dev as $k=>$v) {
$cmd=$_REQUEST[$dev[$k]['name']];
if ($cmd!='') {
$url="http://" . $dev[$k]['esp_ip'] . "/msg?";
if ($cmd!='r') $url .= "pin=" . $dev[$k]['pin'] . "&";
$url .= "stat=" . $cmd;
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
$output = curl_exec($curl);
curl_close($curl);
print $output;
}
}
You can replace the somewhat readable device names with anything more cryptic if you like. This code supports multiple ESPs having different ip addresses on your local subnet and keeps track of the proper pin for each device. I'm doing something similar but more complex, allowing control of pwo, servo, temp, etc. in addition to digital I/O.
When you request the status of a pin, the target ESP can just return that to the server which will echo it to your browser. You could have the server generate a page using AJAX to make all those on/off/r calls for you at the click of a button. Not hard if you know javascript and then you have one nifty single page control panel with buttons and status displays for all your devices - and which works on your PC or phone with no typing necessary.