Go Down

Topic: connecting to the Arduino server using its IP with android (Read 280 times) previous topic - next topic

ashkan1637

HI, I would really thankful  if someone could help me regarding  IP connectivity .
Lets sat that there is an arduino web server using the Ethernet shield and a web page which switching on/off a LED with its IP ( 192.168.3.10) . so when I enter this IP in  a browser I could see the page and control the LED. Now lets say I wana turn this web page to an android App using PhoneGap.
What code should I use at the top of the HTML code so  the app connects to the arduino IP automatically when it is started ? in other word do the same thing as entering the IP in the browser?
I've tried :

socket = new Socket("192.168.3.10", [80]);

but its not working.
THANKS in advance.

SurferTim

If you are using the Droid's cellular provider for the data connection, you can't use a 192.168.x.x ip. Those are localnet ips.

You basically have two choices:
1) Port forward a port on your public ip (WAN interface on the router) to the port on your Arduino and use the public ip:port.
or
2) Connect to the same router's wifi and use it for the data connection using the 192.168.x.x ip.

That works with my CrackBerry.

ashkan1637

Thanks a lot for your response,
actually I am trying to do the 2nd solution that you've  provided here but i dont know the coding. i may not explained it well.
I convert the web page to an App, then as the phone is connected to the router through a Wifi i wana use a code that when i start the app it automatically connects to the shield as the shield is also connected to the same router and is waiting for a client.
in the Head part of the HTML coding of the web page which i am going to convert it to an android app, what code should i use ?
something like :

<head>
<script>
socket = new Socket("192.168.3.10", [80]);
.
.
</script>
</head>

?

Thanks.

SurferTim

Then you have already gotten the http connection to the Arduino working with your Android? If not, work on that first. Otherwise you could end up chasing your tail. On your Droid web browser:
http://192.168.3.10

Go Up