मैं एक ऐसी ही विन्यास (एंड्रॉयड Galaxy S3 फोन 4.0 और आर एन -42 बीटी ऊनो Arduino से जुड़ा) मैं Android और ब्लूटूथ जोड़ी बनाने में और एंड्रॉयड से आर.एन.-42 बीटी से कनेक्ट करने में सक्षम हूँ (राशि मैं इसका परीक्षण करने के लिए ब्लू टर्म ऐप का उपयोग कर रहा हूं) हालांकि, मैं आरएन -42 बीटी से एंड्रॉइड फोन में कनेक्ट करने में असमर्थ हूं। http://www.instructables.com/id/Missed-calls-and-SMS-Notifier-Accessory/
मैं क्रमादेशित 42 बीटी एक ग्राहक के रूप में सेवा और ऑटो के लिए सेट करने के लिए मोड कनेक्ट (एसआर, 3): मैं innstructions और में कोड उदाहरण का पालन किया। मेरे एंड्रॉइड कोड में, BluetoothSerialService (PhoneInfoServer उदाहरण कोड के समतुल्य) AcceptThread पर: socket = mmServerSocket.accept() पर फंस गया है; मैं कोड के निम्न भाग कि कनेक्शन की समस्या से जुड़े हुए हैं संलग्न कर रहा हूँ:
- Arduino कोड कि ऑटो के लिए कनेक्शन मोड सेट और Android फ़ोन
- एंड्रॉयड BluetoothSerialService AcceptThread कोड के साथ एक संबंध की शुरुआत करता है कि कनेक्शन
- logcat संदेश जो पता चलता है कि कोड भेजे कनेक्शन के लिए प्रतीक्षारत अटक गई है आने को सुनता है
Google के ब्लूटूथ में डेमो ऐप में फ़ोन को खोजने योग्य बनाने का एक विकल्प है ताकि एक और फोन इससे जुड़ सके। मैं ब्लूटूथ सीरियल कनेक्शन के लिए कुछ इसी तरह की तलाश में हूं। मैंने Google Play पर एक ऐप की तलाश की है जो ब्लूटूथ सीरियल डिवाइस से आने वाले कनेक्शन अनुरोध के लिए सूचीकरण का परीक्षण करेगा, लेकिन ऐसा ऐप नहीं मिला। क्या कोई ऐसे ऐप के बारे में जानता है?
सादर, Avner
Arduino कोड कि ऑटो के लिए कनेक्शन मोड सेट और एंड्रॉयड फोन
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");
}
एंड्रॉयड BluetoothSerialService AcceptThread
कोड है जो आने वाले कनेक्शन
को सुनता है के साथ एक संबंध शुरू की // ...
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);
//...
logcat संदेश जो पता चलता है कि कोड भेजे कनेक्शन
// ...
12-09 01:04:38.765: I/BluetoothSerialServiceAcceptThread(16175): BEG AcceptThread::AcceptThread
12-09 01:04:38.765: I/BluetoothSerialServiceAcceptThread(16175): AcceptThread constructor trying to create listening socket
12-09 01:04:38.765: V/BluetoothSocket.cpp(16175): initSocketNative
12-09 01:04:38.765: V/BluetoothSocket.cpp(16175): ...fd 49 created (RFCOMM, lm = 0)
12-09 01:04:38.765: V/BluetoothSocket.cpp(16175): initSocketFromFdNative
12-09 01:04:38.775: D/BluetoothUtils(16175): isSocketAllowedBySecurityPolicy start : device null
12-09 01:04:38.775: V/BluetoothSocket.cpp(16175): bindListenNative
12-09 01:04:38.775: V/BluetoothSocket.cpp(16175): ...bindListenNative(49) success
12-09 01:04:38.785: D/BluetoothSerialServiceAcceptThread(16175): AcceptThread: Listening BT Socket Insecure created
12-09 01:04:38.785: D/BluetoothSerialServiceAcceptThread(16175): mmServerSocket: [email protected]
12-09 01:04:38.785: D/BluetoothReadService(16175): END start
12-09 01:04:38.795: I/BluetoothSerialServiceAcceptThread(16175): BEG BluetoothSerialService::run
12-09 01:04:38.795: D/BluetoothSerialServiceAcceptThread(16175): AcceptThread.run: socket type:Insecure
12-09 01:04:38.795: I/BluetoothSerialServiceAcceptThread(16175): mState: 1
12-09 01:04:38.795: I/BluetoothSerialServiceAcceptThread(16175): socket before mmServerSocket.accept(): null
12-09 01:04:38.795: V/BluetoothSocket.cpp(16175): acceptNative
12-09 01:04:38.855: I/MainActivity(16175): mBtStatus: [email protected]
12-09 01:04:38.855: I/MainActivity(16175): In case: BluetoothSerialService.STATE_LISTEN
12-09 01:04:38.855: D/MainActivity(16175): Beg onCreateOptionsMenu
12-09 01:04:38.885: D/memalloc(16175): ion: Mapped buffer base:0x5d760000 size:3768320 offset:0 fd:57
12-09 01:04:38.925: D/CLIPBOARD(16175): Hide Clipboard dialog at Starting input: finished by someone else... !
// ...
मैं आगे पता चला कि आर एन -42 बीटी ऑटो-कनेक्ट मोड में हो रही है, लेकिन एक और गैर एंड्रॉयड एलजी से कनेक्ट करने की कोशिश करता है के लिए इंतज़ार कर अटक गई है घर पर फोन करें।
मैंने इसे आरएन -42 बीटी को कारखाने के डिफ़ॉल्ट पर रीसेट करके खोजा। ब्लू टर्म ऐप का उपयोग करके मैं एंड्रॉइड फोन से आरएन -42 बीटी तक सफलतापूर्वक कनेक्ट हूं। जब मैं एक जांच स्कैन ($$$ I \ r) करता हूं तो मुझे मैक पता और एलजी फोन का नाम मिलता है। इस फोन में एक अलग मैक पता (0026e25d8a91) के साथ ब्लूटूथ है - मुझे नहीं पता कि आरएन -42 बीटी इस डिवाइस के साथ प्रयास करने और कनेक्ट करने का कारण क्या है।
इसका मतलब है कि ऑटो कनेक्ट मोड काम करता है लेकिन कनेक्शन गलत फोन पर निर्देशित होता है। मैं pazzled रहा हूँ क्योंकि मैं निम्न कमांड का प्रयोग को निर्दिष्ट कर रहा हूँ Android फ़ोन की मैक पते
// The mac address of the android phone
$$$SR,04FE3144A0A4\r
// Force a complete reboot of the device (similar to a power cycle).
$$$R,1\r
// SM,3 - mode=auto
// SO,Z - Extended Status String, Setting this string enables status messages to be sent to the local serial port.
// --- - exit command mode (three minus signs).
$$$SM,3\rSO,Z\r---\r
अब मैं सोच रहा हूँ कि आर एन -42 बीटी से कनेक्शन दीक्षा ठीक है (उन दोनों के बीच देरी के साथ) लेकिन एंड्रॉइड कोड पर BluetoothServerSocket ठीक से स्थापित नहीं है।
मैंने listenUsingInsecureRfcommWithServiceRecord और listenUsingRfcommWithServiceRecord का उपयोग करके सुनने के लिए BluetoothServerSocket सेट करने का प्रयास किया है। मुझे लगता है कि एक कमांड createInsecureRfcommSocketToServiceRecord है। क्या मुझे इसका इस्तेमाल करना चाहिए?
किसी भी सलाह की सराहना की जाएगी।
धन्यवाद, Avner
भूल आप अपने खुद के जवाब को स्वीकार कर सकते है। –
तो उदाहरण के लिए, क्या आप जानते हैं कि मैं अपने निकटतम ब्लूटूथ डिवाइस से कनेक्ट करने के लिए केवल मैन्युअल रूप से ब्लूटूथ सक्रिय करने के साथ कैसे कर सकता हूं? –