Example #1
0
File: puzle1.py Project: dres-a/PBE
    def read_uid(self):
        PN532_HSU = Pn532Hsu(
            Pn532Hsu.RPI_MINI_UART
        )  #Creo interfaz. El argumento indica el puerto serial al que esta conectado el PN532
        lector = Pn532(
            PN532_HSU
        )  #Creo el objeto encargado de interpretar la información recibida

        lector.begin()

        if (
                not lector.getFirmwareVersion()
        ):  #Este método se usa exclusivamente para verificar si la RPI detecta el dispositivo

            print(
                "ERROR. Compruebe la conexión del dispositivo a la RPI. Vuelva a intentarlo"
            )  # Solo entra en esta condición si no se reconoce PN532
            sys.exit()

        leido, uid = lector.readPassiveTargetID(
            pn532.PN532_MIFARE_ISO14443A_106KBPS)

        while (not leido):

            leido, uid = lector.readPassiveTargetID(
                pn532.PN532_MIFARE_ISO14443A_106KBPS)

        uid = binascii.hexlify(uid).decode('utf-8').upper()
        return uid
Example #2
0
def setup():
    global nfc
    global config
    global tags

    # test for settings.ini
    config = parseConfig('settings.ini')
    if (config == []):
        log(message=
            'Error missing or empty settings.ini - see settings.ini.example')
        sys.exit(1)

    # test for mpc
    mpc_result = call(['mpc', 'status'])
    if (mpc_result != 0):
        log(message=
            'Error missing mpc command - check if volumio is setup correctly on the device'
            )
        sys.exit(1)

    # update nfc code list
    if refresh_list():
        log(message='Updated local tag list from %s' %
            config['readnfc']['tagurl'])

    # test for nfc code list
    tags = read_cards()
    if tags == False:
        log('Error no tags from local tag file read')
        sys.exit(1)

    # test for nfc reader
    log('Initialize i2c...')
    # pn532 = Pn532_i2c()
    PN532_I2C = Pn532I2c(1)
    # log('config')
    # pn532.SAMconfigure()
    log('Initialize NFC reader...')
    nfc = Pn532(PN532_I2C)
    # log('refresh list')

    log('Get NFC reader data...')
    nfc.begin()

    versiondata = nfc.getFirmwareVersion()
    if not versiondata:
        log("Didn't find PN53x board: " + str(versiondata))
        raise RuntimeError("Didn't find PN53x board")  # halt

    log('Set NFC reader configuration...')
    nfc.setPassiveActivationRetries(0xFF)
    nfc.SAMConfig()
Example #3
0
def pn532uid():
    PN532_I2C = Pn532I2c(1)
    nfc = Pn532(PN532_I2C)
    nfc.begin()
    versiondata = nfc.getFirmwareVersion()
    if (not versiondata):
        print("Didn't find PN53x board")
        raise RuntimeError("Didn't find PN53x board")  # halt

    #  Got ok data, print it out!
    print("Found chip PN5 {:#x} Firmware ver. {:d}.{:d}".format((versiondata >> 24) & 0xFF, (versiondata >> 16) & 0xFF,
                                                                (versiondata >> 8) & 0xFF))

    #  configure board to read RFID tags
    # nfc.SAMConfig()
    success, uid = nfc.readPassiveTargetID(pn532.PN532_MIFARE_ISO14443A_106KBPS)
    res = format(binascii.hexlify(uid))
    return res
    def read_uid(self):
        PN532_HSU = Pn532Hsu(Pn532Hsu.RPI_MINI_UART)
        nfc = Pn532(PN532_HSU)

        nfc.begin()
        nfc.SAMConfig()
        print("Esperando tarjeta...")

        success, uid = nfc.readPassiveTargetID(
            pn532.PN532_MIFARE_ISO14443A_106KBPS)

        while (not success):
            success, uid = nfc.readPassiveTargetID(
                pn532.PN532_MIFARE_ISO14443A_106KBPS)

        id = uid.hex()
        print("Detectado\nUID en hexadecimal: ")
        return id
Example #5
0
import time
import binascii

from pn532pi import Pn532
from pn532pi import Pn532I2c
from pn532pi import Pn532Spi
from pn532pi import Pn532Hsu

# Set the desired interface to True
SPI = False
I2C = False
HSU = True

if SPI:
    PN532_SPI = Pn532Spi(Pn532Spi.SS0_GPIO8)
    nfc = Pn532(PN532_SPI)
elif HSU:
    PN532_HSU = Pn532Hsu(0)
    nfc = Pn532(PN532_HSU)

elif I2C:
    PN532_I2C = Pn532I2c(1)
    nfc = Pn532(PN532_I2C)

_prevIDm = bytearray(b'\x00' * 8)
_prevTime = 0


def millis():
    return int(round(time.time() * 1000))
Example #6
0
 def __init__(self):
     self.PN532_I2C = Pn532I2c(0)
     self.nfc = Pn532(self.PN532_I2C)
     self.setup()
Example #7
0
import time
import binascii

from pn532pi import Pn532, pn532
from pn532pi import Pn532I2c

PN532_I2C = Pn532I2c(1)
nfc = Pn532(PN532_I2C)


def setup():
    nfc.begin()

    versiondata = nfc.getFirmwareVersion()
    if (not versiondata):
        print("Didn't find PN53x board")
        raise RuntimeError("Didn't find PN53x board")  # halt
    nfc.SAMConfig()
    print("Waiting for an ISO14443A Card ...")


def get_nfc_ids():
    success, uid = nfc.readPassiveTargetID(
        pn532.PN532_MIFARE_ISO14443A_106KBPS)

    if (success):
        if (len(uid) == 4):
            keya = bytearray([0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF])
            success = nfc.mifareclassic_AuthenticateBlock(uid, 4, 0, keya)

            if (success):
from pn532pi import Pn532, pn532
from pn532pi import Pn532Hsu

PN532_HSU = Pn532Hsu(Pn532Hsu.RPI_MINI_UART)
nfc = Pn532(PN532_HSU)


class Rfidpuzzle1:
    def read_uid(self):
        PN532_HSU = Pn532Hsu(Pn532Hsu.RPI_MINI_UART)
        nfc = Pn532(PN532_HSU)

        nfc.begin()
        nfc.SAMConfig()
        print("Esperando tarjeta...")

        success, uid = nfc.readPassiveTargetID(
            pn532.PN532_MIFARE_ISO14443A_106KBPS)

        while (not success):
            success, uid = nfc.readPassiveTargetID(
                pn532.PN532_MIFARE_ISO14443A_106KBPS)

        id = uid.hex()
        print("Detectado\nUID en hexadecimal: ")
        return id


if __name__ == '__main__':
    rf = Rfidpuzzle1()
    uid = rf.read_uid()
Example #9
0
import binascii

from pn532pi import Pn532
from pn532pi import Snep
from pn532pi import Pn532I2c
from pn532pi import Pn532Spi
from pn532pi import Pn532Hsu

# Set the desired interface to True
SPI = False
I2C = False
HSU = True

if SPI:
    PN532_SPI = Pn532Spi(Pn532Spi.SS0_GPIO8)
    PN532 = Pn532(PN532_SPI)
# When the number after #elif set as 1, it will be switch to HSU Mode
elif HSU:
    PN532_HSU = Pn532Hsu(0)
    PN532 = Pn532(PN532_HSU)

# When the number after #if & #elif set as 0, it will be switch to I2C Mode
elif I2C:
    PN532_I2C = Pn532I2c(1)
    PN532 = Pn532(PN532_I2C)

nfc = Snep(PN532)


def setup():
    print("-------Peer to Peer--------")