Set-Up Info:
Beaglebone Black Rev C running debian jessie
PN532 Elechouse V3 Module
iojs v2.2.1
ndef-js
mifare-classic-js
libnfc v1.7.1
libfreefare 0.4.0
Code I use to write the tag:
#!/usr/bin/env node
var ndef = require('ndef'),
mifare = require('..'),
message,
bytes;
message = [
ndef.textRecord("Hello from nodejs")
];
bytes = ndef.encodeMessage(message);
mifare.write(bytes, function(err) {
if (err) {
console.log("Write failed ");
console.log(err);
} else {
console.log("OK");
}
});
Code I use to read the tag:
var ndef = require('ndef'),
mifare = require('..');
mifare.read(function(err, buffer) {
if (err) {
console.log("Read failed ");
console.log(err);
} else {
// TODO handle empty buffer!
console.log(buffer.toJSON());
var message = ndef.decodeMessage(buffer.toJSON());
console.log("Found NDEF message with " + message.length +
(message.length === 1 ? " record" : " records" ));
console.log(ndef.stringify(message));
}
})
I am getting this error when trying to use this library with mifare-classic which you wrote also.
I read up about what .slice and .unshift do and it seems to work on arrays but instead the value returned is an object so i modified your code to
ndef.js:276
var bytes = bytes.data.slice(0),
ndef-uri.js:41
encoded.data.unshift(protolCode);
ndef-text.js:8
languageCode = data.data.slice(1, 1 + languageCodeLength),
ndef-text.js:14
return util.bytesToString(data.data.slice(languageCodeLength + 1));
ndef-text.js:25
encoded.data.unshift(lang.length);
no errors appear but nothing happens and the mifare classic card doesn't appear to get written at all.
I just get this:
Found Mifare Classic 1k with UID 07cf36f2.
NFC Forum application contains a "NDEF Message TLV".
Record
Even when i tried to log the raw data to understand what was going on, it showed me this:
Found Mifare Classic 1k with UID 07cf36f2.
NFC Forum application contains a "NDEF Message TLV".
{ type: 'Buffer', data: [ 193, 0, 0, 0, 0, 0, 0, 0 ] }
Found NDEF message with 1 record
Record
Which is weird because it seems to be missing some data as I think it's supposed to look like
This is the encoded Data
[ 193,
undefined,
0,
0,
0,
0,
{ type: 'Buffer', data: [ 84 ] },
{ type: 'Buffer',
data:
[ 2,
101,
110,
72,
101,
108,
108,
111,
32,
102,
114,
111,
109,
32,
110,
111,
100,
101,
106,
115 ] } ]
NDEF file is 8 bytes long.
Found Mifare Classic 1k with UID 07cf36f2.
OK
instead.
The card also reads as empty on android.
I tried to follow and log all the return values and it seems like the return values are definitely correct. But it's just not writing to the card which is what I don't understand.
I messaged you on twitter about this also.