I'm trying to connect my pc to my android phone via WIFI..
But the problem is anytime I disconnect my phone from WIFI and turn it on again
I'm getting a different IP address so my pc doesn't connect until I change the IP address to connect to.. Is there any way to get the correct IP address of the phone?
That might be a router settings issue. Have you ever heard of "DHCP Reservation"? Most routers support such an option, which enables the router to memorize an IP to every distinct client ever connected and then to assign this ip to the respective client every time it reconnects.
Check your router settings / documentation for this option.
Here is a link, which could help you with your further investigation:
http://lifehacker.com/5822605/how-to-set-up-dhcp-reservations-so-you-never-have-to-check-an-ip-address-again
Related
I want to run a socket server on android, and read/write data from/to other android devices with different networks.
Here is the problem:
When I'm trying to setup server with external IP, I get java.net.BindException: bind failed: EADDRNOTAVAIL (Cannot assign requested address)
When I setup server with IPv4 address - other android devices from different networks can't connect to it.
What should I do, to link two or more android devices with sockets from different networks?
The main point is run server on any of that devices (client-server code in one app).
You can't bind to an address you don't have.
You need (a) to bind to an interface on your android device, and (b) arrange port forwarding / open the firewall (depends on router+network config) from your router to your android device.
You do not have to bind your server socket to an ip address.
Just dont call bind().
Further your server is only reachable if it runs on an Android device connected with wifi to a router.
If the Android device is on mobile connection your server is not reachable. –
I have an ESP8266 that connects to my WiFi network after being configured (via WiFi Manager library) and runs a HTTP web server that displays certain sensor data. It connects to my specific network with a 192.168.0.XX IP and it works well.
My problem comes with the android app, and how to actually programmatically retrieve the IP that the webserver is running on? My routers DHCP only reserves IP's for a week - so hardcoding the IP into the app is not a good option, and having less tech-savvy people find the IP and configure it themselves is also not what I'm looking to do.
I also can't hardcode a static IP as friends & family will be using this with different networks and routers (so 192.168.0.X would not work on a router with an IP of 10.0.0.1 for example).
So, how do I go about programmatically getting the IP of my ESP8266 that is connected to my local network?
There is a solution that maybe isn't very optimal and professional, but will do for hobby project. You can make your android app scan your local network using http GET on all addresses - e.g. trying to GET something like this: http://192.168.0.X/sensor_status. You can configure your esp8266 device to respond with code 200 (OK) and save this address in your android app's persistent storage. Next time you can simply check if there is ip saved in persistent storage and try to connect to it. If esp8266 is not available under remembered ip, you can re-scan your network.
as you can read in title I'm making a super simple IOT (Not really)
and
using a esp8266 and want to make it connect to my home wifi network and make a communication between a android app and the module (android app connects to home wifi)
Note : Iam Using CODE VISION AVR
you may say :
Why not directly connect to ESP when its on Server Mode?
that's fine cause when ESP is server "he" can set ip for him self so
ip will be always same BUT I want it to connect to home wifi
-
Why you wont connect with IP ?
you cant find the module ip easily because its given by Wifi
-
Find ESP ip using IP scanner
Its not possible cause it changes every time and user have to change
IP every time in android app AND my app cant scann every time it want
to connect to a single device its so dumb...
-
Do a Static Ip for ESP !
well that's not possible too because maybe that IP was taken by
someone before ESP send static IP AT command ! + if IP wasent taken it may taken after Home Wifi Restarts !
Sorry for bad English :X
You can use software serial to configure esp8266 from arduino. You need to know the setup circuit perfectly. Keep it in mind that esp8266 operates on 3.3V where arduino gives 5V output. The most important thing is to send AT commands to esp8266. You can use the following command to connect with your wifi.
AT+CWJAP="Your_WiFi","password"
If you need to see the ip address of esp8266, you can use this command.
AT+CIFSR
If you want to set static ip to esp8266 , then you can try this one.
AT+CIPSTA="ip module","ip gateway","subnet mask"
Use mDNS responder:
https://github.com/esp8266/Arduino/blob/master/libraries/ESP8266mDNS/examples/mDNS_Web_Server/mDNS_Web_Server.ino
This way you would be able to connect to ESP8266 via hardcoded url like http://esp8266.local.
I'm programming a client-server app, my client being an android phone, my server being my laptop.
So my issue is that this one line of code:
Socket connectionToServerSocket = new Socket(hostName, portNumber);
works perfectly fine when my cellular phone connects to the Internet with my home wifi connection, and simply times out when connected through 3G (cellular provider) eg it blocks for a while then throws a timeout exception.
The funky thing is,that I can see (using OS Monitor) that some apps are connected through very common ports, for example port #80, but switching portNumber (as well as the port that the server is listening to) to 80 doesn't help (eg it still times out), and I've tried many different ports-same result.
DNS works fine (eg it translates the logical String which I gave hostName to the correct IP) but it doesn't send the server anything...
I'm lost,what could be the reason? How can I check and resolve it?
I've run into this issue as well doing a similar application.
Your laptop and phone can connect to each other while on the same network because they share a IP address lookup through your router.
When the device is connected to the WIFI, it's request get passed through the router to check for IP addresses, it will find your laptops IP and save a request to a DNS because it can find the laptops IP already. The laptop works the same way, it finds the Ip address of the client through the router as well.
However, when your phone is on 3G, it has no way of knowing exactly where your laptop's IP address is. That's why it times out: it goes from your router to your nearest DNS (where it tries to resolve the correct IP Address), if it cannot find a domain or IP that matches it will fail.
Some steps to fix this . . .
Depending on your router you can set up port forwarding for your laptop's IP. This means incoming requests to your router can be piped to your laptop's server implementation.
Then go to any site like this http://touch.whatsmyip.org/ on your laptop to get your laptops IP. Save this to add to your clients Socket set up.
For debugging until your laptop server is visible for DNS lookup, go into your client code and add this.
Socket debugSocket = new Socket("the.laptop.ip", 80);
Some warnings:
Depending on your Router, your ip may change during restarts
With port-forwarding any browser with your ip, ex) 178.12.434.01 can log onto your laptops personal server
Future Changes:
Once a dedicated server is up and running, registered with a domain you can change the above ip parameter to "your.domain.com", and behind the scenes the actual IP address to your server will be found via DNS lookup.
the reason for that is that the server in your laptop is closed to external network by default, what you need to do is something called port forwarding
*take note: port forwarding put your server in a cyber security risk, make sure you make the right adjustments to keep your server safe.
case 1: It is working when your laptop and your phone is connected to wifi right ?
Try this once
case 2 :
connect your phone to 3G.
enable hotspot on phone.
connect your laptop to your phone's hotspot.
check the IP of your laptop if it is changed replace that in Socket object. Socket connectionToServerSocket = new Socket(newIP, portNumber);
Run your project.
Just try this once you will get what i am trying to say.
You are getting the timeout exception because your server that is
having the service is not reachable from the external network.
Hope this will help :)
I have two android devices - one is a server, second is a client. I run WiFi hotspot on server (using some external app, like QuickSettings), and then connect to this hotspot on second device. I have an application which transfers some data between these devices, so I need to get an IP address of the server to be able to create a socket on client. So my question is how can I do that inside my application (not justing by typing the proper IP manually)?
Did you try assuming the hotspot is the first IP in the valid range?
I mean: The hotspot gives you device an IP and a mask (and it should give even a gateway). The IP of the hotspot is the IP gateway, but if the hostspot did not tell your device such IP, the gateway is usually the first IP in the range allowed by the mask.