Merge branch 'master' of github.com:paulwalko/bac_monitoring_system

master
Paul Walko 2018-05-07 14:37:57 +00:00
commit 6b301b0245
1 changed files with 75 additions and 41 deletions

116
client.py
View File

@ -9,6 +9,75 @@ import pika
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):
"""Prints [Checkpoint] <message>
"""
@ -27,8 +96,9 @@ def process_response(response):
"""Process response from serve & update GUI
"""
id = response[0]
time = response[1]
drinks = response[0]
time = round(response[1], 2)
update_gui(str(drinks), str(time))
# Update GUI with color
# TODO
@ -39,15 +109,13 @@ def process_response(response):
# TODO
reject = False
checkpoint("Drink rejected? \'{}\'".format(reject))
if reject:
if reject:
channel.basic_publish(exchange=rmq_params['exchange'],
routing_key=rmq_params['order_queue'],
body=str(id))
return
def main():
if __name__ == "__main__":
"""Processes rfid scans
"""
parser = argparse.ArgumentParser(description='Processses arguments')
@ -90,38 +158,4 @@ def main():
.format(socket_host, socket_port))
# Continuously listen for RFID ids
while True:
# 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()
mainloop()