【问题标题】:Send data between Android and Arduino via Wifi通过 Wifi 在 Android 和 Arduino 之间发送数据
【发布时间】:2017-07-07 14:37:40
【问题描述】:

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

【问题讨论】:

    标签: android error-handling arduino wifi


    【解决方案1】:

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

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

    【讨论】:

    • 你使用任何端口吗?尝试在末尾添加/
    • 现在我测试这些 URL url = new URL("192.168.4.1:80"); URL url = new URL("192.168.4.1/");但没用
    • 你有什么想法吗?
    • 您需要添加httphttps 以便它知道您使用的是哪种协议
    • 亲爱的我测试了这些 URL url = new URL("ht tp://192.168.4.1:80"); URL url = new URL("ht t p://192.168.4.1/");它基于 80 端口的 http....我不能使用 https
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-07-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-12-16
    相关资源
    最近更新 更多