updated to include gui

master^2
Celine Stewart 2018-05-06 19:14:53 -04:00
parent 26c3217275
commit 4d75aad55b
1 changed files with 62 additions and 41 deletions

103
client.py
View File

@ -9,6 +9,62 @@ 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):
v.set(numDrinks)
v1.set(timeLeft)
def checkpoint(message): def checkpoint(message):
"""Prints [Checkpoint] <message> """Prints [Checkpoint] <message>
""" """
@ -27,8 +83,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
@ -39,15 +96,13 @@ def process_response(response):
# TODO # TODO
reject = False reject = False
checkpoint("Drink rejected? \'{}\'".format(reject)) checkpoint("Drink rejected? \'{}\'".format(reject))
if reject: if reject:
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 +145,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()