NFC P2P - JAVA / ANDROID project

2,230 views
Skip to first unread message

Zakaria Chentouf

unread,
May 20, 2012, 1:38:00 PM5/20/12
to nfc-dev...@googlegroups.com
Hi everyone  ,

First , thank you very much for sharing your work .

Right now , i am making an NFC project , one part in Java( the server) - one part in Android application (the client).
For that project , I have  a Nexus S / Galaxy Nexus (both with Ice Cream Sandwich)  and an ACR122U-A2  .

 It's simple , my objective is to transform my Nexus One to "Ticket book" . I explain :

A customer come to a swimming pool , he just have to  pass his phone in  the front of the reader and the gate open to let him go inside.
 

It's work like that :

(1)Nexus is one ACR122  -> /(2) ACR122 read and send to Java application information /(3) Java application  processes the information /(4) ask ACR122 to answer / ->  (5)ACR122 send data to the Nexus S -> (6)/Android application pocess 

With the work of  Adrian  and Liu , i can send uri and other things to my phone continuously (part 4 /5) . But i real don't know wich part of the code can help me to build  the "receive" part .


Thank you verry much

Chentouf Zakaria

Adrian Stabiszewski

unread,
May 21, 2012, 11:13:38 AM5/21/12
to nfc-dev...@googlegroups.com
Hi Chentouf Zakaria,

this sounds like an interesting project. Hope your Nexus doesn't get wet ;)

Have you tried to use my Demo Applet to send NDEF messages from your phone?
http://www.grundid.de/nfc/

Regards,
Adrian.

Zakaria Chentouf

unread,
May 24, 2012, 5:31:32 PM5/24/12
to nfc-dev...@googlegroups.com
Hello, 


I did better , I am able to send any type of NDEF message to my nexus and i can receive text/plain message for now. 
Thanks to the brand new  LlcpDemo who help me a lot.

Right now, i am doing an Android application test to see if everything work well with NFCTools.(technology Test) then i will attack my own project.

I think for this first project , i just send NDEF Message "Text/plain" type to do manage the deal. When i finish the 2 test , i will upload it here.


Thanks for your work Adrian

Zakaria

Zakaria Chentouf

unread,
May 26, 2012, 9:19:09 AM5/26/12
to nfc-dev...@googlegroups.com
Hello every on,

I have to do somethings new for my project ,  I Need to separate the LlcpDemon in two class : LlcpSend and LlcpReceive  and one thread who check if they do what they have to do .So my thread work like that

Run the thread
-> create and launch LlcpSend 
 -> Check the status and wait until the message is send
 -> Message send ->Kill LlcpSend  // Part 1
-> create and launch LlcpReceive
 -> Check the status and wait until the message is receive
 -> Message  receive ->Program is done Part 2

Everything work well but , when i finish the part 2 , i have a null pointer exception.... I really don't know why.
Maybe some one can give me another point of view
I put the 3 class

Thanks to everyone.
ManagerOfThread.java
LlcpReceive.java
LlcpSend.java

Zakaria Chentouf

unread,
May 26, 2012, 10:16:30 AM5/26/12
to nfc-dev...@googlegroups.com
In fact , that's don't work always , I get an error.

Someone knows how to stop the LlcpService properly? 

I think that's my big problems because they still ruining and i try to launch another service on...

Thank you 

Zakaria

Adrian Stabiszewski

unread,
May 26, 2012, 11:52:29 AM5/26/12
to nfc-dev...@googlegroups.com
Hi!

I think this is not going to work. You cannot start two threads that share one NFC reader.

I'm currently trying to establish a P2P connection to Android based on the IsoDep class. This would allow for a bidirectional communication. However it is not working yet.

With Android Beam and the LLCPServer demo you won't be able to do that.

Regards,
Adrian.

Zakaria Chentouf

unread,
May 26, 2012, 7:04:55 PM5/26/12
to nfc-dev...@googlegroups.com
Hello , 


That's the point , i thought it's not possible to use two thread  in same time ,that's why i use that way :
I want is to launch the first thread (LlcpSend) , he will get access to the terminal to write.
Then , i kill everything (normally , the NFC reader will be available because the LlcpSend will be destroyed)  and launch the second thread (LlcpReceive).

I know  it's possible (maybe not by this way) because you do it here (http://www.grundid.de/nfc/). You can send and receive . I don't want P2P connection  but i want to be able to send then to receive ( 10s between)-

Thank you for your help
Zakaria

Adrian Stabiszewski

unread,
May 27, 2012, 4:06:36 AM5/27/12
to nfc-dev...@googlegroups.com
Ok, but I don't understand why you want to split LlcpService into two classes. The applet demo what you see in the browser is exactly the same as LlcpService.

Are you able to send and receive data during the same session using the applet or do you have to remove the phone from the reader and then touch again?
Message has been deleted

Zakaria Chentouf

unread,
May 29, 2012, 3:39:49 AM5/29/12
to nfc-dev...@googlegroups.com
Hi everyone , 

I correct my project and everything works well know. I let this test project for others people. 
Hope it will be helpful for you 

First -> Java Part
This litle application allow you to send message to your Nexus. Then she wait for confirmation but if you don't confirm in the 60s , another  Thread restart the application.
Second part -> Android application
This one just show you the message you receive fron your reader , then allow you to confirm the transaction. 

 
TestProject.zip

Pan Shaw

unread,
Jul 30, 2012, 6:04:11 AM7/30/12
to nfc-dev...@googlegroups.com
Hi,Zakaria,
    I'm new to NFC.I download your test project today,I have a Nexus S and a ACR122 NFC reader,so ,I execute the java part on PC,and press the "send it"button,then I open the android application on Nexus S and put the phone on the ACR122 reader,android beam is triggered,but the communication seems not successful,the java part stay showing waiting...sometimes android application doesn't show the text received.Do I need something else to do? or whether I make some mistakes in operating?
   hope your answers.

   PS:I use eclipse to run the java part,the console column show:Error sending message [D440010520060F636F6D2E616E64726F69642E6E7070] (0,22) => [SW1: 99, SW2:0, Data: ] 

Zakaria Chentouf

unread,
Jul 30, 2012, 8:25:48 AM7/30/12
to nfc-dev...@googlegroups.com
Hi Pan,  

Can you tell me more about device you use (Firmware version) and did you try to launch the debug to see in which line the message is generated?


Thank you


2012/7/30 Pan Shaw <xiaop...@gmail.com>

Pan Shaw

unread,
Aug 1, 2012, 8:30:42 AM8/1/12
to nfc-dev...@googlegroups.com
Hi, Zakaria,
    I am so sorry late reply to you, the firmware version of the NFC reader device is ACR122U210, and the android system is 4.0.4.
    Today I test the program again, I use eclipse to run it, then I put the phone on NFC reader, the debug information  shows that the communication is OK, the phone and receive the message, but it seems that the phone does not give a response signal to the NFC reader, so the java program stay showing waiting ...
    I do it again, I first run the Java program, push the send button, I put the Android phone on it, it receive the message, then put the phone away, after the NFC reader switch to the red light, I put the phone on it again, android beam is triggered, I touch the screen, and the Java Ndefpush successful program receive the signal, pop-up a success message.it seems okay, but when I watch the console, some error message (Error sending message [ D440010000] (0,5) = SW1 [>: 99, SW2: 0, Data:]) output connection between twice (I think maybe the reason is that i put the phone away before it switch to red light), another problem. is that the timer did not stop after the java program pop up the successful message, when the number turns to 0, it pop up the time out message.
    I am not sure that this operation is right or I make some mistake wrong.did again?
    Thanks for your reply.

On Monday, 30 July 2012 20:25:48 UTC +8 Zakaria wrote Chentouf:
Hi Pan,   Can you tell me more about you-use device (firmware version) and did you try to launch the debug to see line # in which the message is generated? Thank you







30/07/2012 Pan Shaw < xiaop...@gmail.com >
Hi, Zakaria,
    I'm new to NFC.I download your test project today, I have a Nexus S ACR122 NFC reader and a, well, I execute the java part on PC, and press the "send it" button, then I open the android application on Nexus S and put the phone on the ACR122 reader, android beam is triggered, but the communication seems not successful, the java part stay waiting ... sometimes showing android application does not show the text received.Do I need something else to do? Whether or I make some mistakes in operating?
   hope your answers.

   PS: I use eclipse to run the java part, the console show column: Error sending message [ D440010520060F636F6D2E616E6472 6F69642E6E7070] (0.22) = [SW1: 99, SW2: 0, Data:]>  On Tuesday, 29 May 2012 15:39:49 UTC +8 Zakaria wrote Chentouf:

Hi everyone, 

I correct my project and everything works well know. I let this test project for others people. 
Hope it will be helpful for you 

First -> Java Part
litle This application allow you to send your message to Nexus. Then she wait for confirmation but if you do not confirm in the 60s, another thread restart the application.
Second part -> Android application
This one just show you the message you receive fron your reader, then allow you to confirm the transaction. 

 

Richard Bailey

unread,
Sep 5, 2012, 3:56:45 AM9/5/12
to nfc-dev...@googlegroups.com
Hi Zakaria,

First of all, I would like to thank you, for the demo project. 

Some background information:
  • Android phone: GT-I9300 (version 4.0.4)
  • Reader: ACR122U-A2 (driver version 1.1.6.3)
  • Windows 7 64
I ran the LlcpService demo and received the following output:

INFO : org.nfctools.examples.llcp.LlcpService - Connected to ACS ACR122 0
INFO : org.nfctools.spi.acs.AcsTerminal - Waiting...
DEBUG: org.nfctools.spi.acs.ApduReaderWriter - command  APDU => FF0000002DD48C0008001234564001FE0100000000000000000000000000FFFF01FE01000000000000000646666D01011000
DEBUG: org.nfctools.spi.acs.ApduReaderWriter - response APDU <= 
org.nfctools.spi.acs.ApduException: Error sending message [D48C0008001234564001FE0100000000000000000000000000FFFF01FE01000000000000000646666D01011000] (0,45) => []
at org.nfctools.spi.acs.ApduReaderWriter.write(ApduReaderWriter.java:111)
at org.nfctools.spi.tama.AbstractTamaCommunicator.sendMessageInternal(AbstractTamaCommunicator.java:64)
at org.nfctools.spi.tama.AbstractTamaCommunicator.sendMessage(AbstractTamaCommunicator.java:53)
at org.nfctools.spi.tama.nfcip.TamaNfcIpCommunicator.connectAsTarget(TamaNfcIpCommunicator.java:109)
at org.nfctools.spi.acs.AcsTerminal.connectAsTarget(AcsTerminal.java:210)
at org.nfctools.spi.acs.AcsTerminal.initTargetDep(AcsTerminal.java:182)
at org.nfctools.examples.llcp.LlcpService.run(LlcpService.java:90)
at org.nfctools.examples.llcp.LlcpService.main(LlcpService.java:148)

Did you come across this error? If so, what am I doing wrong? 

When I run the NdefPushView demo, I receive the following output:

Mode: TARGET
Waiting for P2P, press ENTER to exit

DEBUG: org.nfctools.spi.acs.AcsDirectChannelTag - command: FF0000002DD48C0008001234564001FE0100000000000000000000000000FFFF01FE01000000000000000646666D01011000
DEBUG: org.nfctools.spi.acs.AcsDirectChannelTag - response: 6300
org.nfctools.spi.acs.ApduException: Error sending message [D48C0008001234564001FE0100000000000000000000000000FFFF01FE01000000000000000646666D01011000] (0,45) => [SW1: 99, SW2:0, Data: ]
at org.nfctools.spi.acs.ApduTagReaderWriter.write(ApduTagReaderWriter.java:43)
at org.nfctools.spi.tama.AbstractTamaCommunicator.sendMessageInternal(AbstractTamaCommunicator.java:64)
at org.nfctools.spi.tama.AbstractTamaCommunicator.sendMessage(AbstractTamaCommunicator.java:53)
at org.nfctools.spi.tama.nfcip.TamaNfcIpCommunicator.connectAsTarget(TamaNfcIpCommunicator.java:109)
at org.nfctools.spi.acs.TargetTerminalTagScanner.run(TargetTerminalTagScanner.java:39)
at java.lang.Thread.run(Unknown Source)

As mentioned to Adrian, my task (which I though would be pretty simple - guess I was wrong) is to send some or other unique code / text / whatever to an application running on a PC. The reason for this, is to identify the phone - which is linked to a person / account.

Could you please point me in the right direction?

Many thanks in advance!
Kind regards,

Richard

Adrian Stabiszewski

unread,
Sep 9, 2012, 12:25:01 PM9/9/12
to nfc-dev...@googlegroups.com
Hi Richard,

don't worry about the exceptions. The software will recover from them. Just try again.

You might want to download the new nfctools-examples.jar from github.
https://github.com/grundid/nfctools-examples/downloads
I have made some corrections so that the SnepDemo now also works with Android 4.1. I don't know why but at the moment it only works in target mode:

java -cp nfctools-examples.jar org.nfctools.examples.snep.SnepDemo -target -url http://www.google.com

The expected output is something like this:

Using: ACS ACR122 0

Mode: TARGET
Waiting for P2P, press ENTER to exit

DEBUG: org.nfctools.spi.acs.AcsDirectChannelTag - command: FF0000002DD48C0008001234564001FE0100000000000000000000000000FFFF01FE01000000000000000646666D01011000
DEBUG: org.nfctools.spi.acs.AcsDirectChannelTag - response: D58D251ED400BC0E7FE0B9C84D6581710000003246666D010111030200130401969000
DEBUG: org.nfctools.spi.acs.AcsDirectChannelTag - command: FF00000002D486
DEBUG: org.nfctools.spi.acs.AcsDirectChannelTag - response: D5870000009000
DEBUG: org.nfctools.snep.SnepClient - Connecting to urn:nfc:sn:snep
DEBUG: org.nfctools.spi.acs.AcsDirectChannelTag - command: FF00000015D48E0520060F75726E3A6E66633A736E3A736E6570
DEBUG: org.nfctools.spi.acs.AcsDirectChannelTag - response: D58F009000
DEBUG: org.nfctools.spi.acs.AcsDirectChannelTag - command: FF00000002D486
DEBUG: org.nfctools.spi.acs.AcsDirectChannelTag - response: D5870000009000
DEBUG: org.nfctools.spi.acs.AcsDirectChannelTag - command: FF00000004D48E0000
DEBUG: org.nfctools.spi.acs.AcsDirectChannelTag - response: D58F009000
DEBUG: org.nfctools.spi.acs.AcsDirectChannelTag - command: FF00000002D486
DEBUG: org.nfctools.spi.acs.AcsDirectChannelTag - response: D587008184020200789000
INFO : org.nfctools.llcp.LlcpConnectionManager - connect complete, remote: 4 lA: 32
DEBUG: org.nfctools.snep.SnepClient - Connection succeeded
INFO : org.nfctools.examples.snep.SnepAgentListenterImpl - SNEP connection available, sending message...
DEBUG: org.nfctools.spi.acs.AcsDirectChannelTag - command: FF0000001AD48E13200010020000000FD1010B5501676F6F676C652E636F6D
DEBUG: org.nfctools.spi.acs.AcsDirectChannelTag - response: D58F009000
DEBUG: org.nfctools.spi.acs.AcsDirectChannelTag - command: FF00000002D486
DEBUG: org.nfctools.spi.acs.AcsDirectChannelTag - response: D587008344019000
DEBUG: org.nfctools.spi.acs.AcsDirectChannelTag - command: FF00000004D48E0000
DEBUG: org.nfctools.spi.acs.AcsDirectChannelTag - response: D58F009000
DEBUG: org.nfctools.spi.acs.AcsDirectChannelTag - command: FF00000002D486
DEBUG: org.nfctools.spi.acs.AcsDirectChannelTag - response: D5870000009000
DEBUG: org.nfctools.snep.SnepClient - No data to send, disconnecting...
DEBUG: org.nfctools.spi.acs.AcsDirectChannelTag - command: FF00000004D48E1160
DEBUG: org.nfctools.spi.acs.AcsDirectChannelTag - response: D58F009000
DEBUG: org.nfctools.spi.acs.AcsDirectChannelTag - command: FF00000002D486
DEBUG: org.nfctools.spi.acs.AcsDirectChannelTag - response: D5870081C4009000
INFO : org.nfctools.llcp.LlcpConnectionManager - Closing open connection
DEBUG: org.nfctools.snep.SnepClient - Disconnect succeeded
DEBUG: org.nfctools.spi.acs.AcsDirectChannelTag - command: FF00000004D48E0000
DEBUG: org.nfctools.spi.acs.AcsDirectChannelTag - response: D58F009000

Regards,
Adrian.


tangx...@gmail.com

unread,
Apr 8, 2013, 8:42:17 AM4/8/13
to nfc-dev...@googlegroups.com
hi, i'm now deal with a project which involved the NFC communication between Android Phone and NFC reader. The Android Phone is Sony m27i while NFC reader is ACR122U-A1NOCT1. I want to transmit a message from my Android Phone to NFC reader . And I have tested your Demo Applet ,but when my phone close to the NFC reader and send NDEF message ,there is no reflect ,in other word, your Demo Applet doesn't receive anything . Why did this happen? please help me .Thanks

在 2012年5月21日星期一UTC+8下午11时13分38秒,Adrian Stabiszewski写道:

tangx...@gmail.com

unread,
Apr 8, 2013, 8:44:26 AM4/8/13
to nfc-dev...@googlegroups.com


在 2012年5月21日星期一UTC+8上午1时38分00秒,Zakaria Chentouf写道:

Md Asif

unread,
May 22, 2014, 2:42:33 AM5/22/14
to nfc-dev...@googlegroups.com
Hi there I tried your coding and when i run want to send message to my Android phone i receive this in the console section
Nfc.jpg

Zakaria Chentouf

unread,
May 22, 2014, 5:45:05 AM5/22/14
to nfc-dev...@googlegroups.com
Hi,

It's completely normal, means the system is waiting for a device.


--
Sie erhalten diese Nachricht, weil Sie in Google Groups ein Thema der Gruppe "nfc-developers" abonniert haben.
Wenn Sie sich von diesem Thema abmelden möchten, rufen Sie https://groups.google.com/d/topic/nfc-developers/BB_xCCGeFRU/unsubscribe auf.
Wenn Sie sich von dieser Gruppe und allen Themen dieser Gruppe abmelden möchten, senden Sie eine E-Mail an nfc-developer...@googlegroups.com.
Weitere Optionen finden Sie unter https://groups.google.com/d/optout.

Message has been deleted

Sagar More

unread,
Jan 16, 2016, 5:30:41 AM1/16/16
to nfc-developers
Can anyone send me code that sends a url to mobile through ACR122U
Reply all
Reply to author
Forward
0 new messages