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);
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)