This repository has been archived by the owner on Sep 10, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 372
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
257 additions
and
330 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
release: pyscan pysense pysense2 pytrack pytrack2 | ||
|
||
|
||
pyscan: | ||
rm -rf pyscan | ||
rm -f pyscan.zip | ||
@echo "Making Pyscan" | ||
mkdir pyscan | ||
mkdir pyscan/lib | ||
#sensors | ||
cp shields/lib/LIS2HH12.py pyscan/lib/ | ||
cp shields/lib/MFRC630.py pyscan/lib/ | ||
cp shields/lib/SI7006A20.py pyscan/lib/ | ||
cp shields/lib/LTR329ALS01.py pyscan/lib/ | ||
#pycoproc | ||
cp shields/lib/pycoproc_1.py pyscan/lib/ | ||
#example | ||
cp shields/pyscan_1.py pyscan/main.py | ||
|
||
zip -r pyscan.zip pyscan | ||
|
||
pysense: | ||
rm -rf pysense | ||
rm -f pysense.zip | ||
@echo "Making Pysense" | ||
mkdir pysense | ||
mkdir pysense/lib | ||
# sensors | ||
cp shields/lib/LIS2HH12.py pysense/lib/ | ||
cp shields/lib/LTR329ALS01.py pysense/lib/ | ||
cp shields/lib/MPL3115A2.py pysense/lib/ | ||
cp shields/lib/SI7006A20.py pysense/lib/ | ||
# pycoproc | ||
cp shields/lib/pycoproc_1.py pysense/lib/ | ||
# example | ||
cp shields/pysense_1.py pysense/main.py | ||
|
||
zip -r pysense.zip pysense | ||
|
||
pysense2: | ||
rm -rf pysense2 | ||
rm -f pysense2.zip | ||
@echo "Making Pysense 2" | ||
mkdir pysense2 | ||
mkdir pysense2/lib | ||
# sensors | ||
cp shields/lib/LIS2HH12.py pysense2/lib/ | ||
cp shields/lib/LTR329ALS01.py pysense2/lib/ | ||
cp shields/lib/MPL3115A2.py pysense2/lib/ | ||
cp shields/lib/SI7006A20.py pysense2/lib/ | ||
# pycoproc | ||
cp shields/lib/pycoproc_2.py pysense2/lib/ | ||
# example | ||
cp shields/pysense_2.py pysense2/main.py | ||
|
||
zip -r pysense2.zip pysense2 | ||
|
||
pytrack: | ||
rm -rf pytrack | ||
rm -f pytrack.zip | ||
@echo "Making Pytrack" | ||
mkdir pytrack | ||
mkdir pytrack/lib | ||
#sensors | ||
cp shields/lib/L76GNSS.py pytrack/lib/ | ||
cp shields/lib/LIS2HH12.py pytrack/lib/ | ||
#pycoproc | ||
cp shields/lib/pycoproc_1.py pytrack/lib/ | ||
#example | ||
cp shields/pytrack_1.py pytrack/main.py | ||
|
||
zip -r pytrack.zip pytrack | ||
|
||
pytrack2: | ||
rm -rf pytrack2 | ||
rm -f pytrack2.zip | ||
@echo "Making Pytrack2" | ||
mkdir pytrack2 | ||
mkdir pytrack2/lib | ||
#sensors | ||
cp shields/lib/L76GNSS.py pytrack2/lib/ | ||
cp shields/lib/LIS2HH12.py pytrack2/lib/ | ||
#pycoproc | ||
cp shields/lib/pycoproc_2.py pytrack2/lib/ | ||
#example | ||
cp shields/pytrack_2.py pytrack2/main.py | ||
|
||
zip -r pytrack2.zip pytrack2 | ||
|
||
clean: | ||
@echo "Cleaning up files" | ||
rm -rf pyscan | ||
rm -rf pysense | ||
rm -rf pysense2 | ||
rm -rf pytrack | ||
rm -rf pytrack2 | ||
|
||
rm -f pyscan.zip | ||
rm -f pysense.zip | ||
rm -f pysense2.zip | ||
rm -f pytrack.zip | ||
rm -f pytrack2.zip |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,86 +1,114 @@ | ||
''' | ||
Simple Pyscan NFC / MiFare Classic Example | ||
Copyright (c) 2020, Pycom Limited. | ||
Copyright (c) 2019, Pycom Limited. | ||
This example runs the NFC discovery loop in a thread. | ||
If a card is detected it will read the UID and compare it to VALID_CARDS | ||
RGB LED is BLUE while waiting for card, | ||
GREEN if card is valid, RED if card is invalid | ||
This example continuously sends a REQA for ISO14443A card type | ||
If a card is discovered, it will read the UID | ||
If DECODE_CARD = True, will attempt to authenticate with CARDkey | ||
If authentication succeeds will attempt to read sectors from the card | ||
''' | ||
|
||
DEBUG = False # change to True to see debug messages | ||
|
||
from pycoproc_1 import Pycoproc | ||
from MFRC630 import MFRC630 | ||
from LIS2HH12 import LIS2HH12 | ||
from LTR329ALS01 import LTR329ALS01 | ||
import binascii | ||
import time | ||
import pycom | ||
import _thread | ||
|
||
#add your card UID here | ||
VALID_CARDS = [[0x43, 0x95, 0xDD, 0xF8], | ||
[0x43, 0x95, 0xDD, 0xF9], | ||
[0x46, 0x5A, 0xEB, 0x7D, 0x8A, 0x08, 0x04]] | ||
|
||
|
||
# This is the default key for an unencrypted MiFare card | ||
CARDkey = [ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF ] | ||
DECODE_CARD = False | ||
|
||
py = Pycoproc(Pycoproc.PYSCAN) | ||
nfc = MFRC630(py) | ||
lt = LTR329ALS01(py) | ||
li = LIS2HH12(py) | ||
|
||
pybytes_enabled = False | ||
if 'pybytes' in globals(): | ||
if(pybytes.isconnected()): | ||
print('Pybytes is connected, sending signals to Pybytes') | ||
pybytes_enabled = True | ||
|
||
RGB_BRIGHTNESS = 0x8 | ||
|
||
RGB_RED = (RGB_BRIGHTNESS << 16) | ||
RGB_GREEN = (RGB_BRIGHTNESS << 8) | ||
RGB_BLUE = (RGB_BRIGHTNESS) | ||
|
||
counter = 0 | ||
|
||
def check_uid(uid, len): | ||
return VALID_CARDS.count(uid[:len]) | ||
|
||
def send_sensor_data(name, timeout): | ||
if(pybytes_enabled): | ||
while(True): | ||
pybytes.send_signal(2, lt.light()) | ||
pybytes.send_signal(3, li.acceleration()) | ||
time.sleep(timeout) | ||
|
||
# Make sure heartbeat is disabled before setting RGB LED | ||
pycom.heartbeat(False) | ||
|
||
# Initialise the MFRC630 with some settings | ||
nfc.mfrc630_cmd_init() | ||
|
||
def check_uid(uid, len): | ||
return VALID_CARDS.count(uid[:len]) | ||
|
||
def print_debug(msg): | ||
if DEBUG: | ||
print(msg) | ||
|
||
def send_sensor_data(name, timeout): | ||
while(True): | ||
print(lt.light()) | ||
print(li.acceleration()) | ||
time.sleep(timeout) | ||
|
||
def discovery_loop(nfc, id): | ||
while True: | ||
# Send REQA for ISO14443A card type | ||
print_debug('Sending REQA for ISO14443A card type...') | ||
atqa = nfc.mfrc630_iso14443a_WUPA_REQA(nfc.MFRC630_ISO14443_CMD_REQA) | ||
print_debug('Response: {}'.format(atqa)) | ||
if (atqa != 0): | ||
# A card has been detected, read UID | ||
print_debug('A card has been detected, read UID...') | ||
uid = bytearray(10) | ||
uid_len = nfc.mfrc630_iso14443a_select(uid) | ||
print_debug('UID has length: {}'.format(uid_len)) | ||
if (uid_len > 0): | ||
print_debug('Checking if card with UID: [{:s}] is listed in VALID_CARDS...'.format(binascii.hexlify(uid[:uid_len],' ').upper())) | ||
print('Scanning for cards') | ||
while True: | ||
# Send REQA for ISO14443A card type | ||
atqa = nfc.mfrc630_iso14443a_WUPA_REQA(nfc.MFRC630_ISO14443_CMD_REQA) | ||
if (atqa != 0): | ||
# A card has been detected, read UID | ||
print('A card has been detected, reading its UID ...') | ||
uid = bytearray(10) | ||
uid_len = nfc.mfrc630_iso14443a_select(uid) | ||
print('UID has length {}'.format(uid_len)) | ||
if (uid_len > 0): | ||
# A valid UID has been detected, print details | ||
counter += 1 | ||
print("%d\tUID [%d]: %s" % (counter, uid_len, nfc.format_block(uid, uid_len))) | ||
if DECODE_CARD: | ||
# Try to authenticate with CARD key | ||
nfc.mfrc630_cmd_load_key(CARDkey) | ||
for sector in range(0, 16): | ||
if (nfc.mfrc630_MF_auth(uid, nfc.MFRC630_MF_AUTH_KEY_A, sector * 4)): | ||
pycom.rgbled(RGB_GREEN) | ||
# Authentication was sucessful, read card data | ||
readbuf = bytearray(16) | ||
for b in range(0, 4): | ||
f_sect = sector * 4 + b | ||
len = nfc.mfrc630_MF_read_block(f_sect, readbuf) | ||
print("\t\tSector %s: Block: %s: %s" % (nfc.format_block([sector], 1), nfc.format_block([b], 1), nfc.format_block(readbuf, len))) | ||
else: | ||
print("Authentication denied for sector %s!" % nfc.format_block([sector], 1)) | ||
pycom.rgbled(RGB_RED) | ||
# It is necessary to call mfrc630_MF_deauth after authentication | ||
# Although this is also handled by the reset / init cycle | ||
nfc.mfrc630_MF_deauth() | ||
else: | ||
#check if card uid is listed in VALID_CARDS | ||
if (check_uid(list(uid), uid_len)) > 0: | ||
print_debug('Card is listed, turn LED green') | ||
print('Card is listed, turn LED green') | ||
pycom.rgbled(RGB_GREEN) | ||
if(pybytes_enabled): | ||
pybytes.send_signal(1, ('Card is listed', uid)) | ||
else: | ||
print_debug('Card is not listed, turn LED red') | ||
print('Card is not listed, turn LED red') | ||
pycom.rgbled(RGB_RED) | ||
else: | ||
# No card detected | ||
print_debug('Did not detect any card...') | ||
pycom.rgbled(RGB_BLUE) | ||
nfc.mfrc630_cmd_reset() | ||
time.sleep(.5) | ||
nfc.mfrc630_cmd_init() | ||
|
||
# This is the start of our main execution... start the thread | ||
_thread.start_new_thread(discovery_loop, (nfc, 0)) | ||
_thread.start_new_thread(send_sensor_data, ('Thread 2', 10)) | ||
if(pybytes_enabled): | ||
pybytes.send_signal(1, ('Unauthorized card detected', uid)) | ||
|
||
else: | ||
pycom.rgbled(RGB_BLUE) | ||
# We could go into power saving mode here... to be investigated | ||
nfc.mfrc630_cmd_reset() | ||
time.sleep(.5) | ||
# Re-Initialise the MFRC630 with settings as these got wiped during reset | ||
nfc.mfrc630_cmd_init() |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.