Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error while reading! Status: false Data: 55 BitSize: 0 #27

Open
ulisesvina opened this issue Dec 19, 2021 · 0 comments
Open

Error while reading! Status: false Data: 55 BitSize: 0 #27

ulisesvina opened this issue Dec 19, 2021 · 0 comments

Comments

@ulisesvina
Copy link

I tried using the example code in issue 5 (modified a bit to make it work), and the output was the following.

Error while reading! Status: false Data: 55 BitSize: 0
[ 55 ]
Error while writing! Status: false Data: 55 BitSize: 0
Error while reading! Status: false Data: 55 BitSize: 0
[ 55 ]
Error while writing! Status: false Data: 55 BitSize: 0
Error while reading! Status: false Data: 55 BitSize: 0
Block 6
[ 105, 116, 104, 117 ]
Error while writing! Status: false Data: 55 BitSize: 0
Error while reading! Status: false Data: 55 BitSize: 0
[ 55 ]
Error while reading! Status: false Data: 55 BitSize: 0
Block 7
[ 98, 46, 99, 111 ]
Error while writing! Status: false Data: 55 BitSize: 0
Error while reading! Status: false Data: 55 BitSize: 0
[ 55 ]
Error while reading! Status: false Data: 55 BitSize: 0
Block 8
[ 109, 254 ]
Error while writing! Status: false Data: 55 BitSize: 0
Error while reading! Status: false Data: 55 BitSize: 0
[ 55 ]
finished successfully!

This is the new code I wrote:

const MFRC522 = require("mfrc522-rpi"),
SoftSPI = require("rpi-softspi");

let continueReading = true;

const softSPI = new SoftSPI({
    clock: 23,
    mosi: 19,
    miso: 21,
    client: 24
}),
mfrc522 = new MFRC522(softSPI).setResetPin(22);

const defaultUrl = "github.com";
let payload = process.argv[2] ? process.argv[2] : defaultUrl;

while (continueReading) {
  //# reset card
  mfrc522.reset();

  //# Scan for cards
  let response = mfrc522.findCard();
  if (!response.status) {
      continue;
  }

  //# Get the UID of the card
  response = mfrc522.getUid();
  if (!response.status) {
      console.log("UID Scan Error");
      continue;
  }
  //# If we have the UID, continue
  const uid = response.data;

  // add 0xFE to end of message
  payload = payload + "þ";
  // character to be inserted after NDEF header
  let firstChar = payload.slice(0, 1).charCodeAt(0);
  let stringArray = chunkSubstr(payload.slice(1), 4);

  // NDEF message headers
  let data = [0x03, 0x44, 0xD1, 0x01];
  console.log(mfrc522.getDataForBlock(4));
  mfrc522.writeDataToBlock(4, data);
  // 0x04 = https://
  data = [0x40, 0x55, 0x04, firstChar];
  console.log(mfrc522.getDataForBlock(5));
  mfrc522.writeDataToBlock(5, data);

  const startBlock = 6;
  for (var i = startBlock; i < (startBlock + stringArray.length); i++){
    // must read page before writing
    mfrc522.getDataForBlock(i);
    let binPayload = string2Bin(stringArray[i-startBlock]);
    console.log(`Block ${i}`);
    console.log(binPayload);
    mfrc522.writeDataToBlock(i, binPayload);
    console.log(mfrc522.getDataForBlock(i).splice(0, 4));
  }
  continueReading = false;
  console.log("finished successfully!");
}

function string2Bin(str) {
  var result = [];
  for (var i = 0; i < str.length; i++) {
    // result.push(str.charCodeAt(i).toString(10));
    result.push(str.charCodeAt(i));
  }
  return result;
}

function chunkSubstr(str, size) {
  var numChunks = Math.ceil(str.length / size),
      chunks = new Array(numChunks);

  for(var i = 0, o = 0; i < numChunks; ++i, o += size) {
    chunks[i] = str.substr(o, size);
  }

  return chunks;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant