-
• #2
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?
-
• #3
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! -
• #4
Hi @Gordon
I've figured out what the data in the arrays are.new Uint8Array([162, 4, 3, 10, 209, 1]).buffer 162: NFC command for "write" 4: Index for where to put data within tag array 3: Type length 10: Record length 209: NDEF record header 1: Type Name Field new Uint8Array([162, 5, 6, 84, 2, 101]).buffer 6: Payload Length 84: Well known record 2: Well known record type (in this case - the encoding for this text (UTF)) 101: e new Uint8Array([162, 6, 110, 112, 111, 111]).buffer 110: n - ("en" is locale) 112: p 111: o 111: o new Uint8Array([162, 7, 254, 0, 0, 48]).buffer 254: Marks the end of the payload
Further information on this can be found here.
I am now able to send custom commands/string through NFC to Puck.js. -
• #5
That's great! If you get a moment it'd be really good if you could post up some example code for how to handle this on both sides :)
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:
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):
What am I missing?
Thanks in advance