基本的に、ギャラクシー ノート (4.1.2) を arduino に接続されている bluesmirf とペアにしようとしています ( https://www.sparkfun.com/products/582 )
私はこのプロジェクトをInstructables http://www.instructables.com/id/Missed-calls-and-SMS-Notifier-Accessory/から剥ぎ取り 、コードの小さな部分を置き換えることを提案するフレンドリーなコメントを見つけました。 AndroidがBluetoothモジュールとの接続を確立しようとするたびにパスワードを入力する必要があります(AndroidでペアリングされたBluetoothデバイスに自動接続します)。
私は Avner と同じコードを使用しているので、参照として彼/彼女のコードを借りました。
//////////////////////////////////////////////////////////////////////////
1. Arduino code that sets the connection mode to auto and initiates a
connection with the Android phone
//////////////////////////////////////////////////////////////////////////
void setup()
{
Serial.begin(115200);
Serial.println("BEG setup");
static const char *initString0 = "$$$SR,04FE3144A0A4\r";
// R,1 Forces a complete reboot of the device (similar to a power cycle).
static const char initString1a[] = "$$$";
static const char initString1b[] = "R,1\r";
// auto
static const char initString2a[] = "$$$";
static const char initString2b[] = "SM,3\rSO,Z\r---\r";
static const char *initVector[] = { initString0, initString1a, initString1b, initString2a, initString2b, NULL };
int i;
for (i=0; initVector[i] != NULL; i++)
{
Serial.print(initVector[i]);
delay(500);
}
Serial.println("Setup completed");
}
//////////////////////////////////////////////////////////////////////////
2. Android BluetoothSerialService AcceptThread code that listens to
incoming connection
//////////////////////////////////////////////////////////////////////////
...
private class AcceptThread extends Thread
{
// The local server socket
static private final String TAG = "BluetoothSerialServiceAcceptThread";
private final BluetoothServerSocket mmServerSocket;
private String mSocketType;
/** Creates an thread for accepting incoming Bluetooth connections
* @param secure Currently ignored, but suppose to represent the mode of socket.
* All communication is currently done over insecure socket
*/
public AcceptThread(boolean secure)
{
Log.i(TAG, "BEG AcceptThread::AcceptThread");
BluetoothServerSocket tmp = null;
mSocketType = secure ? "Secure":"Insecure";
// Create a new listening server socket
try
{
Log.i(TAG, "AcceptThread constructor trying to create listening socket");
if (!secure)
{
// This is for Android 2.2
// tmp = mAdapter.listenUsingRfcommWithServiceRecord(NAME_INSECURE, BT_SPP_UUID);
// This is for Android 2.3 but testing the above on 2.3 device showed it to be working.
tmp = mAdapter.listenUsingInsecureRfcommWithServiceRecord(NAME_INSECURE, BT_SPP_UUID);
}
Log.d(TAG, "AcceptThread: Listening BT Socket " + mSocketType + " created");
}
catch (IOException e)
{
Log.e(TAG, "AcceptThread: Listening BT Socket Type: " + mSocketType + " listen() failed " + e.getMessage());
acceptProblem();
}
mmServerSocket = tmp;
Log.d(TAG, "mmServerSocket: " + mmServerSocket);
} // public AcceptThread
public void run()
{
Log.i(TAG, "BEG BluetoothSerialService::run");
if (mmServerSocket == null)
{
Log.e(TAG, "AcceptThread.run: No server socket");
return;
}
Log.d(TAG, "AcceptThread.run: socket type:" + mSocketType);
setName("AcceptThread" + mSocketType);
BluetoothSocket socket = null;
Log.i(TAG, "mState: " + mState);
// Listen to the server socket if we're not connected
while (mState != STATE_CONNECTED)
{
Log.i(TAG, "socket before mmServerSocket.accept(): " + socket);
try
{
// This is a blocking call and will only return on a
// successful connection or an exception
socket = mmServerSocket.accept();
Log.d(TAG, "AcceptThread.run: returned from accept");
}
catch (IOException e)
{
Log.e(TAG, "AcceptThread.run: Socket Type: " + mSocketType + "accept() failed " + e.getMessage());
break;
}
Log.i(TAG, "socket after mmServerSocket.accept(): " + socket);
...
これは私が持っているEclipseからの現在のフィードバックです.elipseはlistenUsingInsecureまたはcreateInsecureRfが未定義であると主張しています
タイプ BluetoothAdapter PhoneInfoServer.java /myPhoneInfoWithService/src/myPhoneInfo/test/zakiem のメソッド listenUsingInsecureRfcommWithServiceRecord(String, UUID) が定義されていません 539 行目の Java 問題
createInsecureRfcommSocketToServiceRecord を使用して listenUsingInsecureRfcommWithServiceRecord を置き換える場合も同様です
個人的には、グーグルで調べた後のAPIバージョンの問題だと思いますが、どうすればこれを機能させることができますか? ここではまったく初心者なので、これに関する助けをいただければ幸いです。
前もって感謝します。