A Python wrapper for MATRIX HAL NFC
Project description
MATRIX-Lite-NFC-Py
MATRIX Lite NFC Py is a package that allows users of varying skill levels to easily program NFC with their MATRIX Creator.
Smartphone Apps For Debugging
Roadmap
- Reading Info (All tags)
- Reading Pages (MIFARE Ultralight & NTAG)
- Writing Page (MIFARE Ultralight & NTAG)
- Reading NDEF (MIFARE Ultralight & NTAG)
- Writing NDEF (MIFARE Ultralight & NTAG)
- Docker deployment to PyPi
Installation
- Install matrix-hal-nfc to use this library.
Reference
Import Statement
import matrix_lite_nfc as nfc
nfc.status
When a read or write function completes, it will contain a status code to indicate the result. nfc.Status returns a string of what that number means.
nfc.status(/*number*/)
nfc.read
There can only be one instance of NFC reading. This is a hardware limitation that will not change.
Synchronous Read
A simple read that returns an object with tag data.
nfc.read.scan({
# At least 1 read options is required. Less options -> faster reading!
"info": True, # Generic information for any NFC tag
"pages": True, # All page data
"ndef": True, # A single page(faster than pages)
"page": 0, # All NDEF data
})
Starting Read Loop
A non-blocking loop that passes tag data to a callback.
def read_callback(tag):
if(tag.status == 256):
print("NFC Tag Scanned!")
print(tag)
elif(tag.status == 1024):
print("Nothing Scanned!")
# Configure what you want to read
nfc.read.start({
"rate": 0.5, # Read loop speed (Seconds)
"info": True,
"pages": True,
"ndef": True,
"page": 0,
}, read_callback)
Stopping Read Loop
nfc.read.stop()
nfc.Message
1. Creating a new NDEF Message
# Create an empty NDEF message
msg = nfc.Message()
# Add NDEF Records to message
msg.addUriRecord("https://community.matrix.one")
msg.addUriRecord("tel:+14085551212")
msg.addTextRecord("Hello World")
msg.addTextRecord("Hola Mundo", "es")
msg.addMimeMediaRecord("text/json", '{"answer": 42}')
# You then pass msg into nfc.write.message(msg)
2. Reading a new NDEF Message
# Get NDEF data from scanned tag
tag = nfc.read.scan({"ndef": True})
# Create & print NDEF message
msg = nfc.Message(tag.ndef.content)
print(msg.getRecords())
nfc.write
Writing to an NFC tag should normally be done inside the read loop.
Writing an NDEF message
# Create new message
msg = nfc.Message()
msg.addUriRecord("https://community.matrix.one")
# Write and then Print status codes for activation & writing
print(nfc.write.message(msg))
Erasing an NDEF message
print(nfc.write.erase())
Writing to a tag's page (WARNING)
Be careful when writing to a page. You can accidentally lock your NFC tag!
# arg1: page you want to overwrite
# arg2: Array of numbers that represents a byte
print(nfc.write.page(25, [48,45,59,21]))
Building Locally For Development
Download the repository.
git clone https://github.com/matrix-io/matrix-lite-nfc-py
Install pybind11.
sudo python3 -m pip install pybind11
Compile and install library.
sudo python3 -m pip install ./matrix-lite-nfc-py
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Hashes for matrix_lite_nfc-0.0.1-cp37-cp37m-linux_armv7l.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a7cb957ebcae9940cda120877d0bc156bb793b8eeeda7494f2cff60e960bc80e |
|
MD5 | 8d640a06dfaf1b846bf13da9c1ec515b |
|
BLAKE2b-256 | 8b0c05972ca0293a568daaee6d8e1b239289df5bfb89bdccc8ecb0df59b9e2d8 |
Hashes for matrix_lite_nfc-0.0.1-cp37-cp37m-linux_armv6l.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9b29eaab6e2e28b7256368a1cfc481c7a5e08c5204e96230c97dd0b08762f50e |
|
MD5 | 90e3c6c8b4be388265b9d95bbd349035 |
|
BLAKE2b-256 | 4ea026947540962a5ac955dc6f03b1f066f117fc7f0b5baa3facb84bb6957c97 |
Hashes for matrix_lite_nfc-0.0.1-cp35-cp35m-linux_armv7l.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e6daf3fcc27bb8d97a8e5e240ff838d1695f2e39f9498475100b9f2d3c68fdf9 |
|
MD5 | f7583aefd20660288469a74bedf2d866 |
|
BLAKE2b-256 | ca85b672bd46ef05702336c96579ad356cba9448feb581a90e45ca4bbd1a5c37 |
Hashes for matrix_lite_nfc-0.0.1-cp35-cp35m-linux_armv6l.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 36ba1878b028f5ff28edd4185e26fe17f764e28a5c18e45702dd83dd91271eec |
|
MD5 | 4a6988eff2ffffd98cd57228448e8e61 |
|
BLAKE2b-256 | 05e1b146f3171b586271280c31de08ce20df64f2a179ab504981709fca8e39e1 |