Coder Social home page Coder Social logo

firsttris / mfrc522-rpi Goto Github PK

View Code? Open in Web Editor NEW
115.0 8.0 35.0 53.24 MB

:key: Control your MFRC522 RFID Module with your Raspberry-pi and JavaScript

License: MIT License

JavaScript 100.00%
mfrc522 nodejs wiringpi nfc rpi rfid rfid-reader rfid-authentication chip card

mfrc522-rpi's People

Contributors

ahmedbhameed avatar devrim-oguz avatar firsttris avatar jonathan-reisdorf avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mfrc522-rpi's Issues

Example of how to write on NTAG213, if possible

Hi,

I'm learning about the mfrc522 and I have a project that can use it with Ntag213, but it would work better if I can write on the tags.

I'm not sure mfrc522 can do this, if it don't could you just comment saying it is not possible? But if it can could you please provide a example of how to write to a NTAG213?

I've spent the last few hours trying to make it work but no success, no Google search that helped.

Thanks.

Pin in use

getting error GPIO24 is currently in use by /sys/class/gpio

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

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;
}

7 byte uid

any way to make this module read the complete UID of newer tags with 7 byte UID?

Very long delay on startup: Reason for 250ms delay?

Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, 250 - i);

I uncovered an issue when this device isn't actually connected, or if rpio is in mock mode.. this loop with Atomics.wait causes my program to hang for several seconds before this frees up.

Can you provide some insight into the reason for the 250ms delay and reducing that by 1ms per cycle for 250 cycles. I'm considering refactoring this, but want to have a better understanding first.

Thanks,

Thomas

Error: Cannot find module '../build/Release/WiringPi

I am trying to bundle up all the required modules starting at read.js into a single file called bundle.js with the browserify command: The following error is raised during operation. Any help

(venv) pi@raspberrypi:~/RFID/New $ browserify node_modules/mfrc522-rpi/test/read.js -o bundle.js
Error: Cannot find module '../build/Release/WiringPi' from '/home/pi/RFID/New/node_modules/wiringpi-node/lib'
at /home/pi/.nvm/versions/node/v8.9.4/lib/node_modules/browserify/node_modules/browser-resolve/node_modules/resolve/lib/async.js:55:21
at load (/home/pi/.nvm/versions/node/v8.9.4/lib/node_modules/browserify/node_modules/browser-resolve/node_modules/resolve/lib/async.js:69:43)
at onex (/home/pi/.nvm/versions/node/v8.9.4/lib/node_modules/browserify/node_modules/browser-resolve/node_modules/resolve/lib/async.js:92:31)
at /home/pi/.nvm/versions/node/v8.9.4/lib/node_modules/browserify/node_modules/browser-resolve/node_modules/resolve/lib/async.js:22:47
at FSReqWrap.oncomplete (fs.js:152:21)

MFRC522-python not working after running mfrc522-rpi

Hello,
I have just installed mfrc522-rpi on my raspberry pi 3, and it I ran the read test example successfully. However, after exiting the app (Ctrl+c), I noticed that my other python program which uses MFRC522-python library, now is not detecting that rfid tag unless I reboot and run it before the mfrc522-rpi example.

in other words, if I run the python example first it works. On exit I call GPIO.cleanup(), so when I run node node /node_modules/mfrc522-rpi/test/read.js it works fine, but if I run python3 mypythonapp.py after it it doesn't detect the tag and output is:
/usr/local/lib/python3.7/dist-packages/mfrc522/MFRC522.py:151: RuntimeWarning: This channel is already in use, continuing anyway. Use GPIO.setwarnings(False) to disable warnings.
GPIO.setup(pin_rst, GPIO.OUT)

I think this has to do with gpio cleanup?
P.S I tried to call rpio.close(22); and this.spi.close() in /node_modules/mfrc522-rpi/index.js, the warning above is gone, but still can't detect the tag.
Can anyone help with this please?

Ta

Hardware: raspberry pi 3 running raspbian buster
Node v12.8.0 (using nvm)

MFRC522 not working on RPi 4

Hi, I'm getting the following error using my SD card that works fine in a Raspberry Pi Model 3, if I put it into a Raspberry Pi Model 4:

WARNING: Hardware auto-detect failed, running in raspi-3 mock mode

And consequently the card detection does not work. Any idea what this could be related to?
Thanks

Race condition(?) on a mifare ISO/IEC 14443-4 card

I'm using this to read mifare classic 1k card and there haven't been any issues. I was recently given a different type of mifare card and at first it looked liked it wasn't being read by the reader but after debugging the findCard() function at index.js it worked?

If i debug around Line 278, nothing happens the response is empty, however if I debug before that and wait just a few milliseconds to a second then I get a response and I successfully get the UID.

So am I right that there is a race condition happening somewhere? it's weird that if I debug the code I get a response but nothing if I don't.

Increasing range of MFRC522

Hello,

In the repo for the python version they claim to have increased the range:
mxgxw/MFRC522-python#30

How can this be done with this module?

I tried:

First I logged the byte that sets the antenna gain
console.log(this.readRegister(CMD.RFCfgReg)) which returns 72.
According to the datasheet of MRFC522, 72 corresponds to 33db.

I tried putting it on 112 (which is 48db) with

this.writeRegister(CMD.RFCfgReg, 0x07 << 4);

in index.js in the function reset();

But If I try to read the same byte later, again with
console.log(this.readRegister(CMD.RFCfgReg)) it still logs 72!

How do I increase the gain?

Thanks

Use SPI1

Hi guys, we are currently doing a prototype that includes a MFRC522 (Robotdyn) reader and a 3.5 TFT screen from Waveshare, after a few days of fighting while we took the two devices (TFT screen in SPI0 and MFRC522 in SPI1), everything works correctly with

but not with this library, we always receive the message
Can not open the SPI device: There is no such file or directory
but
ls /dev/spidev*
returns
/dev/spidev1.0
any ideas for make wiringpi work in spi1?

Cannot get continuous read

Hi,

I am running the read.js script on the test folder, and it seems I cannot get a solid card detection.
When there is no card I can trace that using the following code:

    //# Scan for cards
    let response = mfrc522.findCard();
    if (!response.status) {
        console.log("NOT detected");
        console.log(" ### ");
        return;
    }

But when I let my tag on the reader I cannot get a solid read, instead I get "NOT DETECTED", then it works and I get the tag info ( a read ), then "NOT DETECTED" again, then it works again ... etc. It keeps going on and off like that.

Since I want to be able to tell when there is something on the reader or not the fact that when there is something I cannot get a solid signal is then a problem to me, because it seems that someone is taking the tag out, to put it back in, and out ... etc.

Do you know where that could come from?
I hope I'm not too vague.

Thomas P

LEDs on module

I see at least one red LED on the module. Is it possible to let that blink?!

Atomics.wait cannot be called in this context

My electron build on Raspberry Pi 4 B gives this error:

Uncaught TypeError: Atomics.wait cannot be called in this context
    at Atomics.wait (<anonymous>)
    at MFRC522.setResetPin (/home/alba/Interface_Automat_ArGe/node_modules/mfrc522-rpi/index.js:32)
    at rfid_controller.js:19

It is shown to be caused by the line 32 of index.js -> Atomics.wait( new Int32Array(new SharedArrayBuffer(4)), 0, 0, 50);

can't we replace these Atomics.wait with something else for electron compatibility?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.