NRC received events ( NRF.on('NFCrx') )

Posted on
  • I'm using Puck.js (Espruino v2.01) and I want to be able to manipulate variables based on data that is written to the NFC tag using NFCrx.
    If I use the 'NFCon' event, and console log based on that, everything works when I scan NFC:

    >NRF.on('NFCon', () => { console.log("test"); });
    =undefined
    test
    test
    test
    

    But when I use the NFCrx event instead, after NFCStart of course, the event callback is not called (almost as if the event is not registered):

    >NRF.nfcStart();
    =new Uint8Array([95, 193, 71, 81, 42, 138, 1, 165, 4, 3]).buffer
    >NRF.on('NFCrx', (rx) => { console.log(rx); });
    =undefined
    >NRF.on('NFCrx', (rx) => { NRF.nfcSend("test"); });
    =undefined
    >NRF.on('NFCrx', (rx) => { console.log("test"); });
    =undefined
    

    What am I missing?
    Thanks in advance

  • That's odd - I guess you could try using nfcStop first just in case NFC was already set up?

    Personally I haven't used it but this module does:

    Do you could use that as a reference?

  • Hi Gordon - Only just got around to looking at this one again - it seems to be working now (for whatever reason...)

    I have a much better understanding of how this all works too - I'm working on a way today read the data transmitted via NFC and action upon it based on whether it matches an expected format.
    I've got reading and writing working fine - but I'm tripping over the format of the data that's actually being sent. I'll spill my thoughts here, in case anyone else stumbles across this.
    When a 'write' command is sent to the chip, (if it complies to NTAG213/215/216) it'll be formatted like so:
    [[command code] [address of data to be changed] [data] [crc]]
    Pretty basic so far. But the NFC writer app that I'm using to test actually writes some prefix and suffix data, which makes it hard to find the data that I have specified to be written, as it is surrounded by metadata. Here is an example of a write sent to the chip (actually ends up being 4 write commands):

    new Uint8Array([162, 4, 3, 10, 209, 1]).buffer
    new Uint8Array([162, 5, 6, 84, 2, 101]).buffer
    new Uint8Array([162, 6, 110, 112, 111, 111]).buffer // <-- my data, following the 110, in ASCII
    new Uint8Array([162, 7, 254, 0, 0, 48]).buffer
    

    So the question I'm looking into is, what is the prefix/suffix data? And even if I wish to ignore this, there is no callback function on the tag to detect that it has finished being written to, so it's hard to locate my data afterwards - or even know when afterwards is.
    I'll keep the thread posted, for archive sake!

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

NRC received events ( NRF.on('NFCrx') )

Posted by Avatar for user94249 @user94249

Actions