Merge branch 'master' of github.com:paulwalko/bac_monitoring_system
commit
6b301b0245
114
client.py
114
client.py
|
@ -9,6 +9,75 @@ import pika
|
||||||
|
|
||||||
from params import rmq_params, socket_params
|
from params import rmq_params, socket_params
|
||||||
|
|
||||||
|
import sys
|
||||||
|
import os
|
||||||
|
import tkinter
|
||||||
|
from tkinter import *
|
||||||
|
|
||||||
|
root=Tk()
|
||||||
|
root.geometry("500x400")
|
||||||
|
|
||||||
|
textBox=Text(root, height=2, width=30)
|
||||||
|
textBox.grid(row=0, column=1)
|
||||||
|
buttonCommit=Button(root, height=1, width=10, text="Enter",
|
||||||
|
command=lambda: retrieve_input())
|
||||||
|
buttonCommit.grid(row=0, column=2)
|
||||||
|
Label(root, text="# of Allowed Drinks: ").grid(row=5, column=1)
|
||||||
|
v = StringVar()
|
||||||
|
v.set("--")
|
||||||
|
Label(root, textvariable=v).grid(row=5, column=2)
|
||||||
|
Label(root, text="Time Until Another Drink (Hours): ").grid(row=6, column=1)
|
||||||
|
v1 = StringVar()
|
||||||
|
v1.set("--")
|
||||||
|
Label(root, textvariable=v1).grid(row=6, column=2)
|
||||||
|
|
||||||
|
def retrieve_input():
|
||||||
|
rfid_id=textBox.get("1.0","end-1c")
|
||||||
|
order_data = {'id': rfid_id, 'ip': socket_host, 'port': socket_port,
|
||||||
|
'size': socket_size}
|
||||||
|
|
||||||
|
checkpoint("Received id \'{}\'".format(rfid_id))
|
||||||
|
|
||||||
|
# Submit new drink order to queue
|
||||||
|
channel.basic_publish(exchange=rmq_params['exchange'],
|
||||||
|
routing_key=rmq_params['order_queue'],
|
||||||
|
body=str(order_data))
|
||||||
|
checkpoint("Getting status for id \'{}\'".format(rfid_id))
|
||||||
|
|
||||||
|
## Wait for response from server for drink order
|
||||||
|
# Listen for reply from server
|
||||||
|
server, address = s.accept()
|
||||||
|
svr_addr = server.getpeername()[0]
|
||||||
|
svr_port = server.getpeername()[1]
|
||||||
|
checkpoint("Accepted server connection from {} on {}"
|
||||||
|
.format(svr_addr, svr_port))
|
||||||
|
|
||||||
|
# Receive data from server
|
||||||
|
recv_data = server.recv(socket_size)
|
||||||
|
recv_data = pickle.loads(recv_data)
|
||||||
|
checkpoint("Received data: {}".format(recv_data))
|
||||||
|
|
||||||
|
# Update GUI based on response
|
||||||
|
process_response(recv_data)
|
||||||
|
|
||||||
|
|
||||||
|
def update_gui(numDrinks, timeLeft):
|
||||||
|
if int(numDrinks) <= 0:
|
||||||
|
change_red()
|
||||||
|
elif int(numDrinks) == 1:
|
||||||
|
change_yellow()
|
||||||
|
else:
|
||||||
|
change_green()
|
||||||
|
v.set(numDrinks)
|
||||||
|
v1.set(timeLeft)
|
||||||
|
|
||||||
|
def change_red():
|
||||||
|
root.configure(background="red")
|
||||||
|
def change_yellow():
|
||||||
|
root.configure(background="yellow")
|
||||||
|
def change_green():
|
||||||
|
root.configure(background="green")
|
||||||
|
|
||||||
def checkpoint(message):
|
def checkpoint(message):
|
||||||
"""Prints [Checkpoint] <message>
|
"""Prints [Checkpoint] <message>
|
||||||
"""
|
"""
|
||||||
|
@ -27,8 +96,9 @@ def process_response(response):
|
||||||
"""Process response from serve & update GUI
|
"""Process response from serve & update GUI
|
||||||
"""
|
"""
|
||||||
|
|
||||||
id = response[0]
|
drinks = response[0]
|
||||||
time = response[1]
|
time = round(response[1], 2)
|
||||||
|
update_gui(str(drinks), str(time))
|
||||||
|
|
||||||
# Update GUI with color
|
# Update GUI with color
|
||||||
# TODO
|
# TODO
|
||||||
|
@ -43,11 +113,9 @@ def process_response(response):
|
||||||
channel.basic_publish(exchange=rmq_params['exchange'],
|
channel.basic_publish(exchange=rmq_params['exchange'],
|
||||||
routing_key=rmq_params['order_queue'],
|
routing_key=rmq_params['order_queue'],
|
||||||
body=str(id))
|
body=str(id))
|
||||||
|
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
def main():
|
if __name__ == "__main__":
|
||||||
"""Processes rfid scans
|
"""Processes rfid scans
|
||||||
"""
|
"""
|
||||||
parser = argparse.ArgumentParser(description='Processses arguments')
|
parser = argparse.ArgumentParser(description='Processses arguments')
|
||||||
|
@ -90,38 +158,4 @@ def main():
|
||||||
.format(socket_host, socket_port))
|
.format(socket_host, socket_port))
|
||||||
|
|
||||||
# Continuously listen for RFID ids
|
# Continuously listen for RFID ids
|
||||||
while True:
|
mainloop()
|
||||||
# TODO
|
|
||||||
print('Continuously listen for RFID ids')
|
|
||||||
# TODO
|
|
||||||
input()
|
|
||||||
|
|
||||||
rfid_id = '123456'
|
|
||||||
order_data = {'id': rfid_id, 'ip': socket_host, 'port': socket_port,
|
|
||||||
'size': socket_size}
|
|
||||||
|
|
||||||
checkpoint("Received id \'{}\'".format(rfid_id))
|
|
||||||
|
|
||||||
# Submit new drink order to queue
|
|
||||||
channel.basic_publish(exchange=rmq_params['exchange'],
|
|
||||||
routing_key=rmq_params['order_queue'],
|
|
||||||
body=str(order_data))
|
|
||||||
checkpoint("Getting status for id \'{}\'".format(rfid_id))
|
|
||||||
|
|
||||||
## Wait for response from server for drink order
|
|
||||||
# Listen for reply from server
|
|
||||||
server, address = s.accept()
|
|
||||||
svr_addr = server.getpeername()[0]
|
|
||||||
svr_port = server.getpeername()[1]
|
|
||||||
checkpoint("Accepted server connection from {} on {}"
|
|
||||||
.format(svr_addr, svr_port))
|
|
||||||
|
|
||||||
# Receive data from server
|
|
||||||
recv_data = server.recv(socket_size)
|
|
||||||
recv_data = pickle.loads(recv_data)
|
|
||||||
checkpoint("Received data: {}".format(recv_data))
|
|
||||||
|
|
||||||
# Update GUI based on response
|
|
||||||
process_response(recv_data)
|
|
||||||
|
|
||||||
main()
|
|
||||||
|
|
Loading…
Reference in New Issue