0

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 .

2
  • See this and understand every class github.com/EspressifApp/IOT-Espressif-Android It may be help you Commented Nov 19, 2016 at 10:45
  • How to look into that android flow from which folder i have to start tell me for better understandability Commented Nov 19, 2016 at 19:33

1 Answer 1

2

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 server You can use HttpUrlConnection and GET or POST requests on Android side and corresponding script on esp8266 side;

  • if it implements ServerSocket You 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();
Sign up to request clarification or add additional context in comments.

3 Comments

I agreed with your point . But want to ask one doubt socket connection socket server - esp8266 and socket client - android app right ?? #include <ESP8266WiFi.h> #include <WiFiClient.h> WiFiServer server(80); WiFi.mode(WIFI_AP); WiFi.softAP(ssid, password); IPAddress apip = WiFi.softAPIP(); server.begin(); This is socket Connection or HTTP Webserver
"#include <WiFiClient.h> WiFiServer server(80);" - yes, seems it's code for Socket communication. Please see updated answer for example.
Thanks for info..!!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.