Comments (3)
Hello this is an example that can write to NTAG21x:
"use strict";
const mfrc522 = require("mfrc522-rpi");
mfrc522.initWiringPi(0);
let continueReading = true;
//# This loop keeps checking for chips. If one is near it will get the UID and authenticate
console.log("scanning...");
console.log("Please put chip or keycard in the antenna inductive zone!");
console.log("Press Ctrl-C to stop.");
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;
}
from mfrc522-rpi.
thanks @musdom
from mfrc522-rpi.
closing the issue, and linking this in the readme as example for NTAG213
from mfrc522-rpi.
Related Issues (17)
- Unable to determine hardware version. I see: Hardware : BCM2835 HOT 9
- MFRC522 not working on RPi 4 HOT 5
- Increasing range of MFRC522 HOT 2
- MFRC522-python not working after running mfrc522-rpi HOT 1
- Very long delay on startup: Reason for 250ms delay? HOT 10
- 7 byte uid HOT 1
- Cannot get continuous read HOT 5
- Atomics.wait cannot be called in this context HOT 12
- Pin in use
- Request for publishing the package in npm
- Race condition(?) on a mifare ISO/IEC 14443-4 card
- Request for publishing the repo in npm
- Error while reading! Status: false Data: 55 BitSize: 0
- Use SPI1 HOT 8
- Error: Cannot find module '../build/Release/WiringPi HOT 6
- LEDs on module HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mfrc522-rpi.