Click here to Skip to main content
15,886,110 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello
I try to compare ID store in database mysql with ID read from reader RFID in python using Raspberry PI.
If right ID -> ON led
How can I compare it?
Here is my code reader RFID:
Python
import serial
import RPi.GPIO as GPIO
import MySQLdb
from binascii import hexlify
serial = serial.Serial("/dev/ttyAMA0",
                        parity = serial.PARITY_NONE,
                        stopbits = serial.STOPBITS_ONE,
                        bytesize = serial.EIGHTBITS,
                        timeout = 0.1)
GPIO.setmode(GPIO.BOARD)
GPIO.setup(12, GPIO.OUT)
send = "\xAA\x00\x03\x25\x26\x00\x00\xBB" 
db = MySQLdb.connect(host='localhost', user='root',passwd='root', db='ex_1')
while 1:
     serial.write(send)
     data = serial.readline()
     tach = data[5:8]
     hex = hexlify(tach) 
     num = int(hex,16)
     print (num) #-> it return 180031
     if (num == # ID in database mysql):
        GPIO.output(12, True);
     else:
        GPIO.output(12, False);

how to compare "num" with ID in database?
Please help me. Thanks.
Posted
Updated 22-Oct-14 0:01am
v3

1 solution

Well, I guess you start with getting the ID from your database.

MySQL Python tutorial[^]

Then it should be easy to compare the values. :)
 
Share this answer
 
Comments
Member 10390715 22-Oct-14 6:45am    
Thanks, I will see it :D

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900