So if you like me wanted to do a project using NFC peer-to-peer (P2P) between Android and Arduino (the P532 chip) there is no doubt that you have spent countless hours searching for libraries or examples which have already implemented this feature. You may have even built test application for Android (I used this one) and a sketch for your Arduino (I started with this sketch). I at least saw that the NFC was communicating between the devices so it’s a start. It took me a few days of searching before I even got to this point. Now I needed to figure out why I wasn’t actually sending the NDEF message from Android — the breakpoint at createNdefMessage is never reached.
So lets lay down some facts:
- You are using the PN532 NFC chip.
- You are attempting to send a message between your Android device and your Arduino
- You want peer-to-peer between the devices.
- The protocol is SNEP on top of LLCP.
As I said, I spent a long time looking for a c/c++ library which already implemented this protocol. I haven’t looked too much into the source of libnfc at this point but I found a java library which implements the protocols for a specific card reader. I really didn’t feel like digging through that code and I will use it as a last result. This reader is using the PN532 chip so the code should be compatible. I also found this forum post where the guy who wrote the java library details some of his work. This should help in setting the appropriate messages for the NDEF packets.
Anyway, I wrote this post in order to save people some time searching for a similar solution. I am going to keep going down this path of implementing the protocols in c++ to work on Arduino. This is no small task and should take quite some time to even implement the basics.