Friday, March 20, 2015

Hyper Text Coffe Pot Protocol - My functional implementation of RFC2324

On April 1st 1998 the IETF published RFC2324, a protocol for controlling, monitoring, and diagnosing coffee pots. Even though it was a joke, I could see a real need for implementing this. Finally the making of coffee could be could be added to cron jobs and makefiles. When gcc spat out more than 50 errors it could automatically start making the coffee that you'll be needing. You could add a BREW request to anything that makes that takes a very long time to run. Simply put, this a thing that really needed to be real.

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
 BREW specifies that coffee should be brewed, and is synonymous with POST. PROPFIND returns metadata about the pot, and WHEN is sent when the server has added enough of an addition to the coffee (sugar, cream, rum, etc.)

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.


Yet Another Teenager's Tech Blog

I've decided to start a personal blog as a place to keep a collection of  project write ups, my fixes for odd undocumented problems I run across (mostly on Arch Linux and Debian), and hardware hacks. I find a lot of answers to tech related problems on blogs, so I figure a blog of my own would be a good repository for these sort of things as well. I'm writing it mostly for myself, but if anyone finds it useful then that's great!