如何使用android应用程序控制覆盆子pi gpio端口?

使用Android应用程序控制Raspberry Pi的GPIO端口有哪些方法可用?

我已经看过使用nodejs和简单的socketio – 但是如何去实现这个技术真的不明智吗?

有人能够更多地解释这种方法/build议一个替代scheme/有现有的例子吗?

谢谢

我build议您使用Bottle web服务器将树莓派制作成web服务器,然后开发一个android应用程序,向web服务器发送HTTP请求以控制GPIO引脚。 你可以使用这个类来创buildhttp请求:

class RequestTask extends AsyncTask<String, String, String> { @Override protected String doInBackground(String... uri) { HttpClient httpclient = new DefaultHttpClient(); HttpResponse response; String responseString = null; try { response = httpclient.execute(new HttpGet(uri[0])); StatusLine statusLine = response.getStatusLine(); if(statusLine.getStatusCode() == HttpStatus.SC_OK){ ByteArrayOutputStream out = new ByteArrayOutputStream(); response.getEntity().writeTo(out); out.close(); responseString = out.toString(); } else{ //Closes the connection. response.getEntity().getContent().close(); throw new IOException(statusLine.getReasonPhrase()); } } catch (ClientProtocolException e) { //TODO Handle problems.. } catch (IOException e) { //TODO Handle problems.. } return responseString; } @Override protected void onPostExecute(String result) { super.onPostExecute(result); Toast.makeText(getApplicationContext(), result, 0).show(); } } 

例如,当您按下应用程序中的button时发出http请求。 你只需在函数中写入:

  new RequestTask().execute("http://192.168.1.145:80/3"); 

在我的例子中,我假设应用程序和树莓派连接在同一个networking中。