HK RFID Monitor is basically a Python-based software for RFID. It reads the data coming to the com port and displays it on your laptop screen. The data used in this project are IDs, names, and roll numbers of students, coming from a micro-controller (AVR or simply Arduino). The software reads the values with the serial' module of Python and displays it using 'Tkinker.'
How is the data coming to the COM port?In this project, Arduino is used to sending data to the COM port, so it is easier to understand how the data is coming to the port for those who have worked with Arduino or AVR microcontroller.
Let us assume that our microcontroller board (Arduino UNO) is connected to COM port 4 of our PC and take the following dummy Arduino code:
void setup() {
Serial.begin(9600); }void loop() {
Serial.print("id=1000; name=Hamza Khalid; rollnumber=115;");
Serial.print("\n "); delay(3000);
Serial.print("id=1001; name=Ahmed Arif; rollnumber=120;");
Serial.print("\n ");
delay(3000);
Serial.print("id=1002; name=Ammar Ahmed; rollnumber=142;");
Serial.print("\n ");
delay(3000);
}
So, the output on Arduino's serial monitor will be:
id=1000; name=Hamza Khalid; rollnumber=115;id=1001; name=Ahmed Arif; rollnumber=120;id=1002; name=Ammar Ahmed; rollnumber=142; (... continue)
How is software processing data?The following line (Line 121) in our Python file allows you to type the port name on which the data is coming. As our Arduino is connected to port No. 4 so we write 'COM4' in the input box:
Labelh=Label(root,text='Enter port Name. E.g: COM4',font=("Arial","14")).place(x=120,y=40)
The python program now starts reading 'COM4' and saves every line in a string with the help of the following lines (Line 55, 56):
thing = self.ser.readline().decode('ascii')
string = str(thing)
The program now does string parsing to separate the values of id, name, and roll number of a student with the help of the following lines (Line 72-83):
for i in range(2, len(string)):
if string[i] == ';':
break
v = string[3:i]
for j in range(10, len(string)):
if string[j] == ';':
break
c = string[i + 7:j]
or k in range(20, len(string)):
if string[k] == len(string):
break
p = string[j + 13:k-1]
Storing in the databaseThe values of id, name, and roll number are stored in variable v, c, and p. The values are then stored in thethesqlite3 database and are displayed on the software screen with the help of the following lines:
call.execute("INSERT INTO rfid (datestamp, id, name, rollnumber) VALUES (?,?,?,?)", (date, v, c, p))
conn.commit()
call.execute('SELECT * FROM rfid ORDER BY datestamp DESC LIMIT 5')for row in call.fetchall():
print(row)
self.tree.insert("", 0, text="FETCHED --- >", values=(date, v, c, p))
How to make changes for your own data?It would be best if you made the following changes for your own data:
- You need to change the Arduino code, which is sending data to the port. *Note that your source of sending data to the COM port can be anything, so make changes accordingly.
- Make changes in lines (61-72) of Python program used for string parsing to separate values from the string (in our case, alphanumeric values if their, name, and roll number).
- Change the names of columns in the database.
- Change the tree used in the python code.
Comments