NFC vCard

Posted on
  • I've implemented a PoC for NFC vCard support.

    My implementation consists of two modules. A NFC card emulation NFCTag.js and a NDEF vCard wrapper NFCvCard.js.

    NFCTag: Features READ and WRITE support.
    NFCvCard: Its a pretty crude application example for NFCTag that can be altered to support various MIME-Type based NDEF tag types.

    I've tested my vCard example below using­er-for-iphone/id1249686798?mt=8

    var tag = require("NFCvCard").create("BEGIN:VCARD\­n"+
                                         "FN:John Doe\n"+
                                         "TEL;WORK;VOICE:(111) 555-1212\n"+

    2 Attachments

  • That's awesome - thanks!

    You know there's NRF.nfcRaw? It feels like that should really be doing what NFCTag is (minus the writing, obviously). Is the issue that it already applies a header already?

    If so, I wonder how many people actually use nfcRaw - probably none. I should probably change it so that it doesn't apply any header - and then stuff like your vCard implementation could use that (which wouldn't struggle with the potential delays in response if the JS interpreter was busy)

  • Yes NRF.nfcRaw does also work (see attachment). However the purpose of this one hour project was to demo my low level NFC API, which was recently merged, and test my iPhones NFC feature..

    1 Attachment

  • Aha, that makes more sense - thanks! Are you interested in getting those modules listed on the Espruino site?

    Wow, so vCard NFC actually works on iPhones? I assumed they were only used for Apple Pay.

  • Yes, iPhone 7, 8, X with iOS11 (released in September 2017) feature a NFC reader API for NDEF records. (No write support and no arbitrary tag type support, just NDEF read.)

    I'd like to have NFCTag.js listed. Should I open a pull request?
    Since NFCTag.js implements write support, it opens up additional possibilities. In theory you could download code to a Puck using NFC...

    I've come up with an additional example:

    var data = new Uint8Array(16+768);
    data.set("\xE1\x11\x60\x00", 0x0C);
    var tag = require("NFCTag").create(data);

    This code creates an empty tag with 768 bytes of writable storage.

    The data can be initialized with an Android App, i.e.­ls?id=com.nxp.nfc.tagwriter

  • That's great! So the NFC URL is possible with an app on iOS, even it's not enabled in the OS yet.

    It'd be helpful if you could open a PR for the vCard and actual tag - I'm not sure if you've done it before, but just stick stuff in EspruinoDocs/modules (as it's not actual hardware) with a markdown file with an example or two of how to use it. Otherwise I could do that based on this thread?

    I think the native vCard might be more useful as a module, but the NFCTag library itself is amazingly useful on its own, and the vCard implementation for it would probably be good in the docs, to compare to what happens for nfcRaw.

    It's quite exciting that something like:

    var data = new Uint8Array(16+768);
    data.set("\xE1\x11\x60\x00", 0x0C);
    var tag = require("NFCTag").create(data);
    setWatch(function() {
      eval(E.toString(new Uint8Array(data.buffer,16)));
    }, BTN, {edge:"rising",repeat:true,debounce:20})­;

    should mean you can write JS code via NFC then press the button to execute it :)

  • I'll open a pull request for NFCTag.js on the weekend.

    About downloading arbitrary data using NFC:
    It's generic and works for text, images, js... for this reason the data is wrapped in a NDEF MIME Record. Andoird features an API for wrap und unwrap.

    Wrap and unwrap is missing from Pucks JS-Engine, namely:

    • Parse and skip NDEF Message Header. (Usually 2 or 4 bytes)
    • Parse and skip NDEF MIME-Record Header. (Here length greatly depends on the payload type string e.g. "text/javascript" is already 15 bytes on it's own.)

    If there is interest I would invest some time into a MIME record wrap unwrap module.

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview

NFC vCard

Posted by Avatar for AntiCat @AntiCat