So I started out building a coffee pot capable of supporting HTCPCP. I decided to use a Raspberry Pi to run the server application. It's a bit overpowered for the task, but it's nice to have a *NIX environment to work with, and it makes updating the code very easy. The idea was to connect a relay in place of the on/off switch on an old coffee pot I had laying around.
- GPIO pin 17 connects a relay capable of switching at least 2A at 120V
- GPIO pin 21 connects to a pushbutton
- GPIO pin 22 connects to a status LED
Completed circuit board |
On the RPi I chose to install Arch Linux because this project doesn't need everything installed by default in Raspbian, and I find that NetworkManager is less flaky than wpa_supplicant alone for connecting to encrypted WiFi networks.
Once the pi was connected to the internet I installed WiringPi started working on the code for the HTCPCP server. The RFC specifies the following requests in addition to HTCP
- BREW
- WHEN
- PROPFIND
Since my pot doesn't have the capabilities to support additions yet, WHEN will return an error. Sending either BREW, POST, or GET will set GPIO 17 to high for half an hour (I can't see myself waiting any longer than that for coffee ever.) Once a BREW or synonymous request is sent,
potinfo.ready
is set to false. Once the pot is refilled with water and coffee grounds, pressing the pushbutton will set the ready status to true. Holding the button down for more than 3 seconds, the pi will power off. PROPFIND will return at any time the readiness of the pot to make coffee. The code for the HTCPCP server is available at https://github.com/saljs/htcpcp
(The
sleep(30);
is a dirty hack to make sure that the pi connects to the network fully before the server tries to claim a port.)Once I got the server working, I put the following in
/etc/systemd/system/htcpcpd.service
[Unit]
Description=Hyper Text Coffee Pot Control Protocol Server
Requires=network.target
[Service]
Type=forking
ExecStart=/usr/local/bin/htcpcpd
[Install]
WantedBy=multi-user.target
Then enabled the server. In Raspbian the same could be done by putting
/usr/local/bin/htcpcpd
on a line in /etc/rc.local
The last thing I did before assembling it all was to make the root filesystem read-only to prevent corruption. https://web.archive.org/web/20160305060007/http://ruiabreu.org/2013-06-02-booting-raspberry-pi-in-readonly.html was the guide I used.
Here are some pictures of the completed project. It was banned from the kitchen because it doesn't exactly match with the decoration, so instead I keep it by the sink in the basement. Please forgive the mess.
3d printed case for the pi+relay board |
All plugged in |
Closeup of the pi |
Coffee tastes all the better for knowing that it was brewed over my network.
No comments:
Post a Comment