通过Wifi在Android和Arduino之间发送数据

时间:2017-07-07 14:37:41

标签: android error-handling arduino wifi

我编程我的Arduino,当我的平板电脑类型192.168.4.1 arduino发送给我Html页面,但当我使用这段代码我不能收到任何数据,我得到这个错误:

  

java.net.MalformedURLException:未找到协议:192.168.4.1

我该如何解决这个问题?

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();
    }
}

1 个答案:

答案 0 :(得分:1)

尝试将http://添加到您的网址:

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