You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
constMFRC522=require("mfrc522-rpi"),SoftSPI=require("rpi-softspi");letcontinueReading=true;constsoftSPI=newSoftSPI({clock: 23,mosi: 19,miso: 21,client: 24}),mfrc522=newMFRC522(softSPI).setResetPin(22);constdefaultUrl="github.com";letpayload=process.argv[2] ? process.argv[2] : defaultUrl;while(continueReading){//# reset cardmfrc522.reset();//# Scan for cardsletresponse=mfrc522.findCard();if(!response.status){continue;}//# Get the UID of the cardresponse=mfrc522.getUid();if(!response.status){console.log("UID Scan Error");continue;}//# If we have the UID, continueconstuid=response.data;// add 0xFE to end of messagepayload=payload+"þ";// character to be inserted after NDEF headerletfirstChar=payload.slice(0,1).charCodeAt(0);letstringArray=chunkSubstr(payload.slice(1),4);// NDEF message headersletdata=[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);conststartBlock=6;for(vari=startBlock;i<(startBlock+stringArray.length);i++){// must read page before writingmfrc522.getDataForBlock(i);letbinPayload=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!");}functionstring2Bin(str){varresult=[];for(vari=0;i<str.length;i++){// result.push(str.charCodeAt(i).toString(10));result.push(str.charCodeAt(i));}returnresult;}functionchunkSubstr(str,size){varnumChunks=Math.ceil(str.length/size),chunks=newArray(numChunks);for(vari=0,o=0;i<numChunks;++i,o+=size){chunks[i]=str.substr(o,size);}returnchunks;}
The text was updated successfully, but these errors were encountered:
I tried using the example code in issue 5 (modified a bit to make it work), and the output was the following.
This is the new code I wrote:
The text was updated successfully, but these errors were encountered: