hey there,
I am following this thread to set up JSON data, but it is not working for me. This is my first time working with hardware, which is making things much more challenging. I am using the NXP Android library and the sample Android application from here: https://www.nxp.com/design/design-center/software/rfid-developer-resources/taplinx-software-developm...
Below is my code inside Sample_Application_Android/src/main/java/com/nxp/sampletaplinx/WriteActivity.java
public static byte[] intTo2ByteArray(int value) {
return new byte[] {
(byte) (value & 0xFF), // LSB
(byte) ((value >> 8) & 0xFF), // middle byte
(byte) ((value >> 16) & 0xFF) // MSB
};
}
private void tag424DNACardLogic(INTAG424DNA ntag424DNA) {
byte[] KEY_AES128_DEFAULT = new byte[] {
(byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00,
(byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00,
(byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00,
(byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00,
};
byte[] NTAG424DNA_APP_NAME =
{(byte) 0xD2, (byte) 0x76, 0x00, 0x00, (byte) 0x85, 0x01, 0x01};
byte[] data ={ 0x73, 0x75, 0x73, 0x68, 0x69, 0x6C };
mStringBuilder.append("\n\n");
int timeOut = 2000;
try {
ntag424DNA.isoSelectApplicationByDFName(NTAG424DNA_APP_NAME);
KeyData aesKeyData = new KeyData();
Key keyDefault = new SecretKeySpec(KEY_AES128_DEFAULT, "AES");
aesKeyData.setKey(keyDefault);
ntag424DNA.authenticateEV2First(0, aesKeyData, null);
mStringBuilder.append(getString(R.string.Authentication_status_true));
mStringBuilder.append("\n\n");
ntag424DNA.setPICCConfiguration(true);
String jsonTemplate = "{\"uuid\":\"00000000000000\",\"counter\":\"000000\",\"cmac\":\"0000000000000000\",\"domain1\":" + 1 + ",\"domain2\":" + 1 + "}";
byte[] jsonBytes = jsonTemplate.getBytes("UTF-8");
NTAG424DNAFileSettings fs = new NTAG424DNAFileSettings(
CommunicationMode.Plain, // or MAC/ENC depending on your security
(byte) 0x0E, // Read access: Key 0
(byte) 0x0E, // Write access: Key 0
(byte) 0x0E, // Read/Write: Key 0
(byte) 0x00 // Change access: Free
);
byte[] type = "U".getBytes("US-ASCII");
fs.setSDMEnabled(true);
fs.setUIDMirroringEnabled(true);
fs.setSDMReadCounterEnabled(true);
byte[] bytes = new byte[] { (byte)0xE0, (byte)0x00, (byte)0x00 };
fs.setSdmAccessRights(bytes);
byte[] uuidOffset = intTo2ByteArray(8);
fs.setUidOffset(uuidOffset);
byte[] readCounterOffset = intTo2ByteArray(35);
fs.setSdmReadCounterOffset(readCounterOffset);
byte[] macOffset = intTo2ByteArray(51);
fs.setSdmMacInputOffset(uuidOffset);
fs.setSdmMacOffset(macOffset);
ntag424DNA.changeFileSettings(FILE_NUMBER, fs);
// Create NDEF record
NdefRecordWrapper record = new NdefRecordWrapper(
NdefRecordWrapper.TNF_WELL_KNOWN,
type,
new byte[0], // empty ID
jsonBytes // payload (your JSON)
);
// Wrap record into NDEF message
NdefMessageWrapper msg = new NdefMessageWrapper(record);
ntag424DNA.writeNDEF(msg);
NxpLogUtils.save();
} catch (Exception e) {
writeFailedMessage();
mStringBuilder.append(e.getMessage());
Log.i("MainActivity", "URI NDEF message written successful $msg " + e.getMessage() );
showMessage(mStringBuilder.toString(), PRINT);
NxpLogUtils.save();
}
} would be great help if someone can assist me with this