File Transfer using beam.py between Android phone and Raspberry Pi?

Asked by Lewis Molyneux

Hi all,

I have been trying to transfer files such as docs, pdfs, jpegs, etc between an Android phone (galaxy s6) and a Raspberry Pi by using a PN532 and the beam.py example. I have come across a few problems problems:

Upon completion of sending the file from the host (phone) , the client device (rpi) will save the file stated in the terminal. When it is opened, it contains the address to the application used to display the file on the other device such as:

muplay.google.com/store/apps/details?id=com.microsoft.office.word&feature=beamTandroid.com:pkgcom.microsoft.office.word

This is what is shown on the terminal for receiving (doesn't look like anything is wrong from my pov):

root@raspberrypi:/home/pi/nfcpy/trunk/examples# sudo ./beam.py
--device ttyAMA0:pn532 recv save test1rc.doc
[nfc.clf] searching for reader on path ttyAMA0:pn532
[nfc.clf] using PN532v1.6 at /dev/ttyAMA0
[nfc.snep.server] snep server bound to port 4 (MIU=1984, RW=15), will
accept up to 1048576 byte NDEF messages
[nfc.dep] running as NFC-DEP Target 424F passive mode MIU=251 RWT=0.077329
[nfc.llcp.llc] LLCP Link established as NFC-DEP Target
Local LLCP Settings
  LLCP Version: 1.1
  Link Timeout: 500 ms
  Max Inf Unit: 2175 octet
  Service List: 0000000000010011
Remote LLCP Settings
  LLCP Version: 1.2
  Link Timeout: 1000 ms
  Max Inf Unit: 2175 octet
  Service List: 0000000000010011
[nfc.llcp.tco] accepting CONNECT from SAP 32
[nfc.snep.server] serving snep client on remote sap 32
[main] default snep server got put request
[main] save ndef message 'urn:nfc:wkt:U'
[nfc.dep] stop NFC-DEP Target 424F passive mode MIU=251 RWT=0.077329,
packets sent/rcvd INF 134/134 ATN 0/0 ACK 0/0 NAK 0/0

I believe this is typical of another phone which doesn't have this application which causes the client to download it before continuing with the transfer. So I believe this is a problem with the AAR (Android Application Record) on androids part as the link shows below:

http://developer.android.com/guide/topics/connectivity/nfc/nfc.html#p2p

So I presume I have to disable this to solve this problem?

A similar thing happens the other way round (rpi sends a file to the phone) where the phone shows a "New tag collected" and the contents being "application/msword". This is the same place where the tutorial opens the beam.py for sending a file to the phone.

From the terminal for sending:

root@raspberrypi:/home/pi/nfcpy/trunk/examples# sudo ./beam.py
--device ttyAMA0:pn532 send file Test1.doc
[nfc.clf] searching for reader on path ttyAMA0:pn532
[nfc.clf] using PN532v1.6 at /dev/ttyAMA0
[nfc.snep.server] snep server bound to port 4 (MIU=1984, RW=15), will
accept up to 1048576 byte NDEF messages
[nfc.dep] running as NFC-DEP Target 424F active mode MIU=251 RWT=0.077329
[nfc.llcp.llc] LLCP Link established as NFC-DEP Target
Local LLCP Settings
  LLCP Version: 1.1
  Link Timeout: 500 ms
  Max Inf Unit: 2175 octet
  Service List: 0000000000010011
Remote LLCP Settings
  LLCP Version: 1.1
  Link Timeout: 1000 ms
  Max Inf Unit: 2175 octet
  Service List: 0000000000010011
[nfc.llcp.llc] BrokenLinkError('Error 0x29: Released by Initiator
while operating as Target',)
[nfc.dep] stop NFC-DEP Target 424F active mode MIU=251 RWT=0.077329,
packets sent/rcvd INF 160/128 ATN 0/0 ACK 0/33 NAK 0/0

Broken link error caused by the me removing the phone since it wont
progress any further.

In some cases the phone won't send a file (even 5kb in size) to the raspberry pi stating that the receiver isn't capable of receiving large files via beam.

If anyone can help or point me in a certain direction it will be greatly appreciated. Note that I may need some things dumbed down because I'm not the most capable person with these things.

Thanks,

Lewis

Question information

Language:
English Edit question
Status:
Answered
For:
nfcpy Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
Stephen Tiedemann (stephen-tiedemann) said :
#1

Android Beam does different things depending on whether or not the foreground application has configured Beam to send content. If an app hasn't configured Beam then Android will send a link to the play store and an application record. With "beam.py recv print" and WhatsApp beamed from the phone you'll see:

record 1
  type = 'urn:nfc:wkt:U'
  name = ''
  data = '\x03play.google.com/store/apps/details?id=com.whatsapp&feature=beam'
record 2
  type = 'urn:nfc:ext:android.com:pkg'
  name = ''
  data = 'com.whatsapp'

The Youtube app configures Android Beam to send a link for the currently played (or paused) Youtube video (if the Youtube app is fresh started it'll just not send anything). With beam.py you would receive something like this:

record 1
  type = 'https://www.youtube.com/watch?v=q7U1by0y8qE#t=1'
  name = ''
  data = ''

If you look at an image in Google Photo or the stock Gallery app the configuration done by those apps instructs the Beam app to send the image with NFC connection handover and Bluetooth. Sending the image through NFC would take a lot of time because in best case NFC will send at about 25 kByte/second. And again, if you display an image within WhatsApp it'll be sending again just the PlayStore link and AAR for WhatsApp (because Beam not configured).

The nfcpy beam example works a bit different in that it sends only via NFC, also if you do "beam.py send file <FILE>". If you try with an image file of ~100KB you'll see it pop up and displayed in the "New tag collected" screen after a couple of seconds (add the "--timeit" flag after "send" to get the transfer speed, my Nexus 5 needs about 10 sec and an Xperia Z2 completes in 5).

You msword file can't be rendered by the "New tag collected" app, you're seeing only the MIME type "application/msword" which beam.py guessed from the file content and transmitted as NDEF record type along with the actual data. In cases where beam.py appears to be not progressing it's just due the the file size. If you divide the file size by the transfer speed measured above you'd an idea of the seconds (or minutes) it'll take to finish. And even if you wait to the end, the "New tag collected" app provides nothing to store the content - it's just rendered for once. You'd probably need to write your own app to receive and store.

Revision history for this message
Lewis Molyneux (lewisjmnx) said :
#2

Hi Stephen,

Thank you for your response, it has given me a good insight into the existing problem.

I have looked into existing applications in the attempt to save some time and haven't been very successful, except for the NFC readers such as NFC tools by wakdev and NFC reader by Adam Nyback ( which is available on github: https://github.com/nadam/nfc-reader). These are able to show the the file being received from the Pi such as the file type, the text font in the file, the content of the file, etc. I would post it here but it's not exactly the same as what was produced on my phone and is very long and messy. This is also not the only part of what I have received, I presume the other parts are the AAR, etc?

Finally, I would like to ask if you know of any existing applications that could help or any recommendations on where to start with such an application such as resources etc?

Many thanks,

Lewis

Revision history for this message
Stephen Tiedemann (stephen-tiedemann) said :
#3

The NFC reader by Adam Nyback should be a great starting point. It just happens to print the data content in raw, so you'd have to add your own handling. With nfcpy "beam.py send file <FILE>" you'd receive an NDEF message with a single record, the record type name is set to the MIME type of <FILE>, the record identifier is the <FILE> name and the record data is the <FILE> content.

Can you help with this problem?

Provide an answer of your own, or ask Lewis Molyneux for more information if necessary.

To post a message you must log in.