nebhead / PiTender

Raspberry Pi Smart Bartender
MIT License
13 stars 3 forks source link

Icon PiTender

Raspberry Pi based Automatic Bartender using Python and Flask/Gunicorn/nginx

Also uses Bootstrap 4 (http://getbootstrap.com/) w/jQuery

Note: This project is continuously evolving, and thus this readme will likely be improved over time, as I find the inspiration to make adjustments. That being said, I'm sure there will be many errors that I have overlooked or sections that I haven't updated.

This project was inspired by the Hacker Shack and their excellent smart bartender project (https://www.hackster.io/hackershack/smart-bartender-5c430e). I encourage you to check it out and get a rough idea of how this all works.

This version of the bartender script is a complete re-write using a flask web interface, such that we can use a smart phone, computer, or tablet to control your bartender. I've removed the OLED screen and manual buttons, and have only left the relays and pumps (and have added a couple more pumps if you so desire).

I'm using Gunicorn and nginx to proxy web requests. This is simple enough to configure and setup, however I had to redesign the application without the threading libraries, due to conflicts with Gunicorn. Instead, I am using two processes running concurrently (control.py and app.py). Control handles all of the RasPi GPIO interfaces, while App handles the web routes. They communicate through a series of json files.

Update 2020/12

Happy Holidays! Well, it's time for a little bit of an overhaul of this project. Here are some of the changes that are part of this update:

Note: This project hasn't been fully tested on real working hardware and your mileage may vary. Please do submit issues here if you find any and I will try to get to it when I can.

Screenshots

Here is a screenshot of the dashboard:

Dashboard

Screenshot of the PiTender working:

Working

Here is a screenshot of the recipe builder: Recipe Builder

Screenshot of the ingredients editor: Recipe Builder

Here is a screenshot of the settings screen: Settings

Hardware Configuration

The Parts List

The parts list and setup of this was heavily borrowed from the following guide here: (https://www.hackster.io/hackershack/smart-bartender-5c430e)

Hardware Setup

Below is the schematic borrowed from the Hackster.io site. This is the same basic design that we will be using for the PiTender project, however the display, the LED strip and the buttons are removed from this design.

Instead of these, we will use a Web based user interface that can be used via a local display (attached to the Raspberry Pi), a tablet, smartphone or PC with a web browser.

Schematic

Raspberry Pi GPIO Mapping

Relay Control (defined in settings.json):

Should be configured from the WebUI (Settings Screen). You can easily select what pumps are connected to GPIO pins, thus there isn't really a need to lock down specific GPIO's for the project. Use what is most convenient for you, or follow the Hackster.io implementation.

Software Installation

Raspberry Pi Zero Setup Headless (from raspberrypi.org)

Once you've burned/etched the Raspberry Pi OS image onto the microSD card, connect the card to your working PC and you'll see the card being mounted as "boot". Inside this "boot" directory, you need to make 2 new files. You can create the files using a text editor of your choice.

country=US
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1

network={
    ssid="your_real_wifi_ssid"
    scan_ssid=1
    psk="your_real_password"
    key_mgmt=WPA-PSK
}

Run RasPi-Config

ssh pi@192.168.1.xxx

sudo raspi-config

Automatic Software Installation (Recommended)

I've created a script to install PiTender automatically. If you run into any issues, you can simply retry in the installation or try the manual steps below.

After you've done the above steps to configure your raspberry pi, at the command line type the following:

curl https://raw.githubusercontent.com/nebhead/pitender/master/auto-install/install.sh | bash

OR if that doesn't seem to work for you, try:

wget https://raw.githubusercontent.com/nebhead/pitender/master/auto-install/install.sh
bash install.sh

NOTE: Do not use SUDO with the above commands. The installation script will obtain sudo privledges automatically.

Follow the onscreen prompts to complete the installation. At the end of the script it will reboot, so just be aware of this.

Using The App

If you've configured the supervisord correctly, the application scripts should run upon a reboot. Once the system is up and running, you should be able to access the WebUI via a browser on your smart phone, tablet or PC device.

Simply navigate to the IP address of your device for example (you can usually find the IP address of your device from looking at your router's configuration/status pages). My router typically assigns IPs with prefixes of 192.168.1.XXX. I'll use examples on my home network here, so you'll see URLs like: http://192.168.1.42 Yours may look different depending on your routers firmware/manufacturer (i.e. 10.10.0.XXX, etc.)

Note: It's highly recommended to set a static IP for your Pi in your router's configuration. This will vary from manufacturer to manufacturer and is not covered in this guide. A static IP ensures that you will be able to access your device reliably, without having to check your router for a new IP every so often.

The interface / webui is broken out into three main pages. The first is the dashboard view where you can select your drinks that you want to dispense. Scroll through options moving left to right. Once you've made your selection, tap the "Make Drink" button.

NOTE: PiTender is smart enough to know what ingredients you have attached and only displays the drinks that are possible with those ingredients. The drink_db is expandable, but you are really only limited by what ingredients are attached to your pumps.

Dashboard

Pressing the hamburger icon in the upper right of the interface, allows you to also access to the administration/settings screen. This interface allows you to configure the pump GPIO assignments and the different drinks attached to each pump.

Admin & Settings

Scrolling down further gives you the option to reboot the system or shutdown the system. Below these controls, you'll see more information about the system hardware, and the uptime.

Admin & Settings

Lastly, there is a Recipe Builder that gives you the ability to add more ingredients and drinks to the database. The ingredient table provides the option to edit existing ingredients (either the unique ingredient ID or the display name for each ingredient). NOTE: Ingredient IDs must only contain lowercase and alphanumeric characters. No spaces, or special characters are allowed. PiTender will attempt to fixup the IDs if you entered something incorrectly.

Admin & Settings

You can also Edit or Add your recipes on this page by selecting either Add or Edit an existing recipe. Most of this is pretty self explanitory. Each field has a save button so that you can save changes to the recipe directly. When adding a new recipe, don't forget to create a unique recipe ID. Similar to the ingredients, this ID must be a lowercase, alphanumeric word without spaces or special characters. PiTender will try to fix this up if you don't enter this in correctly.

Admin & Settings

A Note on Cleaning

After you use the bartender, you'll want to flush out the pump tubes in order to avoid bacteria growth. There is an easy way to do this in the settings menu. Hook all the tubes up to a water source, then navigate to Settings->Cleaning, select the pump to clean or clean all pumps, then touch Start Cleaning. All pumps will turn on to flush the existing liquid from the tubes. It is recommended to take the tubes out of the water source halfway through to remove all liquid from the pumps. Note: make sure you have a glass under the funnel to catch the flushed out liquid.

Adding the Web-App to your Homescreen using Chrome on your Android Phone

If you are an Android person, you are likely to be using Chrome on your phone and can not only setup a link to the web-app on your homescreen, but it also makes the interface look like a native application. Pretty cool right? Well here's how you set this up, it's very simple.

First, navigate to the instance of the application in your Chrome browser on your phone. Remember, it's as easy as going to the IP address that was assigned to you device. Then, from the Chrome drop-down menu in the upper right of the screen, select "Add to Home screen".

Add to Home screen in Chrome

Then, when the new dialog box pops up, you will have the opportunity to rename the application, or keep the default.

Rename the application

Approve the shortcut icon.

Approve Shortcut

And there you have it, you've not only created a quick link to your web-app, but you've also created a pseudo application at the same time.

Additional Notes on Accessing the Application from Outside your Local Network

Please take the utmost care in considering options for exposing this application outside of your home network. Given that this application has very limited security built-in, anyone that is able to gain access to it directly or indirectly, may be able to control your hardware which could result in damage to your property or even potentially physical harm to someone nearby.

If you want to have access to this application outside of your home network, and I haven't already convinced you not to do this, then I would recommend setting up a VPN for your local network. This would allow you to tunnel to your home network and access all of your local equipment with some level of security. A good, low cost, and dead simple VPN project I would recommend is PiVPN.

Credits

Web Application created by Ben Parmeter, copyright 2020. Check out my other projects on github. If you enjoy this software and feel the need to donate a cup of coffee, a frosty beer or a bottle of wine to the developer you can click here.

Of course, none of this project would be available without the wonderful and amazing folks below. If I forgot anyone please don't hesitate to let me know.

Licensing

This project is licensed under the MIT license.

MIT License

Copyright (c) 2020 Ben Parmeter

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.