SHARE
TWEET

Untitled

a guest Jun 26th, 2019 66 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import serial
  2. import datetime
  3. ser = serial.Serial('COM4',9600)
  4. print("Serial input ready..")
  5. import mysql.connector
  6. mydb = mysql.connector.connect(
  7.   host="localhost",
  8.   user="rfid",
  9.   passwd="rfidpasswd",
  10.   database="rfid"
  11. )
  12. mycursor = mydb.cursor()
  13. try:
  14.   while True:
  15.     line = ser.readline().strip()
  16.     data = line.decode('ascii').split(':')
  17.     rid = data[0]
  18.     tag = data[1]
  19.     time = datetime.datetime.now()
  20.     c1 = "select * from tag_logs where reader_id = 'Reader_001' and timestamp > time= time - 60 and tag_no = tag"
  21.     if
  22.     c1 = 1
  23.     //returns value then open door (write to serial)
  24.     mycursor.execute(c1)
  25.  
  26.     command2 = "INSERT INTO tag_logs (reader_id, tag_no) VALUES ('" +rid+ "','" +tag+ "')"
  27.     print(command)
  28.     mycursor.execute(command)
  29.     mydb.commit()
  30. except KeyboardInterrupt:
  31.   pass
  32.      
  33. #include <RFID.h>
  34. #include <SPI.h>
  35. #define SS_PIN 10
  36. #define RST_PIN 9
  37.  
  38. RFID rfid(SS_PIN, RST_PIN);
  39. int serNum[5];
  40. String cardno;
  41. int interval = 15000; // millisec
  42. long now = 0;
  43. long lasttime = millis();
  44. // change Reader ID to your name
  45. String readerID = "Reader_002";
  46.  
  47. void setup() {
  48. Serial.begin(9600);
  49. SPI.begin();
  50. rfid.init();
  51. pinMode(MISO, OUTPUT);
  52.  
  53. }
  54.  
  55. void loop() {
  56. now = millis();
  57. if (now > lasttime + interval) {
  58. lasttime = now;
  59. Serial.print(readerID);
  60. Serial.print(":");
  61. Serial.println("I am alive");
  62. }
  63. if (rfid.isCard()) {
  64. if (rfid.readCardSerial()) {
  65. lasttime = now;
  66. cardno = String(rfid.serNum[0]) +
  67. String(rfid.serNum[1]) +
  68. String(rfid.serNum[2]) +
  69. String(rfid.serNum[3]) +
  70. String(rfid.serNum[4]);
  71.  
  72.  
  73.  
  74. //if(tagvalue == HIGH)
  75. Serial.print(readerID);
  76. Serial.print(":");
  77. Serial.println(cardno);
  78. }
  79. }
  80. rfid.halt();
  81. delay(1000);
  82. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top