Nfc connect to bluetooth device

HOw to pair the bluetooth in two devices using NFC

I am trying to pair two devices One is Google Nexus S which has the applicaion running which reads the mac address written over the tag which is stuck on the other phone which is not Android one . Now i am trying to pair the devices as i tap on the other phone , my application reads the MAC address stored in the TAG and automatically creates the Bluetooth connection . Everything is working fine but i am getting a pairing request or to match the keys on both the phones which should not come. Here is the Bluetooth Segment where the connection is happening

private class ConnectThread extends Thread < private final BluetoothSocket mmSocket; private final BluetoothDevice mmDevice; private String mSocketType; public ConnectThread(BluetoothDevice device, boolean secure) < mmDevice = device; BluetoothSocket tmp = null; mSocketType = secure ? "Secure" : "Insecure"; // Get a BluetoothSocket for a connection with the // given BluetoothDevice try < if (secure) < tmp = device.createRfcommSocketToServiceRecord( MY_UUID_SECURE); >else < tmp = device.createInsecureRfcommSocketToServiceRecord( MY_UUID_INSECURE); Log.d("CHECK", "Sucessfully created insecure socket"); >> catch (IOException e) < Log.e(TAG, "Socket Type: " + mSocketType + "create() failed", e); >mmSocket = tmp; > public void run() < Log.i(TAG, "BEGIN mConnectThread SocketType:" + mSocketType); setName("ConnectThread" + mSocketType); // Always cancel discovery because it will slow down a connection mAdapter.cancelDiscovery(); Log.d("CHECK", "Inside RUN"); // Make a connection to the BluetoothSocket try < // This is a blocking call and will only return on a // successful connection or an exception Log.d("CHECK", "Trying to connect"); mmSocket.connect(); Log.d("CHECK", "Tried to connect"); >catch (IOException e) < // Close the socket try < mmSocket.close(); Log.d("CHECK", "Socket closed"); >catch (IOException e2) < Log.e(TAG, "unable to close() " + mSocketType + " socket during connection failure", e2); >Log.d("CHECK", "Connection failed"); connectionFailed(); return; > // Reset the ConnectThread because we're done synchronized (BluetoothChatService.this) < mConnectThread = null; >// Start the connected thread connected(mmSocket, mmDevice, mSocketType); Log.d("CHECK RESULT", "Sucessfully connected"); // Toast.makeText(BluetoothChatService.ConnectThread.this, "Sucessfully connected" , Toast.LENGTH_LONG).show(); > public void cancel() < try < mmSocket.close(); >catch (IOException e) < Log.e(TAG, "close() of connect " + mSocketType + " socket failed", e); >> > 

I am trying for the insecure connection , but i dont know why it is asking for the pairing keys in both the phones.

Читайте также:  Айфон есть ли bluetooth

Hello, I need the same functionality to be develop. Please suggest me how you pair devices when they come closer and start transferring NDEF messages. Please reply me. Its urgent Please.

Источник

How to encode a NFC tag to pair a smart phone to a bluetooth device

Preface: I am brand new to NFC and not a programmer. Doing the best I can to figure out how to accomplish what I’m looking to do and learn in the process. I am attempting to write a NFC tag (using a NXP NTAG215) with GoToTags on Windows using an ACS ACR122 reader/writer via USB connection that pairs a smart phone with a bluetooth speaker. The trouble I’m running into is that GoToTags does not have a bluetooth record built in. I have been searching a lot on the NFCForum (and Google in general) to try to understand how to encode the tag with the bluetooth MAC address I want to pair to, but I’m not sure which type of record in GoToTags to use to do it (or if it is possible). I have seen some binary content from NFCForum, but I don’t have the fundamental understanding of programming/NFC to really do much with that information. My options for records are Android App, Application, Bing Maps, Bing Search, Contact Info, Email, Facebook Profile, Geo Location, Google Maps, Google Search, Local File, Mime Type, Phone Number, Plain Text, Text Message, Twitter Profile, Uri, Website, and YouTube Video. I was thinking I might be able to use the Mime Type or Plain Text record to put in some magic string that asks users to pair (or automagically pairs) to the bluetooth speaker, but I’m really struggling to find what I need. I have also tried using another NFC read/write software on Windows (NFC Tools) to write a bluetooth tag, but it does not work when I scan it with my text iPhone 7 Plus and when I read the tag with GoToTags, it shows an unknown record with a long data string «D220086170706C69636174696F6E2F766E642E626C7565746F6F74682E65702E6F6F620800000000000000.» This might simply be over my head (well, it obviously is right now), and it seems most people are using their knowledge of programming to create their own apps and software. I don’t have a smart phone (just a friend’s iPhone 7 Plus to try to read the tags I create on my Windows machine when I see them—so not that often) and I know there are a lot of Android apps that write bluetooth tags, but I want this to work from my Windows machine, if possible, using GoToTags. Thanks for any help!

Читайте также:  Bluetooth ps3 controller windows

1 Answer 1

The mimeType you need is application/vnd.bluetooth.ep.oob

If you decode that Hex String to Text with https://codebeautify.org/hex-string-converter you get «application/vnd.bluetooth.ep.oob» as the mimeType.

Looking at the Hex string it has the right NDEF headers in front of the mimeType but comparing it to an Android App writes for «Bluetooth Secure Simple Pairing» record, it writes 08 00 followed by the Mac Address in reverse

Update: From the bluetooth spec (Section 3.1) 08 00 is the OOB Optional Data Length (which includes the 2 bytes of itself + the 6 bytes of the Mac Address)

So if you look for «oob» + 08 00 or 6F6F620800 in your string as a pointer to where the MAC address should start then in the string this is correct. What you seem to be missing is any MAC address (It’s all zeros), which is why the Iphone probably won’t do anything with it.

According to an NXP app reading this NDEF record it was stored as a «Short Record» Section 3.2.4 in the spec linked. and the 08 00 is part of the payload data

So Try writing with your windows software a mimeType record of «application/vnd.bluetooth.ep.oob» with the data of 08 00 + MAC address reversed.

E.g. If the MAC Address is A1:B1:C1:A2:B2:C2

The Hex data to write would be 08 00 C2 B2 A2 C1 B1 A1

Источник

Connect Bluetooth devices to your mobile phone via NFC

More and more Bluetooth devices are additionally equipped with NFC

By now, most electronic devices have been equipped with Bluetooth for quite some time and many people appreciate the advantages. Bluetooth allows devices to be connected wirelessly, eliminating the need for cables to exchange data between two devices. For example, a playlist can be sent from a mobile phone to Bluetooth headphones without a cable connection.

However, many manufacturers, such as Sony, Samsung and Sennheiser, are now beginning to equip their devices with an additional NFC function. NFC is also a standard for wireless data exchange between two devices. However, the range of NFC is limited to a few centimetres.

Bluetooth devices with NFC function

  • NFC Headphones
  • NFC Headsets
  • NFC Loudspeaker
  • NFC Sound Bars
  • NFC Keyboards
  • NFC Mouse
  • NFC Printer
  • NFC Cameras
  • NFC Hands-free kits
  • NFC Car radios
  • NFC Clocks

However, the question arises: What exactly are the benefits of NFC in Bluetooth devices, when you can simply pair your smartphone with these devices via Bluetooth?

Advantages of Bluetooth devices with NFC function

To answer this question, it is important to understand the difference between pairing devices via Bluetooth and via NFC. You can read more about the fundamental differences between the two standards for wireless data transmission in our article Bluetooth vs. NFC.

Читайте также:  Arduino and bluetooth shield

How does device pairing via Bluetooth work?

Once the Bluetooth feature is turned on, the smartphone automatically scans its surroundings and searches for connection partners. Since almost every electronic device now supports Bluetooth, the user is then shown a list of all connection partners. From this list, the user selects the desired device and in many cases must confirm the connection by entering a PIN. The smartphone remembers the connection partner as trustworthy and will then connect automatically without entering a PIN as soon as the device is within range.

How does the coupling of devices via NFC work?

As soon as the NFC function is activated in the smartphone, it is sufficient to hold the smartphone briefly near an NFC device. On the NFC device, the appropriate place for this is usually marked with the official NFC symbol. With some devices, the user must then briefly confirm the connection process on his smartphone.

What are the advantages of pairing Bluetooth devices via NFC?

NFC is basically used to speed up the connection process via Bluetooth. The actual connection and data transfer still takes place via Bluetooth, but NFC sets this process in motion more quickly.

Advantage 1: Due to the short range of NFC, it is clear what the smartphone is supposed to connect to. Therefore, no long list of connection partners is displayed.

Advantage 2: The short range of NFC is also an advantage if you regularly connect to several devices. Bluetooth remembers previous connection partners and tries to establish a connection automatically, but if several trustworthy devices are within range, the user has to select the right device from a list again.

Advantage 3: No PIN entry is necessary to confirm the connection process. When pairing via NFC, a dialog window appears on the smartphone which is confirmed by simply touching the «Okay Button».

How pairing a smartphone with a Bluetooth actually works, you can read here for Android and iPhone.

In summary, the short range of NFC in particular provides more clarity for the smartphone when it comes to the right connection partner. This saves a few steps such as selecting the right device from a list of possible connection partners and entering the PIN for confirmation.

Further information

First published: 28.04.2020 / Updated: 23.07.2020 2020-04-28 2020-07-23

Источник

Оцените статью
Adblock
detector