title: read html code made by arduino at android
body: <p>I want to read <code>html</code> code of <code>arduino</code> web server.<br>
  I can make web server simply with from <a href="http://wiki.seeedstudio.com/Wifi_Shield_V2.0/#example-6-wifi-shield-and-android-app" rel="nofollow noreferrer">example 4</a>. code is below.</p>
  
  <pre><code>#include &lt;SoftwareSerial.h&gt;
  #include "WiFly.h"
  
  #define SSID      "yum2"
  #define KEY       "yum000000"
  // check your access point's security mode, mine was WPA20-PSK
  // if yours is different you'll need to change the AUTH constant, see the file WiFly.h for avalable security codes
  #define AUTH      WIFLY_AUTH_WPA2_PSK
  
  int flag = 0;
  
  // Pins' connection
  // Arduino       WiFly
  //  2    &lt;----&gt;    TX
  //  3    &lt;----&gt;    RX
  
  SoftwareSerial wiflyUart(2, 3); // create a WiFi shield serial object
  WiFly wifly(&amp;wiflyUart); // pass the wifi siheld serial object to the WiFly class
  
  void setup()
  {
    wiflyUart.begin(9600); // start wifi shield uart port
    Serial.begin(9600); // start the arduino serial port
    Serial.println("--------- WIFLY Webserver --------");
  
    // wait for initilization of wifly
    delay(1000);
  
    wifly.reset(); // reset the shield
    delay(1000);
    //set WiFly params
  
    wifly.sendCommand("set ip local 80\r"); // set the local comm port to 80
    delay(100);
  
    wifly.sendCommand("set comm remote 0\r"); // do not send a default string when a connection opens
    delay(100);
  
    wifly.sendCommand("set comm open *OPEN*\r"); // set the string that the wifi shield will output when a connection is opened
    delay(100);
  
    Serial.println("Join " SSID );
    if (wifly.join(SSID, KEY, AUTH)) {
        Serial.println("OK");
    } else {
        Serial.println("Failed");
    }
  
    delay(5000);
  
    wifly.sendCommand("get ip\r");
    char c;
  
    while (wifly.receive((uint8_t *)&amp;c, 1, 300) &gt; 0) { // print the response from the get ip command
        Serial.print((char)c);
    }
  
    Serial.println("Web server ready");
  
  }
  
  void loop()
  {
  
      if(wifly.available())
      { // the wifi shield has data available
          if(wiflyUart.find("*OPEN*")) // see if the data available is from an open connection by looking for the *OPEN* string
          {
              Serial.println("New Browser Request!");
              delay(1000); // delay enough time for the browser to complete sending its HTTP request string
              // send HTTP header
              wiflyUart.println("HTTP/1.1 200 OK");
              wiflyUart.println("Content-Type: text/html; charset=UTF-8");
              wiflyUart.println("Content-Length: 244"); // length of HTML code
              wiflyUart.println("Connection: close");
              wiflyUart.println();
  
              // send webpage's HTML code
              wiflyUart.print("&lt;html&gt;");
              wiflyUart.print("&lt;head&gt;");
              wiflyUart.print("&lt;title&gt;My WiFI Shield Webpage&lt;/title&gt;");
              wiflyUart.print("&lt;/head&gt;");
              wiflyUart.print("&lt;body&gt;");
              wiflyUart.print("&lt;h1&gt;Hello World!&lt;/h1&gt;");
              wiflyUart.print("&lt;h3&gt;10 20 30 40 50&lt;/h3&gt;");
              wiflyUart.print("&lt;a href=\"http://yahoo.com\"&gt;Yahoo!&lt;/a&gt; &lt;a href=\"http://google.com\"&gt;Google&lt;/a&gt;");
              wiflyUart.print("&lt;br/&gt;&lt;button&gt;My Button&lt;/button&gt;");
              wiflyUart.print("&lt;/body&gt;");
              wiflyUart.print("&lt;/html&gt;");
          }
      }
  }
  </code></pre>
  
  <p>the web server work well. </p>
  
  <p>I wrote simple android code to read <code>html</code> is below.  </p>
  
  <pre><code>package com.example.http;
  
  import android.os.Handler;
  import android.support.v7.app.AppCompatActivity;
  import android.os.Bundle;
  import android.util.Log;
  import android.view.View;
  import android.widget.Button;
  import android.widget.TextView;
  import java.io.BufferedReader;
  import java.io.InputStreamReader;
  import java.net.HttpURLConnection;
  import java.net.URL;
  
  public class MainActivity extends AppCompatActivity {
      private TextView tv;
      String urlAddress = "192.168.0.10"; // doesn't show
     // String urlAddress = "http://www.kma.go.kr/weather/main.jsp#1159068000"; // work well
      Handler handler = new Handler();
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
               super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
          tv = (TextView)findViewById(R.id.textView1);
          Button b = (Button)findViewById(R.id.button1);
          b.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                  loadHtml();
              }
          });
      }
  
      void loadHtml() {
          Thread t = new Thread(new Runnable() {
              @Override
              public void run() {
                  final StringBuffer sb = new StringBuffer();
  
                  try {
                      URL url = new URL(urlAddress);
                      HttpURLConnection conn =
                              (HttpURLConnection) url.openConnection();
                      if (conn != null) {
                          conn.setConnectTimeout(2000);
                          conn.setUseCaches(false);
                          if (conn.getResponseCode()
                                  == HttpURLConnection.HTTP_OK) {
  
                              BufferedReader br
                                      = new BufferedReader(new InputStreamReader
                                      (conn.getInputStream()));
                              while (true) {
                                  String line = br.readLine();
                                  if (line == null) break;
                                  sb.append(line + "\n");
                              }
                              br.close();
                          }
                          conn.disconnect();
                      }
  
                      Log.d("test", sb.toString());
                      handler.post(new Runnable() {
                          @Override
                          public void run() {
                              tv.setText(sb.toString());
                          }
                      });
                  } catch (Exception e) {
                      e.printStackTrace();
                  }
              }
          });
          t.start();
      }
  }
  </code></pre>
  
  <p>It work very well with  <code>String urlAddress = "http://www.kma.go.kr/weather/main.jsp#1159068000";</code><br>
  but it doesn't show when using 
  <code>String urlAddress = "192.168.0.10";</code> instead of before one. 
  the <code>192.168.0.10</code> is allocated ip of <code>arduino</code> from DHCP that i can check on serial monitor.  </p>
  
  <p>there is any way to read html from arduino web server??</p>