def read(): reader = rc522() try: print("begin reading") id, data = reader.read() return id, data except Exception as error: print("error haappen:%s" % str(error)) finally: GPIO.cleanup()
def write(): reader = rc522() try: data = raw_input("input data: ") print("input data is: " + data) print("place your card to write") reader.write(data) print("write success") return data except Exception as error: print("error haappen: " + str(error)) finally: GPIO.cleanup()
def write(): reader = rc522() try: id, data1 = reader.read() data = raw_input("input data: ") print("input data is: " + (data)) print("place your card to write") data1 = int(data1) + int(data) data1 = str(data1) reader.write(data1) print("write success") return data1 except Exception as error: print("error haappen: " + str(error)) finally: GPIO.cleanup()
def rfid(sock): print("请刷卡") reader = rc522() try: id, data = reader.read() print("id is " + str(id)) print("data is " + str(data)) data = int(data) - 2 data = str(data) reader.write(data) tcp(sock) except Exception as error: print("error haappen: " + str(error)) finally: GPIO.cleanup()
def getValue(name, value): global OPENED while OPENED: reader = rc522() try: print("begin reading.") idid, info = reader.read() print("id is {}".format(idid)) print("information is {}".format(info)) except Exception as error: print("error is {}".format(error)) finally: GPIO.cleanup() if idid != None: send_data = {"idid": "{}".format(idid), "info": "{}".format(info)} req = requests.post(REMOTE_SERVER_URL + "?data=" + str(send_data)) print("time: " + str(datetime.datetime.now())) print("send {0}".format(send_data)) time.sleep(SLEEP_SECOND)
import RPi.GPIO as GPIO from mfrc522 import SimpleMFRC522 as rc522 reader = rc522() LED_number = 7 READ = 0 WRITE = 1 operation = READ GPIO.setup(LED_number, GPIO.OUT) while True: try: if operation == READ: print("begin reading ") id, data = reader.read() data = data.strip() print("id is " + str(id)) print("data is " + str(data)) try: value = float(data) if value > 100: GPIO.output(LED_number, GPIO.HIGH) else: GPIO.output(LED_number, GPIO.LOW) print('input data is ' + str(value)) except Exception as error: print('input data "' + data + '" is not digit only') print("error: " + str(error)) if operation == WRITE: data = raw_input("input data:") print("input data is: " + data)