diff --git a/README.md b/README.txt similarity index 73% rename from README.md rename to README.txt index 9e1b85c..b16f307 100644 --- a/README.md +++ b/README.txt @@ -2,4 +2,4 @@ Our system monitors and restricts students from over drinking when they are downtown. # Libraries -pymongo==3.0.3 **Newer versions don't work** +pymongo==3.5.1 **Newer versions don't work** diff --git a/client.py b/client.py new file mode 100755 index 0000000..c7c1084 --- /dev/null +++ b/client.py @@ -0,0 +1,85 @@ +#!/usr/bin/env python + +import argparse + +import pika + +from rmq_params import rmq_params + +def checkpoint(message): + """Prints [CHeckpoint] + """ + print("[Checkpoint] {}".format(message)) + +def process_response(response): + """Process response from serve & update GUI + """ + # Update GUI with color + # TODO + checkpoint("Update GUI with color \'{}\'".format(color)) + + # Wait a few seconds for a possible reject + # TODO + checkpoint("Drink rejected? \'{}\'".format(reject)) + + return + +def main(): + """Processes rfid scans + """ + parser = argparse.ArgumentParser(description='Processses arguments') + parse.add_argument('-s', help='Set server IP or hostname', required=True) + parse.add_argument('-p', help='Set server Port to receive messages on', + default=8080) + parse.add_argument('-z', help='Set size for socket to recive messages', + default=1024) + + # Process args + args = parser.parse_args() + server_host = args.s + server_port = args.p + server_size = args.z + + # Setup RabbitMQ + credentials = pika.PlainCredentials(rmq_params['username'], + rmq_params['password']) + parameters = pika.ConnectionParameters(host=rmq_host, + virtual_host=rmq_paras['vhost'], + credentials=credentials) + + # Connect to RabbitMQ + connection = pika.BlockingConnection(parameters) + channel = connection.channel() + + # Bind to order queue + channel.queue_bind(exchange=rmq_params['exchange'], + queue=rmq_params['order_queue']) + + # Continuously listen for RFID ids + while True: + # TODO + print('Continuously listen for RFID ids') + # TODO + rfid_id = '123456' + + 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=rfid_id) + checkpoint("Getting status for id \'{}\'".format(rfid_id)) + + # Wait for response from server for drink order + try: + s = socket.socket(AF_INET, socket.SOCK_STREAM) + s.connect((server_host, server_port)) + recv_data = s.recv(server_size) + s.close() + process_response(recv_data) + + # Error receiving message + except Exception as ex: + print(ex) + +main() diff --git a/rmq_params.py b/rmq_params.py new file mode 100644 index 0000000..5f939ca --- /dev/null +++ b/rmq_params.py @@ -0,0 +1,9 @@ +#!/usr/bin/env python3 + +# Things used to establish a connection with the RMQ Server + +rmq_params = {'vhost': 'my_vhost', + 'username': 'user', + 'password': 'pass', + 'exchange': 'my_exchange', + 'order_queue': 'my_order_queue'} diff --git a/server.py b/server.py index b4ef797..c38e0b3 100755 --- a/server.py +++ b/server.py @@ -102,6 +102,14 @@ def allowed_drinks(id): return drinks_left def main(): + """Create & start 'drinks' queue for submitting drinks + """ + + # Create order queue + # TODO + + # Start consuming drink queue + # TODO # Arguments id = 123456