I want some brief idea/links for reference to start how to connect esp8266 router/access point with an android app.In esp8266 static ip is 192.168.4.1 wants to control led blink or other feautre with an android app . how to make establish connection between esp8266 and android app .
-
See this and understand every class github.com/EspressifApp/IOT-Espressif-Android It may be help youVishal Senjaliya– Vishal Senjaliya2016-11-19 10:45:46 +00:00Commented Nov 19, 2016 at 10:45
-
How to look into that android flow from which folder i have to start tell me for better understandabilityayushi mundra– ayushi mundra2016-11-19 19:33:31 +00:00Commented Nov 19, 2016 at 19:33
1 Answer
On Android side it's just network communication without any features. Take a look at Official Documentation and tutorials like this. Everything depends on esp8266 firmware:
if it implements
HTTP web serverYou can use HttpUrlConnection and GET or POST requests on Android side and corresponding script on esp8266 side;if it implements
ServerSocketYou can use Socket connection an implement Socket Client on Android side.
Update:
Socket communication with esp8266 You should do it in separate (not UI) thread. Full example is something like that:
class SocketClientThread implements Runnable {
DataInputStream dis;
DataOutputStream dos;
String strResponseData;
@Override
public void run() {
try {
InetAddress serverAddr = InetAddress.getByName("<address>");
clientSocket = new Socket(serverAddr, <port_number - 80 in your example>);
dos = new DataOutputStream(clientSocket.getOutputStream());
dis = new DataInputStream(clientSocket.getInputStream());
// now you can write data to stream
dos.writeUTF("Hello");
// you can also read data from stream
strResponseData = dis.readUTF();
} catch (UnknownHostException ignore) {
} catch (IOException ignore) {
}
finally{
if (clientSocket != null){
try {
clientSocket.close();
}
catch (IOException ignore) {
}
}
}
}
}
And than You can use SocketClientThread this way:
Thread socketClientThread;
socketClientThread = new Thread(new SocketClientThread());
socketClientThread.start();
3 Comments
Socket communication. Please see updated answer for example.