mxgxw / MFRC522-python

A small class to interface with the NFC reader Module MFRC522
GNU Lesser General Public License v3.0
521 stars 419 forks source link

Error Trying to run Read.py without sudo on RPI 3 B+ #79

Open obdbeats opened 4 years ago

obdbeats commented 4 years ago

Hi! Im getting some headhaches with this I have been testing this code into my RPI MODEL B+ (2011) and works perfectly. Now i have set up same code into my new RPI (3 b+ 2017) and there is the problem. (I thought upgrading to a new RPI would be much more easier)

The code:

#!/usr/bin/python
import signal
import time
import sys
import webbrowser
from pirc522 import RFID
#chrome = chromium-browser()

run = True
rdr = RFID()
util = rdr.util()
util.debug = True

def end_read(signal,frame):
    global run
    print("\nCtrl+C captured, ending read.")
    run = False
    rdr.cleanup()
    sys.exit()

signal.signal(signal.SIGINT, end_read)

print("Starting")
while run:
    rdr.wait_for_tag()

    (error, data) = rdr.request()
    if not error:
        print("\nDetected: " + format(data, "02x"))

    (error, uid) = rdr.anticoll()
    if not error:
        print("Card read UID: "+str(uid[0])+","+str(uid[1])+","+str(uid[2])+","+str(uid[3]))

        print("Setting tag")
        util.set_tag(uid)

    webbrowser.open('http://localhost/verperfil/rfid.php?rfid='+str(uid[0])+''+str(uid[1])+''+str(uid[2])+''+str(uid[3])+'')
        print("\nAuthorizing")
        #util.auth(rdr.auth_a, [0x12, 0x34, 0x56, 0x78, 0x96, 0x92])
        #util.auth(rdr.auth_b, [0x74, 0x00, 0x52, 0x35, 0x00, 0xFF])
        print("\nReading")
        util.read_out(4)
        print("\nDeauthorizing")
        util.deauth()

        time.sleep(1)

when i run as sudo it works almost all except the Web browser (i cannot run as ROOT) the output:

pi@raspberrypi:~ $ sudo python /var/www/html/pi-rc522/examples/asigna.py
/usr/local/lib/python2.7/dist-packages/pi_rc522-2.2.1-py2.7.egg/pirc522/rfid.py:78: RuntimeWarning: This channel is already in use, continuing anyway.  Use GPIO.setwarnings(False) to disable warnings.
Starting
--user-data-dir --disable-quic --enable-tcp-fast-open --ppapi-flash-path=/usr/lib/chromium-browser/libpepflashplayer.so --ppapi-flash-args=enable_stagevideo_auto=0 --ppapi-flash-version=
[1975:1975:0808/005424.477659:ERROR:zygote_host_impl_linux.cc(89)] Running as root without --no-sandbox is not supported. See https://crbug.com/638180.

AND if i run without sudo get this error:

pi@raspberrypi:~ $ python /var/www/html/pi-rc522/examples/asigna.py
Traceback (most recent call last):
  File "/var/www/html/pi-rc522/examples/asigna.py", line 11, in <module>
    rdr = RFID()
  File "build/bdist.linux-armv7l/egg/pirc522/rfid.py", line 78, in __init__
RuntimeError: No access to /dev/mem.  Try running as root!

Also I've already try: sudo chmod 777 /dev/mem chown pi /dev/mem

HELP PLEASE!! HEELP!!