Access ENC28J60 etherShield Outside Home Network

Hi guys,

I need your help on what I think is an simple problem. I have a program working for my etherShield but not all of it works from outside my home network. My program toggles a digital output from web. My web page shows up onside my network, but the switch does not work. I am using my public IP to see the webpage, and I forwarded port 80 to the internal IP of my etherShield.

Public IP example: 24.165.89.18:80
Internal IP of etherShield: 192.168.1.15

I see the webpage from outside my network, but it does not function.
help =(

Project Code: Ethernet_Project - Pastebin.com

Web page code:

  int i=0;
 
 
  uint16_t plen;
 
 
 
  plen=es.ES_fill_tcp_data_p(buf,0,PSTR("HTTP/1.0 200 OK\r\nContent-Type: text/html\r\n\r\n"));
  plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("<center><p><h1>Welcome to the DBM Switch Controller </h1></p> "));
 
  plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("<hr>
<form METHOD=get action=\""));
  plen=es.ES_fill_tcp_data(buf,plen,baseurl);
  plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("\">"));
  plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("<h2> REMOTE SWITCH: </h2> "));
  plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("<h1><font color=\"#00FF00\"> "));
 
  if(on_off)
    plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("ON"));
  else
    plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("OFF"));
 
  plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("  </font></h1>
 ") );
 
  if(on_off){
    plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("<input type=hidden name=cmd value=3>"));
    plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("<input type=submit value=\"Switch off\"></form>"));
  }
  else {
    plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("<input type=hidden name=cmd value=2>"));
    plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("<input type=submit value=\"Switch on\"></form>"));
  }
 
 
  return(plen);

Presumably the web page has a control that triggers an HTTP transaction of some sort?

I suggest you post the page source of a typical page so that we can see what it is supposed to do.

I put a link to my whole project code. I also revised my post and added the code for the web page. Thanks!

I forwarded port 80 to the internal IP of my etherShield.

Some ISPs block port 80 access to home accounts to prevent commercial use. You might try another port.

dbmiller5:
I put a link to my whole project code. I also revised my post and added the code for the web page. Thanks!

Can you post the source of a sample web page, i.e. what the browser actually receives? I don't want to have to wade through the code guessing what it does. Most browsers provide a means to show the source of the currently loaded page. Just paste the source here, in CODE tags.

zoomkat:
Some ISPs block port 80 access to home accounts to prevent commercial use. You might try another port.

I tried this but it didnt work. I could not even see the page using my wan IP and a random port. I thought this was a good idea but...

PeterH:
Can you post the source of a sample web page, i.e. what the browser actually receives? I don't want to have to wade through the code guessing what it does. Most browsers provide a means to show the source of the currently loaded page. Just paste the source here, in CODE tags.

Good idea!

<center><p><h1>Welcome to the DBM Switch Controller </h1></p> <hr>
<form METHOD=get action="http://192.168.1.15/"><h2> REMOTE SWITCH: </h2> <h1><font color="#00FF00"> ON  </font></h1>
 <input type=hidden name=cmd value=3><input type=submit value="Switch off"></form>

The only IP address in that page source is the local address of your Arduino, should it not be the public address of your router ?

UKHeliBob:
The only IP address in that page source is the local address of your Arduino, should it not be the public address of your router ?

When I put my public IP in my code, I cannot connect to it from public or private lan. When I put in the 192.168.1.X in my code, and use my public IP in browser, I can connect to it but other people cannot.

I am still stuck on this problem. Anymore suggestions would be appreciated.

I would love some help, anyone?

The action in your is called by the browser. It will work if the browser can access it (true from the local network only). Since you are using functions from the etherShield library you may be able to retrieve the address of the browser that is sending the request. Then, if it starts with 192.168 you know it's from the local network.

Once you know that, it is easy to change the value of your action so that it reflects the local / public address.

If you cannot get the remote address, your only option is to define different URLs for local and remote clients (e.g. http://192.168.1.15/local, http://your.public.ip/remote). You won't need to define two different pages, just parse the request to differentiate the value of the action.

You are setting the action attribute of the form to "http://192.168.1.15/" so of course that does not work from outside the local network. I guess you're processing the response in the same handler that supplies the original page, so you should be able to get rid of the action attribute completely; it will then default to the URI of the current page.