Search code examples
androiderror-handlingarduinowifi

Send data between Android and Arduino via Wifi


I program my Arduino and when in my tablet type 192.168.4.1 arduino send me Html page but when I use this code I cant receive any data and I get this error:

java.net.MalformedURLException: Protocol not found: 192.168.4.1

How can I solve this problem?

private void getdata(){

    try {
        URL url = new URL("192.168.4.1");
        HttpURLConnection conn = (HttpURLConnection) url.openConnection();
        conn.connect();
        InputStream inputStream = conn.getInputStream();
        InputStreamReader inputStreamReader = new InputStreamReader(inputStream, "UTF-8");
        BufferedReader bufferedReader = new BufferedReader(inputStreamReader);

        String data = "", line = "";
        StringBuffer buffer = new StringBuffer();
        while ((line = bufferedReader.readLine()) != null) {
            // data += line + "\n";
            buffer.append(line + "\n");
        }
        Thread.sleep(4000);
    } //end try

    Log.e("errrorrrrrrrrrrrr", e.toString());
        e.printStackTrace();

    } catch (IOException e) {
        e.printStackTrace();
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
}

Solution

  • try to add http:// to your url :

    URL url = new URL("http://192.168.4.1");