liviudiaconu85
Posts: 6
Joined: Thu May 23, 2019 10:35 am

use if from rc522

Thu May 23, 2019 10:41 am

Hello everyone, I need your help.
I use rc522, and I want to implement if var = id, but I get strange errors.
Thanks for your help.

code:

Code: Select all

#!/usr/bin/env python

import RPi.GPIO as GPIO
from mfrc522 import SimpleMFRC522

reader = SimpleMFRC522()

try:
        id, text = reader.read()
        print(id)
        print(text)

var=id
if(var == 286858287748) :
print "Hi Liviu !"


finally:
        GPIO.cleanup()
error:

Code: Select all

  File "Read2.py", line 13
    var=id
      ^
SyntaxError: invalid syntax

Andyroo
Posts: 3306
Joined: Sat Jun 16, 2018 12:49 am
Location: Lincs U.K.

Re: use if from rc522

Thu May 23, 2019 12:20 pm

Welcome to the forum.

One issue i can see is that you have not completed the ‘try’ block with the ‘except’ part so Python gets a bit lost as to what should come next.

I’m not on a Pi at the moment but I think this should work if you match the indent to your code:

Code: Select all

try:
    id, text = reader.read()
    print(id)
    print(text)
except:
    print(‘Error in reading card’)
There is a good tool to play with the ‘try...except’ function on the web at https://www.w3schools.com/python/python_try_except.asp

Edit: I think you will need to add spaces after the ‘if’ line Else the print will also cause an error. You will find that you have to be very careful wth indents in Python - miss a space or four (4 being the normal setting) and all sorts will happen to the program :roll: :lol:
Need Pi spray - these things are breeding in my house...

liviudiaconu85
Posts: 6
Joined: Thu May 23, 2019 10:35 am

Re: use if from rc522

Thu May 23, 2019 1:36 pm

Code: Select all

#!/usr/bin/env python

import RPi.GPIO as GPIO
import requests
from mfrc522 import SimpleMFRC522

reader = SimpleMFRC522()



try:
        id, text = reader.read()
        print(id)
        print(text)
        os.system("wget -qO /dev/null 'http://www.web.com/rrhh/api/remote.php?i$
finally:
        GPIO.cleanup()
Theoretical I want that after recognizing the id, I call an api on the web. it's possible?

User avatar
jadro
Posts: 395
Joined: Sun Oct 02, 2016 1:20 pm
Location: Croatia

Re: use if from rc522

Thu May 23, 2019 1:45 pm

Code: Select all

try:
        id, text = reader.read()
        print(id)
        print(text)
        if id > 0:
            os.system("wget -qO /dev/null 'http://www.web.com/rrhh/api/remote.php?i$
        # Maybe you want this:
        if id > 0:
            os.system("wget -qO /dev/null 'http://www.web.com/rrhh/api/remote.php?id={}".format(id))
finally:
        GPIO.cleanup()
Oracle backend database developer
SmartHome IoT & Microprocessor enthusiast and hobbyist

liviudiaconu85
Posts: 6
Joined: Thu May 23, 2019 10:35 am

Re: use if from rc522

Thu May 23, 2019 1:47 pm

i am received this error

code

Code: Select all

  #!/usr/bin/env python

import RPi.GPIO as GPIO
import os
import requests
from mfrc522 import SimpleMFRC522

reader = SimpleMFRC522()

try:
        id, text = reader.read()
        print(id)
        print(text)
        if id > 0:
            os.system("wget -qO /dev/null 'http://www.web.com/rrhh/api/remote.php?id={}".format(id))
finally:
        GPIO.cleanup()




error :

Code: Select all

sh: 1: Syntax error: Unterminated quoted string

User avatar
jadro
Posts: 395
Joined: Sun Oct 02, 2016 1:20 pm
Location: Croatia

Re: use if from rc522

Thu May 23, 2019 1:56 pm

It is end of file, put ")
Oracle backend database developer
SmartHome IoT & Microprocessor enthusiast and hobbyist

User avatar
jadro
Posts: 395
Joined: Sun Oct 02, 2016 1:20 pm
Location: Croatia

Re: use if from rc522

Thu May 23, 2019 1:57 pm

It is also one quotte ' to end url
Oracle backend database developer
SmartHome IoT & Microprocessor enthusiast and hobbyist

liviudiaconu85
Posts: 6
Joined: Thu May 23, 2019 10:35 am

Re: use if from rc522

Thu May 23, 2019 2:06 pm

is not work fine.
i am put this

Code: Select all

os.system("wget -qO /dev/null 'http://www.ccccccccs.com/gps/registers.php?id={}.format(id)'")
in MySQL instead of id is this

Code: Select all

id = {}.format(id)

User avatar
jadro
Posts: 395
Joined: Sun Oct 02, 2016 1:20 pm
Location: Croatia

Re: use if from rc522

Thu May 23, 2019 2:38 pm

os.system("wget -qO /dev/null 'http://www.ccccccccs.com/gps/registers.php?id={}' ".format(id))

This is properly closed quotas. Try with this.
Jadro
Oracle backend database developer
SmartHome IoT & Microprocessor enthusiast and hobbyist

liviudiaconu85
Posts: 6
Joined: Thu May 23, 2019 10:35 am

Re: use if from rc522

Thu May 23, 2019 3:48 pm

Now it does not work Error goes out before calling the web.

Code: Select all

 File "read4.py", line 15
    os.system("wget -qO /dev/null 'http://www.ccc.com/gps/registergps.php?id={}'".format(id))
     ^
IndentationError: expected an indented block

User avatar
jadro
Posts: 395
Joined: Sun Oct 02, 2016 1:20 pm
Location: Croatia

Re: use if from rc522

Thu May 23, 2019 3:51 pm

Put it on the same indent as old code. And all in one line, not in two lines
Oracle backend database developer
SmartHome IoT & Microprocessor enthusiast and hobbyist

Andyroo
Posts: 3306
Joined: Sat Jun 16, 2018 12:49 am
Location: Lincs U.K.

Re: use if from rc522

Thu May 23, 2019 3:55 pm

Try this as your formatting is getting out of hand :lol:

Code: Select all

#!/usr/bin/env python

import RPi.GPIO as GPIO
import os
import requests
from mfrc522 import SimpleMFRC522

reader = SimpleMFRC522()

try:
    id, text = reader.read()
    print(id)
    print(text)
    if id > 0:
        os.system("wget -qO /dev/null 'http://www.web.com/rrhh/api/remote.php?id={}'".format(id))
finally:
    GPIO.cleanup()
Need Pi spray - these things are breeding in my house...

liviudiaconu85
Posts: 6
Joined: Thu May 23, 2019 10:35 am

Re: use if from rc522

Thu May 23, 2019 4:09 pm

Thanks, it works.

Return to “Python”