https://github.com/ieee-uottawa/vending-machine
Repository for all things site4026 vending machine related.
https://github.com/ieee-uottawa/vending-machine
bash docker golang python
Last synced: about 2 months ago
JSON representation
Repository for all things site4026 vending machine related.
- Host: GitHub
- URL: https://github.com/ieee-uottawa/vending-machine
- Owner: ieee-uottawa
- Created: 2025-09-05T21:55:15.000Z (10 months ago)
- Default Branch: main
- Last Pushed: 2025-10-02T17:54:52.000Z (9 months ago)
- Last Synced: 2025-10-02T18:37:10.711Z (9 months ago)
- Topics: bash, docker, golang, python
- Language: Go
- Homepage:
- Size: 34.2 KB
- Stars: 1
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# IEEEuO-Machine-Controller
IEEE uOttawa Vending Machine controller using Pi 4
# Context
## Network
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.
## Implementation
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.
### Known Issues
- 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`
# Testing
## With the Square API
1. Log into the Square Developer Console
2. Navigate to Sandbox test accounts
3. Go to Docs & Tools in the navbar and open API Explorer in another tab
4. Open Square Dashboard for Default Test Account
5. In the Dashboard, go to Items & Services in the sidebar, Item Library and create an item
6. 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.
7. Save the item
8. In the API Explorer, choose the Orders API
9. Go to Create order
10. Fill in the Access token, generate an idempotency key, fill the location_id, quantity
11. 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
12. Choose the state as OPEN
13. Run the request and copy the order_id
14. Choose the Payments API
15. Go to Create payment
16. Generate idempotency_key
17. Put the source_id as cnon:card-nonce-ok
18. Put accept_partial_authorization as False
19. In amount_money, set the amount to anything higher than the item cost and the currency to CAD
20. Set autocomplete to true
21. Set the buyer_email_address to your email address
22. Set the delay_duration to P1W3d
23. Set the order_id to the one you copied earlier
24. Run the request
# SSHing into the Pi
## From the BrotherLaserPrinter network
1. Open a terminal or preferably VS Code
2. ```bash
ssh ieeepi@192.168.1.102
```
3. Enter the password
## From the eduroam network (in the office only for now, need to test elsewhere)
1. Open a terminal or preferably VS Code
2. ```bash
ssh ieeepi@10.136.193.96
```
3. Enter the password
## From the VEND tailnet
1. Ask the current Webmaster to send you an invite link to be a member in the VEND tailnet
2. Follow the steps to join the tailnet and make sure with the Webmaster that your device is added to the network
3. You will now be able to SSH into the VEND from anywhere using the Tailscale IP address
```bash
ssh ieeepi@100.87.253.43 #change when new Webmaster Tailscale is set up
```
# Running the server
## Python Server
1. Open a terminal
2. ```bash
cd /home/ieeepi/dev/vending-machine/python-server
```
3. ```bash
python3 dispense.py
```
4. Open another terminal
5. ```bash
ngrok http 8000
```
## Go Server
1. Open a terminal
```bash
cd /home/ieeepi/dev/vending-machine
```
2. Start the server
```bash
make server
./vm-server
```
3. Open another terminal
4. ```bash
ngrok http 8000
```
## To check if it's already running
```bash
ps aux | grep go
sudo lsof -i :8080
```
## TUI
```bash
cd /home/ieeepi/dev/vending-machine
make tui
./vm-tui
```
## System CTL (auto start on boot) files
```bash
cat /etc/systemd/system/vm-server.service
cat /etc/systemd/system/ngrok-tunnel.service
```
## Logs on PI
```bash
journalctl -u vm-server -f
journalctl -u ngrok-tunnel -f
```