Help connecting web server client to WiFly server on LAN

I’m experiencing trouble connecting a client running on my web server to my WiFly server running on my LAN. I have already proven that I can do the opposite, connect my WiFly as a client to the web server. My goal is to send a signal from my iPhone to my WiFly to turn on and off a switch. I already have tested an iPhone app that communicates with my web server.

First off, I’m running the WiFly_WebServer sketch on WiFly. I have no trouble associating to my network. When I power WiFly on, it automatically associates to my router and indicates this with a slow blink green LED. I have not modified the WebServer sketch other than inputting my ssid and passphrase credential. The WebServer sketch is set to port 80.

I’m using a PHP script on my website that executes when I open the webpage. I inputted my router’s IP address as the host IP address (66.31.xxx.xx) on an open port. I’ve tried using ports such as 81, 45000, 9092, etc., any ports that do not show up as officially reserved under http://en.wikipedia.org/wiki/List_of_TC … rt_numbers. As I understand it, my router will receive a request and through port forwarding will route the request to the identified port. I’ve already specified port forwarding for a private IP address of 192.168.1.104 (WiFly). I’m using an Airport Express. I have checked my router logs and statistics and have not been able to find any evidence of contact after running the PHP script.

Thanks for reading. I would appreciate any suggestions for helping me connect to my WiFly server on my LAN.

Andrew

Below the PHP code I’m using on my website server:

<? // form not yet submitted if (!$submit) { ?>

Enter some text:

<input type=“submit”

name=“submit” value=“Send”>

<? } else { // form submitted // where is the socket server? $host="66.31.xxx.xx"; $port = 81; // open a client connection $fp = fsockopen ($host, $port, $errno, $errstr); if (!$fp) { $result = "Error: could not open socket connection"; } else { // get the welcome message fgets ($fp, 1024); // write the user string to the socket fputs ($fp, $message); // get the result $result .= fgets ($fp, 1024); // close the connection fputs ($fp, "END"); fclose ($fp); // trim the result and remove the starting ? $result = trim($result); $result = substr($result, 2); // now print it to the browser } ?>

Server said: <? echo $result; ?>

<? } ?>

Have you done this:

Run the web server on port 8081 of the WiFly. We’ll avoid port 80 and port 8080 in case your home router itself has remote admin enabled on either of these ports (IMO, this should not be enabled - it’s a security risk).

Arrange the WiFly web server’s folders and so on to have a default html content like index.htm and in that file put the barest simple html like hello world in plain text with html header, begin, end tags. No html form, no scripts, just vanilla html.

Give the WiFly a static IP on your LAN, and ensure it cannot conflict with your DHCP server IP address range.

On a PC on your LAN, point the browser to the LAN IP of the WiFly. Prove that the PC to WiFi, via the LAN, no routing needed, works with the html server.

Now ensure your router has a port forward to the LAN IP address of the WiFly, and for port 8081.

Next, you’ll need a computer or smart phone that’s NOT using your LAN or WiFi. Tell it the url for your home: http://111.222.333.444:8081

And if your port-forward is correct, AND IF your ISP does not block ports, it should work. Some ISPs block inward connections to ALL ports to prevent customer operation of their own web servers. Some block by other criteria.

Now, if the PC or smart phone that IS USING your home LAN or WiFi uses your public IP address http://111.222.333.444:8081, the router probably won’t “trombone” that back to the NAT. So you’d use instead http://192.168.1.x:8081 to get to the WiFly.

If all this works, and you disable your router’s use of port 80 for remote admin, you might be able to change WiFly to port 80 instead of 8081.

Hope this helps.

stevech thank you for your reply,

This week I will experiment with WiFly and use your suggestions. I’ll let you know how it’s working out.

I’ve been researching other threads to get a sense of how they accomplished the same goal, like this one http://www.arduino.cc/cgi-bin/yabb2/YaB … 78347111/0.

It sounds like they settled on using the WiFly client sketch to poll a web server every 2-3 seconds in order to detect a request. Do you think this might be a good way of managing the ISP blocking inward connections (if this is in fact a problem)?

I’ve noticed that when I power on the WiFly, it executes the client code and connects with the server. However, it only does this when I power on and then has a “slow blinking” the green LED. How would I modify the code in order to poll my server every 2-3 seconds?