Take the 2-minute tour ×
Arduino Stack Exchange is a question and answer site for developers of open-source hardware and software that is compatible with Arduino. It's 100% free, no registration required.

I'm using an Arduino Wi-Fi shield to make a web server to get sensors values on an Android app (client).

I used the code given by Arduino, WiFi Web Server.

I made an Android app, and at the moment I can send strings from Android to Arduino, but not from Arduino to Android app.

I want to know how I can send data from Arduino to Android. I don't know how made this on Arduino, and Android...

//code used to send data from android to arduino
private static final int SERVER_PORT = 8081;
private static final String SERVER_IP = "192.168.1.98";
private Socket socket;

// ...
    public void startThread(){
        Thread thread = new Thread() {
            @Override
            public void run() {
                try {
                    InetAddress serverAddr = InetAddress.getByName(SERVER_IP);
                    socket = new Socket(serverAddr, SERVER_PORT);
                } catch (UnknownHostException e1) {
                    e1.printStackTrace();
                } catch (IOException e1) {
                    e1.printStackTrace();
                }
            }
        };
        thread.start();
    }

//...
try {
    PrintWriter out = new PrintWriter(new BufferedWriter(new     OutputStreamWriter(socket.getOutputStream())), true);
            out.println(30);// for example i send 30 to arduino
} catch //...
share|improve this question

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.