IPを使用してAndroidからarduinoにデータを転送しています。うまくいけば、アクセスポイントとして機能するため、設定のwifiリストでその名前を選択することにより、arduino + esp8266 wifiモジュールとの接続を確立できます。また、どのブラウザからでも、「192.168.4.1:80?pin=13」と書き込むだけで IP にデータを送信できます。ただし、arduinoが受信していないため、リクエストを送信しないAndroidに問題があります。
これが私のコードです。Androidマニフェストにインターネット許可も含めました。それの何が問題なのですか?
final Button image=(Button) findViewById(R.id.button1);
image.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
image.setText("making change");
String urlGET = "http://192.168.4.1:80/?pin=13";
HttpGet getMethod = new HttpGet(urlGET);
// if you are having some headers in your URL uncomment below line
//getMethod.addHeader("Content-Type", "application/form-data");
HttpResponse response = null;
HttpClient httpClient = new DefaultHttpClient();
try {
response = httpClient.execute(getMethod);
int responseCode = response.getStatusLine().getStatusCode();
HttpEntity entity = response.getEntity();
String responseBody = null;
if (entity != null) {
responseBody = EntityUtils.toString(entity);
//here you get response returned from your server
Log.e("response = ", responseBody);
// response.getEntity().consumeContent();
}
JSONObject jsonObject = new JSONObject(responseBody);
// do whatever you want to do with your json reponse data
}
catch(Exception e)
{
e.printStackTrace();
}
}
});
}
}