Go Down

Topic: Access ENC28J60 etherShield Outside Home Network (Read 1 time) previous topic - next topic

dbmiller5

Feb 08, 2013, 02:57 am Last Edit: Feb 08, 2013, 03:12 am by dbmiller5 Reason: 1
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: http://pastebin.com/90T5ginx

Web page code:
Code: [Select]

  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><br><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><br> ") );

  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);

PeterH

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 only provide help via the forum - please do not contact me for private consultancy.

dbmiller5

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

zoomkat

Quote
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.
Consider the daffodil. And while you're doing that, I'll be over here, looking through your stuff.   8)

PeterH


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.
I only provide help via the forum - please do not contact me for private consultancy.

dbmiller5

#5
Feb 09, 2013, 02:51 am Last Edit: Feb 09, 2013, 03:32 am by dbmiller5 Reason: 1

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...



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!
Code: [Select]

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

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 ?
Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

dbmiller5


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. 

dbmiller5

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

dbmiller5


spatula

The action in your <form METHOD=get action="http://192.168.1.15/"> 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.

PeterH

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.
I only provide help via the forum - please do not contact me for private consultancy.

Go Up