#!env/bin/python3

import argparse
import asyncio
import json
import socket
import websockets

import teensy
import messages

async def contact_server():
    async with websockets.connect(server) as sock:
        await sock.send(json.dumps(dict(
            message='Hello',
            name=name,
            id=None, # In theory we would provide a unique ID for each machine, but we only have one...
        )))

        resp = await sock.recv()
        # Handle new response
        print(json.loads(resp))


def main():
    asyncio.get_event_loop().run_until_complete(contact_server())

if __name__ == "__main__":
    parser = argparse.ArgumentParser(description='Client for connecting to AWS')
    parser.add_argument('server', help='The server to connect to')
    parser.add_argument(
        '-n', '--name', default=socket.gethostname(),
        help='The name of this client coffee machine'
    )

    args = parser.parse_args()
    server = args.server
    name = args.name

    main()

@@ -144,16 +144,42 @@
 _server(
+server, name, coffee_queue
 ):%0A    a
@@ -534,85 +534,667 @@
 ))%0A%0A
-%0Adef main():%0A    asyncio.get_event_loop().run_until_complete(contact_server()
+        # TODO: Actually get real orders...%0A        coffee_queue.put_nowait(messages.DrinkOrder(8, %7B'sugar': 2%7D, 'coffee'))%0A%0Aasync def serial_consumer(serial_device_name, coffee_queue, mock=False):%0A    with teensy.Interface(serial_device_name, mock=mock) as interface:%0A        while True:%0A            order = await coffee_queue.get()%0A%0A            # TODO: Process order...%0A%0Adef main(args):%0A    loop = asyncio.get_event_loop()%0A    coffee_queue = asyncio.Queue(loop=loop)%0A    loop.run_until_complete(asyncio.gather(%0A        contact_server(args.server, args.name, coffee_queue),%0A        serial_consumer(args.serial, coffee_queue, mock=args.mock)))%0A    loop.close(
 )%0A%0Ai
@@ -1510,27 +1510,19 @@
   )%0A
-%0A
    
- args =
  parser.
 pars
@@ -1521,75 +1521,284 @@
 ser.
-parse_args()%0A    server = args.server%0A    name = args.name%0A%0A    main(
+add_argument('-s', '--serial', default=None,%0A            help='The serial device to use, or the first one detected')%0A    parser.add_argument('-S', '--mock', action='store_true',%0A            help='Mock the socket device instead of using a real one')%0A%0A    main(parser.parse_args()
 )%0A

Add drink order passing in Raspberry Pi code