#include <SoftwareSerial.h> // "" int buttonPin = 2; int ledGreenPin = 13; int ledYellowPin = 12; int ledRedPin = 11; // RFID SoftwareSerial RFID(6, 7); String inputString = ""; int rfidData; String rfidNumber = ""; String rfidNumberLast = ""; boolean startPressButton = false; void setup() { Serial.begin(115200); RFID.begin(9600); pinMode(buttonPin, INPUT); pinMode(ledGreenPin, OUTPUT); pinMode(ledYellowPin, OUTPUT); pinMode(ledRedPin, OUTPUT); digitalWrite(ledGreenPin, LOW); digitalWrite(ledYellowPin, LOW); digitalWrite(ledRedPin, LOW); } void loop() { listenButton(); } /* . - RFID */ void listenButton() { if (digitalRead(buttonPin) == HIGH) { if (!startPressButton) { startPressButton = true; clearRFID(); } digitalWrite(ledYellowPin, HIGH); listenRFID(); } else { startPressButton = false; digitalWrite(ledYellowPin, LOW); } } /* RFID. - */ void listenRFID() { if (RFID.available()) { delay(100); rfidNumber = ""; for (int i = 0; i < 14; i++) { rfidData = RFID.read(); if (rfidData < 16) rfidNumber += '0'; rfidNumber += rfidData; } RFID.flush(); sendRDIFNumber(); } } /* */ void sendRDIFNumber() { if (rfidNumber != "" and rfidNumberLast != rfidNumber) { Serial.print("S"); Serial.print(rfidNumber); Serial.print("E"); rfidNumberLast = rfidNumber; rfidNumber = ""; } } /* Arduino */ void serialEvent() { while (Serial.available()) { char inChar = (char)Serial.read(); inputString += inChar; if (inputString == "M1F") { Serial.flush(); inputString = ""; logInOutProcess(); } if (inputString == "M0F") { Serial.flush(); inputString = ""; logInOutFail(); } } } /* - */ void logInOutProcess() { clearRFID(); digitalWrite(ledGreenPin, HIGH); digitalWrite(ledYellowPin, LOW); digitalWrite(ledRedPin, LOW); delay(1000); digitalWrite(ledGreenPin, LOW); digitalWrite(ledYellowPin, LOW); digitalWrite(ledRedPin, LOW); } /* - */ void logInOutFail() { clearRFID(); digitalWrite(ledGreenPin, LOW); digitalWrite(ledYellowPin, LOW); digitalWrite(ledRedPin, HIGH); delay(1000); digitalWrite(ledGreenPin, LOW); digitalWrite(ledYellowPin, LOW); digitalWrite(ledRedPin, LOW); } /* RFID- */ void clearRFID() { RFID.flush(); rfidNumberLast = ""; rfidNumber = ""; }
security find-generic-password -ga my password
var inputString = ""; var serialport = require('serialport'); var SerialPort = serialport.SerialPort; var sp = new SerialPort('/dev/tty.usbmodem20331', { // "" "Tools/Serial Port" Arduino baudrate: 115200 }); var exec = require('child_process').exec; sp.on('open', function() { /* */ sp.on('data', function(data) { inputString += data.toString("utf8"); /* "" */ var cardCode = inputString.match(/S([0-9]+)E/i); if (cardCode && cardCode[1] != 'undefined') { checkCardNumber(cardCode[1]); inputString = ''; } }); }); function checkCardNumber(cardCode) { sp.flush(function() { /* , ... */ if (cardCode == '0211111111111111111111111103') { /* ... Arduino " " */ sp.write('M1F'); /* : " "? */ exec('ps aux | grep -c ScreenSaverEngine.app | grep -v grep', function (error, stdout, stderr) { /* - Kaychain "" */ if (parseInt(stdout) > 2) { exec("security 2>&1 >/dev/null find-generic-password -ga mypassword | ruby -e 'print $1 if STDIN.gets =~ /^password: \"(.*)\"$/'", function (error, stdout, stderr) { if (error !== null) return; var appleScript = 'osascript -e \'tell application "System Events"\' -e \'key code 56\' -e \'delay 0.5\' -e \'keystroke "' + stdout + '"\' -e \'key code 36\' -e \'end tell\''; exec(appleScript); }); /* ... " " - */ } else { exec('open -a /System/Library/Frameworks/ScreenSaver.framework/Versions/Current/Resources/ScreenSaverEngine.app'); } }); /* - Arduino " " */ } else { sp.write('M0F'); } }); }
do shell script "/usr/local/bin/node ~/Desktop/RFIDUnLock/rfid.js"
<key>LSBackgroundOnly</key> </true>
Source: https://habr.com/ru/post/240647/
All Articles