The source code of both the software (python) and firmware (atmega, c) can be found on github. It autodetects architecture and can be run on a desktop computer. To make full use of it; an MPD client has to be installed (music), an NS-API token has to be available (train info), and a Dutch postal code + house number combination has to be set (waste collection info). Of course all of this is only neccesary for the home information part, not for making coffee...
The UI will work well enough without all of this. The code has been written to make sure the UI continues to work at most times, catching and mostly ignoring exceptions - because otherwise it's hard to turn the coffee machine off without SSH.
main.py, to which koffieui is a symlink, holds everything together. It loads the different modules:
- System menu (SysD)
- Train time table display (NSDisplay)
- Music player control panel (MPDisplay)
- Last but not least... the coffee maker interface (Koffiezetter)
In this log I will explain the first three of these.
The source code for the system menu resides in sysd.py. This menu is used to turn off the coffee machine, turn off the cd player computer (=music server), and to watch tv.
It shows the state of the cd player computer (aan=on, uit=off) and also shows if music is available. This is done by checking if it's possible to connect to its apache server. There are scripts to mount/unmount the samba share. I might remove this code, since currently I use snapserver/snapclient for in-sync music playing, the coffee machine not having its own mpd server anymore.
The TV, the three Dutch public channels, are streamed from npolive.nl. After the first implementation, the token authentication scheme changed. The kind people from http://downloadgemist.nl/ helped me out by telling which characters to swap in the token. All the rest I figured out using wireshark. This code is implemented in npo.php, friemelToken(). The code needs changing every once in a while when "they" change their URL or authentication scheme... After getting the stream, it's shown full screen on the coffee machine display using omxplayer.
Hidden in the code is a date/time changer, implemented when I needed to run the coffee machine off network for a while, and I still wanted correct coffee logs. Sadly, it stopped working at some point, probably because of permissions. Currently I don't need it, but the code is still there. Feel free to use it for implementing your own UI.
On the display, the next waste collection type (paper / green / plastic) is shown using an icon of the container and a number for the day count until waste collection. The web site scraping code I developed is in afvalwijzer.py.
The display looks like this:
Because I used to live very close to a train station, I liked the train time table on the machine, in exact the same way as displayed on the real displays. I used Python-API for fetching the information, and built up the display in nsdisplay.py.
It looks like this:
Finally the coffee machine is the kitchen's music player. A python fronted was written using python-mpd. All code is in mpdisplay.py. It looks like this:
The progress bars used in this UI and the coffee UI are in kwidgets.py, a progress bar library written to make easy progress bars in different colors.
Hardware abstraction layer
The hardware (buttons, temperature 'display', light, counter, and all the brewing hardware and sensors) is abstracted away in myhal.py. The pigpio library is used to access the GPIO's to which the buttons are connected. Additionally, python-smbus allows for accessing the Atmega.
To be able to test everything on a desktop, a simulation is provided in myhald.py. It is automatically selected based on the architecture.