I'm using an NTAG I2C plus 2k memory tag and using the react-native-nfc-manager library to interface with the tag.
Is there a way to specify the sector that you're intending to write to?
I know there is an API to specify the page offset to write to, but how do you specify the sector the page offsets are in?
(Updated to include below code sample)
let tech = Platform.OS === 'ios' ? NfcTech.MifareIOS : NfcTech.NfcA;
await NfcManager.requestTechnology(tech, {
alertMessage: 'Hold your phone close to the NFC tag.',
});
let fullLength = data.length + 7;
let payloadLength = data.length + 3;
let cmd =
Platform.OS === 'ios'
? NfcManager.sendMifareCommandIOS
: NfcManager.transceive;
// select sector 2 prior to writing data
await cmd([0xc2, 0xff]);
await cmd([0x02, 0x00, 0x00, 0x00]);
await cmd([
0xa2,
MEMORY_MAPPING[`${chunkToWriteTo}`][1],
0x03,
fullLength,
0xd1,
0x01,
]);
await cmd([
0xa2,
MEMORY_MAPPING[`${chunkToWriteTo}`][2],
payloadLength,
0x54,
0x02,
0x65,
]);
let currentPage = MEMORY_MAPPING[`${chunkToWriteTo}`][0] + 2;
let currentPayload = [0xa2, currentPage, 0x6e];
for (let i = 0; i < data.length; i++) {
currentPayload.push(parseInt(data[i]));
if (currentPayload.length == 6) {
try {
await cmd(currentPayload);
} catch (error) {
console.log(error);
}
currentPage += 1;
currentPayload = [0xa2, currentPage];
}
}
Thanks in advance.