Skip to content
This repository was archived by the owner on Sep 10, 2024. It is now read-only.

Commit f24b3fb

Browse files
authored
makefile release (#141)
1 parent f4845e6 commit f24b3fb

11 files changed

+257
-330
lines changed

.gitignore

+12
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,15 @@
55
*.conf
66
.DS_Store
77

8+
pyscan/*
9+
pysense/*
10+
pysense2/*
11+
pytrack/*
12+
pytrack2/*
13+
14+
pyscan.zip
15+
pysense.zip
16+
pysense2.zip
17+
pytrack.zip
18+
pytrack2.zip
19+

Makefile

+102
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
release: pyscan pysense pysense2 pytrack pytrack2
2+
3+
4+
pyscan:
5+
rm -rf pyscan
6+
rm -f pyscan.zip
7+
@echo "Making Pyscan"
8+
mkdir pyscan
9+
mkdir pyscan/lib
10+
#sensors
11+
cp shields/lib/LIS2HH12.py pyscan/lib/
12+
cp shields/lib/MFRC630.py pyscan/lib/
13+
cp shields/lib/SI7006A20.py pyscan/lib/
14+
cp shields/lib/LTR329ALS01.py pyscan/lib/
15+
#pycoproc
16+
cp shields/lib/pycoproc_1.py pyscan/lib/
17+
#example
18+
cp shields/pyscan_1.py pyscan/main.py
19+
20+
zip -r pyscan.zip pyscan
21+
22+
pysense:
23+
rm -rf pysense
24+
rm -f pysense.zip
25+
@echo "Making Pysense"
26+
mkdir pysense
27+
mkdir pysense/lib
28+
# sensors
29+
cp shields/lib/LIS2HH12.py pysense/lib/
30+
cp shields/lib/LTR329ALS01.py pysense/lib/
31+
cp shields/lib/MPL3115A2.py pysense/lib/
32+
cp shields/lib/SI7006A20.py pysense/lib/
33+
# pycoproc
34+
cp shields/lib/pycoproc_1.py pysense/lib/
35+
# example
36+
cp shields/pysense_1.py pysense/main.py
37+
38+
zip -r pysense.zip pysense
39+
40+
pysense2:
41+
rm -rf pysense2
42+
rm -f pysense2.zip
43+
@echo "Making Pysense 2"
44+
mkdir pysense2
45+
mkdir pysense2/lib
46+
# sensors
47+
cp shields/lib/LIS2HH12.py pysense2/lib/
48+
cp shields/lib/LTR329ALS01.py pysense2/lib/
49+
cp shields/lib/MPL3115A2.py pysense2/lib/
50+
cp shields/lib/SI7006A20.py pysense2/lib/
51+
# pycoproc
52+
cp shields/lib/pycoproc_2.py pysense2/lib/
53+
# example
54+
cp shields/pysense_2.py pysense2/main.py
55+
56+
zip -r pysense2.zip pysense2
57+
58+
pytrack:
59+
rm -rf pytrack
60+
rm -f pytrack.zip
61+
@echo "Making Pytrack"
62+
mkdir pytrack
63+
mkdir pytrack/lib
64+
#sensors
65+
cp shields/lib/L76GNSS.py pytrack/lib/
66+
cp shields/lib/LIS2HH12.py pytrack/lib/
67+
#pycoproc
68+
cp shields/lib/pycoproc_1.py pytrack/lib/
69+
#example
70+
cp shields/pytrack_1.py pytrack/main.py
71+
72+
zip -r pytrack.zip pytrack
73+
74+
pytrack2:
75+
rm -rf pytrack2
76+
rm -f pytrack2.zip
77+
@echo "Making Pytrack2"
78+
mkdir pytrack2
79+
mkdir pytrack2/lib
80+
#sensors
81+
cp shields/lib/L76GNSS.py pytrack2/lib/
82+
cp shields/lib/LIS2HH12.py pytrack2/lib/
83+
#pycoproc
84+
cp shields/lib/pycoproc_2.py pytrack2/lib/
85+
#example
86+
cp shields/pytrack_2.py pytrack2/main.py
87+
88+
zip -r pytrack2.zip pytrack2
89+
90+
clean:
91+
@echo "Cleaning up files"
92+
rm -rf pyscan
93+
rm -rf pysense
94+
rm -rf pysense2
95+
rm -rf pytrack
96+
rm -rf pytrack2
97+
98+
rm -f pyscan.zip
99+
rm -f pysense.zip
100+
rm -f pysense2.zip
101+
rm -f pytrack.zip
102+
rm -f pytrack2.zip

shields/pyscan_1.py

+77-49
Original file line numberDiff line numberDiff line change
@@ -1,86 +1,114 @@
11
'''
22
Simple Pyscan NFC / MiFare Classic Example
3-
Copyright (c) 2020, Pycom Limited.
3+
Copyright (c) 2019, Pycom Limited.
44
5-
This example runs the NFC discovery loop in a thread.
6-
If a card is detected it will read the UID and compare it to VALID_CARDS
7-
RGB LED is BLUE while waiting for card,
8-
GREEN if card is valid, RED if card is invalid
5+
This example continuously sends a REQA for ISO14443A card type
6+
If a card is discovered, it will read the UID
7+
If DECODE_CARD = True, will attempt to authenticate with CARDkey
8+
If authentication succeeds will attempt to read sectors from the card
99
'''
1010

11-
DEBUG = False # change to True to see debug messages
12-
1311
from pycoproc_1 import Pycoproc
1412
from MFRC630 import MFRC630
1513
from LIS2HH12 import LIS2HH12
1614
from LTR329ALS01 import LTR329ALS01
17-
import binascii
1815
import time
1916
import pycom
20-
import _thread
2117

18+
#add your card UID here
2219
VALID_CARDS = [[0x43, 0x95, 0xDD, 0xF8],
2320
[0x43, 0x95, 0xDD, 0xF9],
2421
[0x46, 0x5A, 0xEB, 0x7D, 0x8A, 0x08, 0x04]]
2522

23+
24+
# This is the default key for an unencrypted MiFare card
25+
CARDkey = [ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF ]
26+
DECODE_CARD = False
27+
2628
py = Pycoproc(Pycoproc.PYSCAN)
2729
nfc = MFRC630(py)
2830
lt = LTR329ALS01(py)
2931
li = LIS2HH12(py)
3032

33+
pybytes_enabled = False
34+
if 'pybytes' in globals():
35+
if(pybytes.isconnected()):
36+
print('Pybytes is connected, sending signals to Pybytes')
37+
pybytes_enabled = True
38+
3139
RGB_BRIGHTNESS = 0x8
3240

3341
RGB_RED = (RGB_BRIGHTNESS << 16)
3442
RGB_GREEN = (RGB_BRIGHTNESS << 8)
3543
RGB_BLUE = (RGB_BRIGHTNESS)
3644

45+
counter = 0
46+
47+
def check_uid(uid, len):
48+
return VALID_CARDS.count(uid[:len])
49+
50+
def send_sensor_data(name, timeout):
51+
if(pybytes_enabled):
52+
while(True):
53+
pybytes.send_signal(2, lt.light())
54+
pybytes.send_signal(3, li.acceleration())
55+
time.sleep(timeout)
56+
3757
# Make sure heartbeat is disabled before setting RGB LED
3858
pycom.heartbeat(False)
3959

4060
# Initialise the MFRC630 with some settings
4161
nfc.mfrc630_cmd_init()
4262

43-
def check_uid(uid, len):
44-
return VALID_CARDS.count(uid[:len])
45-
46-
def print_debug(msg):
47-
if DEBUG:
48-
print(msg)
49-
50-
def send_sensor_data(name, timeout):
51-
while(True):
52-
print(lt.light())
53-
print(li.acceleration())
54-
time.sleep(timeout)
55-
56-
def discovery_loop(nfc, id):
57-
while True:
58-
# Send REQA for ISO14443A card type
59-
print_debug('Sending REQA for ISO14443A card type...')
60-
atqa = nfc.mfrc630_iso14443a_WUPA_REQA(nfc.MFRC630_ISO14443_CMD_REQA)
61-
print_debug('Response: {}'.format(atqa))
62-
if (atqa != 0):
63-
# A card has been detected, read UID
64-
print_debug('A card has been detected, read UID...')
65-
uid = bytearray(10)
66-
uid_len = nfc.mfrc630_iso14443a_select(uid)
67-
print_debug('UID has length: {}'.format(uid_len))
68-
if (uid_len > 0):
69-
print_debug('Checking if card with UID: [{:s}] is listed in VALID_CARDS...'.format(binascii.hexlify(uid[:uid_len],' ').upper()))
63+
print('Scanning for cards')
64+
while True:
65+
# Send REQA for ISO14443A card type
66+
atqa = nfc.mfrc630_iso14443a_WUPA_REQA(nfc.MFRC630_ISO14443_CMD_REQA)
67+
if (atqa != 0):
68+
# A card has been detected, read UID
69+
print('A card has been detected, reading its UID ...')
70+
uid = bytearray(10)
71+
uid_len = nfc.mfrc630_iso14443a_select(uid)
72+
print('UID has length {}'.format(uid_len))
73+
if (uid_len > 0):
74+
# A valid UID has been detected, print details
75+
counter += 1
76+
print("%d\tUID [%d]: %s" % (counter, uid_len, nfc.format_block(uid, uid_len)))
77+
if DECODE_CARD:
78+
# Try to authenticate with CARD key
79+
nfc.mfrc630_cmd_load_key(CARDkey)
80+
for sector in range(0, 16):
81+
if (nfc.mfrc630_MF_auth(uid, nfc.MFRC630_MF_AUTH_KEY_A, sector * 4)):
82+
pycom.rgbled(RGB_GREEN)
83+
# Authentication was sucessful, read card data
84+
readbuf = bytearray(16)
85+
for b in range(0, 4):
86+
f_sect = sector * 4 + b
87+
len = nfc.mfrc630_MF_read_block(f_sect, readbuf)
88+
print("\t\tSector %s: Block: %s: %s" % (nfc.format_block([sector], 1), nfc.format_block([b], 1), nfc.format_block(readbuf, len)))
89+
else:
90+
print("Authentication denied for sector %s!" % nfc.format_block([sector], 1))
91+
pycom.rgbled(RGB_RED)
92+
# It is necessary to call mfrc630_MF_deauth after authentication
93+
# Although this is also handled by the reset / init cycle
94+
nfc.mfrc630_MF_deauth()
95+
else:
96+
#check if card uid is listed in VALID_CARDS
7097
if (check_uid(list(uid), uid_len)) > 0:
71-
print_debug('Card is listed, turn LED green')
98+
print('Card is listed, turn LED green')
7299
pycom.rgbled(RGB_GREEN)
100+
if(pybytes_enabled):
101+
pybytes.send_signal(1, ('Card is listed', uid))
73102
else:
74-
print_debug('Card is not listed, turn LED red')
103+
print('Card is not listed, turn LED red')
75104
pycom.rgbled(RGB_RED)
76-
else:
77-
# No card detected
78-
print_debug('Did not detect any card...')
79-
pycom.rgbled(RGB_BLUE)
80-
nfc.mfrc630_cmd_reset()
81-
time.sleep(.5)
82-
nfc.mfrc630_cmd_init()
83-
84-
# This is the start of our main execution... start the thread
85-
_thread.start_new_thread(discovery_loop, (nfc, 0))
86-
_thread.start_new_thread(send_sensor_data, ('Thread 2', 10))
105+
if(pybytes_enabled):
106+
pybytes.send_signal(1, ('Unauthorized card detected', uid))
107+
108+
else:
109+
pycom.rgbled(RGB_BLUE)
110+
# We could go into power saving mode here... to be investigated
111+
nfc.mfrc630_cmd_reset()
112+
time.sleep(.5)
113+
# Re-Initialise the MFRC630 with settings as these got wiped during reset
114+
nfc.mfrc630_cmd_init()

shields/pyscan_1_nfc.py

-75
This file was deleted.

0 commit comments

Comments
 (0)