IEEE uOttawa Vending Machine controller using Pi 4
The Versatile Electronic Nutrient Dispenser (VEND) runs on the BrotherLaserPrinter(BLP) network, which we think is a subnet of the subnet of eduroam that SITE is on (this should be verified). We enabled port forwarding on the BLP router for port 22, which enables us to SSH into the VEND without needing to be on the BLP network. However this does not work on any outside network.
To address this limitation, we set up a VPN Tailscale. Tailscale allows us to create a secure, private network between our devices and the VEND, regardless of which external network we are on. Each participating device, including the VEND, is connected to the same Tailscale tailnet, giving them unique IPv4 addresses within a shared virtual network. This setup removes the need for manual port forwarding. SSH access to the VEND is now possible from any device authenticated on the Tailscale network, of which the admin account is the Webmaster account.
The VEND works by leveraging Square Webhooks and the Sqaure API (for now). We run an HTTP server that receives the Webhooks when a payment for an item on our Square Store is fulfilled, then uses the Square API to get the information on which item was purchased and checks its custom attributes which contain the slot in the VEND where the item is located. It then dispenses the item. For the Square Webhooks to be able to reach the VEND, we need to expose a public domain to the internet. We do this using NGROK, which creates a free temporary domain which forwards traffic to the local port that we choose.
- Whenever NGROK is restarted, the domain changes. This needs to also be reflected in the Square Developer Dashboard's Webhooks configuration, or else it will send the Webhooks to nothing.
- Sometimes the SSH connection disconnects but the server and ngrok are still running so you can't re-run them to get their GUI back. Run this command to kill them
pkill -f "go run ."; pkill -f "ngrok http 8000"; lsof -ti :8000 | xargs -r kill -9
- Log into the Square Developer Console
- Navigate to Sandbox test accounts
- Go to Docs & Tools in the navbar and open API Explorer in another tab
- Open Square Dashboard for Default Test Account
- In the Dashboard, go to Items & Services in the sidebar, Item Library and create an item
- Give the item a name and a price and MOST IMPORTANTLY in the Stock section there is a dropdown called VendingMachineSlot(Square) which you need to assign one of the slots to the item.
- Save the item
- In the API Explorer, choose the Orders API
- Go to Create order
- Fill in the Access token, generate an idempotency key, fill the location_id, quantity
- In the line_items[0] section, enter a quantity, in the catalog_object_id dropdown choose the ITEM_VARIATION_REGULAR option and choose item_type as ITEM
- Choose the state as OPEN
- Run the request and copy the order_id
- Choose the Payments API
- Go to Create payment
- Generate idempotency_key
- Put the source_id as cnon:card-nonce-ok
- Put accept_partial_authorization as False
- In amount_money, set the amount to anything higher than the item cost and the currency to CAD
- Set autocomplete to true
- Set the buyer_email_address to your email address
- Set the delay_duration to P1W3d
- Set the order_id to the one you copied earlier
- Run the request
- Open a terminal or preferably VS Code
- Enter the password
- Open a terminal or preferably VS Code
- Enter the password
- Ask the current Webmaster to send you an invite link to be a member in the VEND tailnet
- Follow the steps to join the tailnet and make sure with the Webmaster that your device is added to the network
- You will now be able to SSH into the VEND from anywhere using the Tailscale IP address
ssh [email protected] #change when new Webmaster Tailscale is set up- Open a terminal
-
cd /home/ieeepi/dev/vending-machine/python-server -
python3 dispense.py
- Open another terminal
-
ngrok http 8000
-
Open a terminal
cd /home/ieeepi/dev/vending-machine -
Start the server
make server ./vm-server
-
Open another terminal
-
ngrok http 8000
ps aux | grep go
sudo lsof -i :8080 cd /home/ieeepi/dev/vending-machine
make tui
./vm-tuicat /etc/systemd/system/vm-server.service
cat /etc/systemd/system/ngrok-tunnel.servicejournalctl -u vm-server -f
journalctl -u ngrok-tunnel -f