NFC vCard

Posted on
Page
of 2
/ 2
Next
  • 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 https://itunes.apple.com/us/app/nfc-read­er-for-iphone/id1249686798?mt=8

    var tag = require("NFCvCard").create("BEGIN:VCARD\­n"+
                                         "VERSION:2.1\n"+
                                         "N:Doe;John;;Mr.\n"+
                                         "FN:John Doe\n"+
                                         "TEL;WORK;VOICE:(111) 555-1212\n"+
                                         "EMAIL:jondoe@example.com\n"+
                                         "END:VCARD\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.
    https://play.google.com/store/apps/detai­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.

  • Is there an example of using this posted anywhere?

  • Can you be a little more specific?

    The documentation for the NFCTag module is available here:
    https://www.espruino.com/NFCTag

    I've tested the library with iOS13 (now also featuring write!!!) using a recently released App (not by me): https://apps.apple.com/ch/app/nfc-tools/­id1252962749

    iOS is a little more picky than Android so tuning some static data is required:

    var data = new Uint8Array(16+872);
    data.set("\x00\x00\xE1\x10\x6D\x00\x03\x­00\xFE\x00", 0x0A);
    var tag = require("NFCTag").create(data);
    
  • Hi @AntiCat, thank you for your response.

    I'd like to specifically use code like what you posted in #1 above, with the NFC vCard in more human readable format. I attempted to simply change the "NFCvCard" to "NFCTag", but hit the following error:

    ____                 _
    |  __|___ ___ ___ _ _|_|___ ___
    |  __|_ -| . |  _| | | |   | . |
    |____|___|  _|_| |___|_|_|_|___|
             |_| espruino.com
     2v04 (c) 2019 G.Williams
    >Uncaught Error: Function "set" not found!
     at line 1 col 77
    ...=NRF.nfcStart();this._data.set(a,0)
                                  ^
    in function "setData" called from line 1 col 15
    this.setData(a);var b=this;NRF.on("NFCrx",function(a){a&&b._­...
                  ^
    in function "c" called from line 1 col 8
    new c(a)
           ^
    in function "create" called from line 70 col 51
                                         "END:VCARD\n");
                                                      ^
    

    If what I'm trying to do isn't possible - please let me know.

  • Mon 2019.10.21

    'I attempted to simply change the "NFCvCard" to "NFCTag" '
    'If what I'm trying to do isn't possible'

    Answers to the request would depend on where the substitution was made.

    Within the 'require' statement in post #9 example at:

    https://www.espruino.com/NFCTag

    or a substitution within the class declaration in code file 'NFCvCard.js' from post #1 ?

    Without that detail, would have to be a pure guess.

    Please post your code so others can easily grasp a snapshot of the coding attempt direction.

  • Hi @Robin, in order to get this working "as-is", I ended up having to use the NFCvCard.js as a local module per post #1 above.

    I'm still unable to do any reading, but the code is the same as well:

    var tag = require("NFCvCard").create("BEGIN:VCARD\­n"+
                                         "VERSION:2.1\n"+
                                         "N:Doe;John;;Mr.\n"+
                                         "FN:John Doe\n"+
                                         "TEL;WORK;VOICE:(111) 555-1212\n"+
                                         "EMAIL:jondoe@example.com\n"+
                                         "END:VCARD\n");
    

    Also using the same NFC Reader app as post #1.

  • ' in order to get this working "as-is" '

    So, I presume the original code module from post #1 is working then?

    ' I attempted to simply change the "NFCvCard" to "NFCTag" '

    Is the module 'NFCTag.js' also used locally, and physically there as implied in post #12 ?
    Is L1 of post #12 where the text within 'require' is changed to 'NFCTag'?

    If so, is the suggestion that the errors as shown in post #10 do occur, by only inserting the single statement as shown in post #12 verbatim, and no other statements acting on var 'tag'? (e.g. other code currently in memory  or  not all the code is posted)



    I also note from the heading 'Example' using link from post #9

    https://www.espruino.com/NFCTag

    that the first six bytes must use six initializer bytes as described in the table shown there. The 'human readable' form as indicated in post #10 doesn't appear to follow that example.

    'with the NFC vCard in more human readable format'



    EDIT:
    I see in file 'NFCvCard.js' function 'publish()' that line(s) ex: this._record.set(data, C.HEADER.length); creates a payload based on the data passed and the header constant 'C' so those initialization bytes are included there.

  • @Robin - let me clarify, as of post #12 no error is reported on the Send to Espruino, however nothing appears on the NFC reader either. After clicking send in the WebIDE, the following is reported:

    Found PUCKJS, 2v04
    Connected to Web Bluetooth, Puck.js xxxx
    No errors in NFCvCard. Minified 2877 bytes to 634 bytes.
    

    So, I presume the original code module from post #1 is working then?

    ...not that I can confirm using the same NFC Reader app as post #1.

    Is the module 'NFCTag.js' also used locally, and physically there as implied in post #12 ?

    No. However internally NFCvCard has the require("NFCTag").create(); inside, which per the module documentation should load.

    To replicate what I am doing in its entirety, download the NFCvCard.js locally to your modules folder, paste the following code in your editor, and upload.

    var tag = require("NFCvCard").create("BEGIN:VCARD\­n"+
                                         "VERSION:2.1\n"+
                                         "N:Doe;John;;Mr.\n"+
                                         "FN:John Doe\n"+
                                         "TEL;WORK;VOICE:(111) 555-1212\n"+
                                         "EMAIL:jondoe@example.com\n"+
                                         "END:VCARD\n");
    

    Once the upload completes, attempt to verify the values with the NFC reader.

  • 'has the require("NFCTag").create(); inside, which per the module documentation should load'

    The 'NFCTag.js' file is viewable from within a browser, so agreed - should load.

    https://www.espruino.com/modules/NFCTag.­js

    Does entering dump(); in the WebIDE Left-Hand console panel, display the same functions as in above file? (e.g. was the file actually fetched and parsed?)



    Still puzzled on this sentence as I'm not seeing the substitution part in the responses.

    ' I attempted to simply change the "NFCvCard" to "NFCTag" '

    Could this now be bad information perhaps?

  • I never submitted a PR for NFCvCard.js since it didn't felt polished enough (especially since the vcard hat to be < 220 bytes). So the detour of downloading and copying to module directory is necessary. I've just double-checked. Using the https://www.espruino.com/modules/NFCTag.­js and the NFCvCard.js from above still works for me...

    That sed I rarely have issues when the BLE connection is also open. What might also break the system is creating multiple instances of NFCTag by calling require("NFCvCard") multiple times without a reset (note an upload performs a reset, so that should be fine in your case).

    My RAW data ends up to be:

    tag._record = new Uint8Array([95, 112, 172, 11, 153, 120, 250, 81, 74, 3, 255, 255, 225, 17, 124, 15, 3, 135, 194, 12, 0, 0, 0, 117, 116, 101, 120, 116, 47, 120, 45, 118, 67, 97, 114, 100, 66, 69, 71, 73, 78, 58, 86, 67, 65, 82, 68, 10, 86, 69, 82, 83, 73, 79, 78, 58, 50, 46, 49, 10, 78, 58, 68, 111, 101, 59, 74, 111, 104, 110, 59, 59, 77, 114, 46, 10, 70, 78, 58, 74, 111, 104, 110, 32, 68, 111, 101, 10, 84, 69, 76, 59, 87, 79, 82, 75, 59, 86, 79, 73, 67, 69, 58, 40, 49, 49, 49, 41, 32, 53, 53, 53, 45, 49, 50, 49, 50, 10, 69, 77, 65, 73, 76, 58, 106, 111, 110, 100, 111, 101, 64, 101, 120, 97, 109, 112, 108, 101, 46, 99, 111, 109, 10, 69, 78, 68, 58, 86, 67, 65, 82, 68, 10, 254]);
    

    Except the first 10 bytes (unique device id) this data should be identical on your Puck.JS.


    1 Attachment

  • Tue 2019.10.22

    Thanks @AntiCat for the verification.

    For @Tesseract-Developer and myself, what version of Espruino is flashed on your device? As the closing post (then) is over twenty months old, could it be that the device you have is still at an older version?

  • Software is 2.04, the Hardware im using is a Puck from the Kickstarter campaign so 1.0e.

    Edit: Could Minify make a difference? It is off on my system. I not at home so I can’t test other options right now.

  • I'm not seeing minification having any real effect on my outcome unfortunately. My software is 2.04 and hardware 1.0e as well.

  • Sat 2019.10.26

    Put another hour into this as I wanted to humor myself with a similar error just trying to load the code. Minification is off. Running on Win10. Code file NFCvCard.js running in local modules folder.

    in function "c" called from line 1 col 8
    new c(a)
           ^
    in function "create" called from line 1 col 39
    this._driver=require('NFCTag').create(),­this.publish(a);
                                          ^
    in function "NFCvCard" called from line 1 col 15
    new NFCvCard(a);
                  ^
    in function "create" called from line 17 col 42
    var tag = require("NFCvCard").create(data);
    

     

    and dump() results

    >dump()
    
    var data = new Uint8Array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 225, 16, 96, 0, 3, 0, 254, 0, 0,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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]);
    var tag = undefined;
    =undefined
    >
    

     

    Results (pared) of WebIDE >> Settings >> Console

    Device found {}
    [success] Connected to ee:21:bf:d1:53:89
    >>> Connected to ee:21:bf:d1:53:89
     - NFCvCard requires ["NFCTag"]
       Queueing NFCTag
    [notify_info] No errors in NFCvCard. Minified 2421 bytes to 651 bytes.
    loadModule(NFCTag)
     - NFCTag requires []
    Found a prompt... great!
    >>> Sending...
    



    @Tesseract-Developer would you please post the result of process.env and process.memory() along with dump and pertinent detail from the console output please.

    What OS is the WebIDE running on?

  • 
    >process.env
    ={
      VERSION: "2v04",
      GIT_COMMIT: "3956264e",
      BOARD: "PUCKJS",
      FLASH: 524288, RAM: 65536,
      SERIAL: "34a36385-8ce8164e",
      CONSOLE: "Bluetooth",
      MODULES: "Flash,Storage,hea" ... "S,crypto,neopixel",
      EXPTR: 536882364 }
    >process.memory()
    ={ free: 1977, usage: 273, total: 2250, history: 170,
      gc: 0, gctime: 3.63159179687, "stackEndAddress": 536924008, flash_start: 0, "flash_binary_end": 419924,
      "flash_code_start": 442368, flash_length: 524288 }
    >
    

    What OS is the WebIDE running on?

    WebIDE is running on OSX 10.14.6

  • Mon 2019.10.28

    Thank you @Tesseract-Developer for posting. Nothing stands out as an obvious cause and pains me, as I thought I had identified what was going on. To prove this, I attempted to update to 2v04 but that (my flash attempt) didn't go as expected.

    Now I'm without a BLE device to further assist short term. I can continue to provide some debugging steps as we still need a bit more information. Others may be holding off too, as they also are unable to provide assistance without the info I've previously requested.


    fr #15 'Does entering dump(); in the WebIDE Left-Hand console panel, display the same functions as in above file? (e.g. was the file actually fetched and parsed?)'

    In #15 I inquired about the results dump() so that we could decide whether the WebIDE is configured correctly. Please post.

    Would you also comment on this line from #15 (#10) also:

    ' I attempted to simply change the "NFCvCard" to "NFCTag" '
    'Could this now be bad information perhaps?'



    I am purposely holding off on my testing results until I have that needed detail. Under some conditions, I was able to get near identical error messages, with the results of #21 and me now not being able to test with the newly flashed version, leave me with a bit of doubt. Still some debugging steps we should take.

  • I am purposely holding off on my testing results until I have that needed detail

    I think perhaps you are fixating on that point. As I said in #14, really it comes down to not being able to see or read any of the values that the replication steps listed are supposed to produce.

  • Tue 2019.10.29

    'really it comes down to not being able to see or read any of the values'

    Yes, exactly @Tesseract-Developer. Several of us have been able to load the modules which do not produce the errors claimed. One setup I tried did produced something similar. From the exhaustive work by @AntiCat furnish a solution which provided instructions, the code source, a sample data dump and a demonstration video to boot.

    Many of us provide our time freely to assist fledgling end users gratis, thereby boosting the community knowledge base. Building on the success of those that have paved the way will shave off valuable development time for the novice.

    I asked three times for detail in order to assist, but the response is akin to asking me to solve your Rubik's cube while handcuffed, and without being able to see the cube!



    May I suggest the several troubleshooting links at:

    See:  Writing an effective forum post

    I wish you all the success in your endeavour. . . .

  • @Robin What am I missing here? I have provided what I thought was everything you asked for, as well as steps to reproduce, in the order to reproduce them, as well as the code being used... the results... the lack of ability to read any information in a reader
    app... I also clearly stated that the once encountered error was no longer occurring in my very first sentence of #14.

    If I’m misreading your response as I’ve somehow offended you - I’ll be the first to apologize!

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

NFC vCard

Posted by Avatar for AntiCat @AntiCat

Actions