Added deployment script and example main.py.

This commit is contained in:
2024-11-19 21:12:40 +01:00
parent df33e072c3
commit 4e7968fc0c
2 changed files with 94 additions and 0 deletions

33
software/src/mfrc522/deploy.sh Executable file
View File

@@ -0,0 +1,33 @@
#!/usr/bin/bash
set -eu
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
MFRC522_LIBDIR=$(readlink -f "$SCRIPT_DIR"/../../lib/micropython-mfrc522)
error_exit()
{
MESSAGE="$1"
echo "Error: $MESSAGE"
echo "Exit."
exit 1
}
check_command()
{
CMD="$1"
if ! command -v "$CMD" 2>&1 >/dev/null
then
error_exit "'$CMD' not found."
fi
}
check_command mpremote
mpremote fs cp "$MFRC522_LIBDIR/mfrc522.py" ":mfrc522.py"
mpremote reset
echo "Library deployed. Run main.py with 'mpremote run main.py'"

View File

@@ -0,0 +1,61 @@
from mfrc522 import MFRC522
import utime
def uidToString(uid):
mystring = ""
for i in uid:
mystring = "%02X" % i + mystring
return mystring
def main():
reader = MFRC522(spi_id=1,sck=10,miso=12,mosi=11,cs=13,rst=9)
print("")
print("Please place card on reader")
print("")
PreviousCard = [0]
try:
while True:
reader.init()
(stat, tag_type) = reader.request(reader.REQIDL)
#print('request stat:',stat,' tag_type:',tag_type)
if stat == reader.OK:
(stat, uid) = reader.SelectTagSN()
if uid == PreviousCard:
continue
if stat == reader.OK:
print("Card detected {} uid={}".format(hex(int.from_bytes(bytes(uid),"little",False)).upper(),reader.tohexstring(uid)))
if reader.IsNTAG():
print("Got NTAG{}".format(reader.NTAG))
reader.MFRC522_Dump_NTAG(Start=0,End=reader.NTAG_MaxPage)
#print("Write Page 5 to 0x1,0x2,0x3,0x4 in 2 second")
#utime.sleep(2)
#data = [1,2,3,4]
#reader.writeNTAGPage(5,data)
#reader.MFRC522_Dump_NTAG(uid,Start=5,End=6)
else:
(stat, tag_type) = reader.request(reader.REQIDL)
if stat == reader.OK:
(stat, uid2) = reader.SelectTagSN()
if stat == reader.OK:
if uid != uid2:
continue
defaultKey = [255,255,255,255,255,255]
reader.MFRC522_DumpClassic1K(uid,Start=0, End=64, keyA=defaultKey)
PreviousCard = uid
else:
pass
else:
PreviousCard=[0]
utime.sleep_ms(50)
except KeyboardInterrupt:
pass
if __name__ == "__main__":
main()