Search code examples
androidnfcnfc-p2p

P2p NFC communication between Android and Adafruit PN532


I am looking for a way to establish p2p communication between an Android phone (lets call it A) and a PN532+microcontroller (lets call them B).

By p2p I mean a scenario in which:

1. A sends some application specific data to B

2. B receives data and sends a response containing application specific data to A.

I have seen similar questions but most of them date back to 2011, stating that such functionality is not yet supported by the API. Looking at the latest API I can still only see a solution in which B is treated as a TAG.

Am I missing something or is the kind of communication I am looking for is still not supported?


Solution

  • When you want to specifically use NFC peer-to-peer mode, then the same answers are valid today: Android only supports Android Beam for P2P communication. Hence, you can, in general, only transmit one message into one direction and you need to tap the Beam UI each time you want to send data. However, if your interaction is exactly 1 message from Android to PN532 and then 1 message from PN532 to Android, and you are okay with tapping the Beam UI when sending from Android, you could use some tricks to first receive the message from Android, then disconnect and reconnect to send the response to Android.

    When you are open to support other modes, then you have some options:

    1. If the Android device has Android 4.4 or later and supports host card emulation (HCE): Use the PN532 in reader/writer mode and implement a HCE service on the Android side.

    2. Otherwise, use the PN532 in host card emulation mode and access it from the Android side using the standard NFC reader/writer API (e.g. IsoDep / NfcA or NfcF).