Setting up Raspberry Pi (Stretch)


Note:  This page is largely deprecated, but I am leaving it here just in case.  To get BrewPi running now, follow these two pages:

  • Off With Her Head! – Headless Raspberry Pi setup.  You can just follow along and skip the wpa_supplicant.conf and .ssh setup if you don’t care about headless operation.
  • BrewPi Remix Install – Instructions to set up the new remix of BrewPi which supports contemporary Raspbian versions.

These instructions were created for the new Raspbian Stretch image. They assume intermediate knowledge of your chosen home computing system, as well as familiarity with using SSH and other networking tools.  These instructions assume a “headless” operation – that no monitor, keyboard, or mouse are needed.

These are the general steps I follow when preparing a new Raspberry Pi image for use with BrewPi (these are specifically deprecated. See the headless setup section in Off With Her Head! The sections below which are struck through may be skipped after following the instructions on that page.)

  • Download your new Raspbian image: https://www.raspberrypi.org/downloads/raspbian/ (get the full version if this is your first time, not the “Lite” one)
  • Install the image on your SD card:
  • While the SD Card is still connected to your computer, configure the image for headless operation:
    • Locate the /Boot/ partition on the SD Card.  In Windows this will be a new drive letter with the volume name “boot (X:)” where “X” is the new drive letter.
    • Create a new file in the root of this drive named “ssh” (no extension.)   This will enable SSH so that you can connect to the RaspberryPi immediately upon first boot.
    • Create a file called “wpa_supplicant.conf” on the root of the boot partition of the SD card.  In it, place the following information:
country=US
ctrl_interface=DIR=/var/run/wpa_supplicant
GROUP=netdev
update_config=1
network={
      ssid="SSID"
      scan_ssid=1
      psk="PASSWORD"
      key_mgmt=WPA-PSK
}

Replace “SSID” with the SSID of your local wireless network (leave it in quotes), and “PASSWORD” with your wireless network (leave it in quotes also) .  This will connect your Raspberry Pi to your wireless network automatically upon startup so double-check the SSID and password.

NOTE:  If you do not have Windows Explorer configured to show file extensions, it is possible to have a hidden “.txt” or other extension on the files.

  • Insert the SD card and boot.  Your Raspberry Pi should now be accessible on the network via PuTTY.
  • Use PuTTY to SSH to “raspberrypi.local” with the username “pi” and password “raspberry”.

NOTE:  If you receive an error stating that the host could not be found, it may be that Bonjour services are not installed on your local computer (assuming you use Windows.)  You can obtain Bonjour either by installing iTunes or with the stand-alone installer found here. Bonjour also enables accessing the BrewPi web page with  “{servername}.local” without having to apply a static IP or remember an IP address.  If you use Linux you will need libavahi; under Mac, Bonjour should be installed with the base OS.

  • Enter the command “sudo raspi-config” to execute Raspbian configuration as the root user.
  • Complete configuration:
    • Immediately “Change User Password” to a secure one.
    • Change “Hostname” (I suggest: “brewpi”, this will be assumed through all documentation on this site.)
    • “Localisation Options”
      • “Change Timezone” to proper timezone for your area.
      • “Change Wi-Fi Country” to proper country fr your area.
  • Select <Finish> and reboot.
  • After the Pi reboots, SSH to “brewpi.local” with the username “pi” and password you set previously.
  • Issue the following commands to ensure your software is up to date:
sudo apt-get update && sudo apt-get upgrade -y
  • Issue the following commands to clean local repositories, deleting space used by downloaded archives:
sudo apt-get clean && sudo apt-get autoclean
  • Issue the following command to update the firmware of your Raspberry Pi:
sudo PRUNE_MODULES=1 RPI_REBOOT=1 rpi-update

If the command updated your firmware it will reboot automatically. If not; go ahead and reboot anyway with:

sudo reboot

That’s it!

Add Reboot and Shutdown Buttons

Note: I do not recommend this approach. It requires granting higher than typical permissions to a user which is generally very limited.

Concept originally posted by “MBasile” at: https://www.homebrewtalk.com/showpost.php?p=7989560&postcount=6999

As you know or will soon learn, the Raspberry Pi does not deal well with being powered off without first being shut down.  These minor changes will give you the ability to reboot or shutdown your Raspberry Pi through the BrewPi web interface rather than needing to ssh in.

  1. Grant access to the web user to perform shutdown and reboots:
    sudo sh -c "echo \"www-data ALL=NOPASSWD: /sbin/reboot, /sbin/shutdown\" >> /etc/sudoers"
  2. Create two new PHP pages which will perform the shutdown and reboot functions:
    sudo echo "<?php system('sudo /sbin/reboot'); ?>" > "/var/www/html/reboot.php"
    sudo chmod 674 /var/www/html/reboot.php
    sudo chown www-data:www-data /var/www/html/reboot.php
    
    sudo echo "<?php system('sudo /sbin/shutdown -h now'); ?>" > "/var/www/html/shutdown.php"
    sudo chmod 674 /var/www/html/shutdown.php
    sudo chown www-data:www-data /var/www/html/shutdown.php
  3. Add the buttons to the Maintenance Panel (maintenance-panel.php) file:
    • At line 66 you will see this:
      <li><a href="#reprogram-arduino"><span>Reprogram <span class="boardMoniker">controller</span></span></a></li>

      Below that line add this:

      <li><a href="#shutdown"><span>Shutdown</span></a></li>
    • Append this block to the end of the file:
      <div id="shutdown">
       <script type="text/javascript">
       function shutdownonclick()
       {
       shutdown_window = window.open("shutdown.php",
       "shutdown_window","status=1,width=350,height=150");
       setTimeout("shutdown_window.close()", 2000);
       }
      
       function rebootonclick()
       {
       reboot_window = window.open("reboot.php",
       "reboot_window","status=1,width=350,height=150");
       setTimeout("reboot_window.close()", 2000);
       }
       </script>
       <button><a href="javascript: shutdownonclick()">Shutdown</a></button>
       <br>
       <br>
       <button><a href="javascript: rebootonclick()">Reboot</a></button>
      </div>
  4. Test.

New Install under Raspbian Jessie or Stretch

(This article is being re-written for BrewPi Legacy Remix.  Expect an update within a week or so – LCB on 1/9/19)

This will detail step by step instructions for installing BrewPi for an Arduino Uno.  We start with a clean Jessie or Stretch install, prepped according to my previous articles.

  1. Install Arduino Core as root:
    sudo apt-get install arduino-core -y
  2. Clone the BrewPi tools into your home directory:
    git clone https://github.com/BrewPi/brewpi-tools.git ~/brewpi-tools
  3. Execute the install script as root:
    sudo ~/brewpi-tools/install.sh
  4. When prompted, install to /home/brewpi.
  5. When prompted, copy the BrewPi web files to /var/www/html.  The script will warn you that the directory is not empty, this is normal and ok to proceed.
  6. Accept all prompts for crontab entries.
  7. When complete, change password for brewpi:
    sudo passwd brewpi
  8. Run the updater script to change the installation back to the Legacy branch for Arduino support:
    sudo ~/brewpi-tools/updater.py --ask
  9. When prompted, select [1] Legacy for the branch you wish to update.
  10. Select [Y] to update even though it is not your current branch.
  11. When prompted, select [3] Legacy for the branch you wish to update.
  12. Select [Y] to update even though it is not your current branch.
  13. When prompted to install firmware on your controller, ensure the Arduino is plugged into your Raspberry Pi’s USB port and select [Y].
  14. If you are prompted about whether your controller is unresponsive, select [Y].
  15. If you are prompted to restore settings or devices select [N].
  16. When prompted for the release to install, select [0] 0.2.10.
  17. Change “KeepAliveTimeout 5” to “KeepAliveTimeout 99” in /etc/apache2/apache2.conf (command is a single line):
    sudo sed -i -e 's/KeepAliveTimeout 5/KeepAliveTimeout 99/g' /etc/apache2/apache2.conf
    
    sudo service apache2 restart

Arduino setup is complete.  Browse to your BrewPi with your web browser and follow instructions for device configuration.

Setting up Raspberry Pi

These are the general steps I follow when preparing a new Raspberry Pi image for use with BrewPi:

  1. Download your new Raspbian image: https://www.raspberrypi.org/downloads/raspbian/ (get the full version, not the “Lite” one)
  2. Install the image on your SD card:
  3. Insert the SD card, connect keyboard, mouse, monitor, and boot to graphical desktop. (1)
  4. Set up Wireless LAN:
    • Click on Wireless graphic in top-right taskbar
    • Select your network by name
    • Enter your pre-shared key
  5. Complete configuration:
    • Select Menu > Preferences > Raspberry Pi Configuration
      • System Tab
        • Expand Filesystem, Do Not Reboot (2)
        • Change Password
        • Change Host name (suggest: BrewPi)
      • Localization Tab
        • Set Locale (Assuming a US user:)
          • Language: en (English)
          • Country: US (USA)
          • Character Set: UTF-8
        • Set Timezone (Change zone to proper one for your area:)
          • Area: America
          • Location: Chicago
        • Set WiFi Country (Assuming a US user:)
          • Country: US United States
      • Select OK and reboot

After the Pi reboots, open a terminal window:

  1. Issue the following commands to ensure your software is up to date:
    sudo apt-get update
    
    sudo apt-get upgrade -y
  2. Install support for Microsoft Terminal Server Client connections*:
    sudo apt-get install xrdp
  3. Issue the following commands to clean local repositories, deleting space used by downloaded archives:
    sudo apt-get clean
    
    sudo apt-get autoclean
  4. Issue the following command to update the firmware of your Raspberry Pi:
    sudo PRUNE_MODULES=1 rpi-update
  5. Menu > Shutdown > Reboot; or:
    sudo reboot

Your Raspberry Pi should now be accessible on the network via PuTTY and with Microsoft Terminal Server Client (mstsc) as “{servername}.local”.   To validate name resolution, open a command prompt on another computer on the network and type:

ping {servername}.local

You should see something like:

C:\>ping brewpi.local

Pinging brewpi.local [192.168.1.110] with 32 bytes of data:
Reply from 192.168.1.110: bytes=32 time=418ms TTL=64
Reply from 192.168.1.110: bytes=32 time=197ms TTL=64
Reply from 192.168.1.110: bytes=32 time=27ms TTL=64
Reply from 192.168.1.110: bytes=32 time=681ms TTL=64

Ping statistics for 192.168.1.110:
 Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
 Minimum = 27ms, Maximum = 681ms, Average = 330ms

If you receive an error stating that the host could not be found, it may be that Bonjour services is not installed on your local computer assuming you use Windows.  You can obtain Bonjour either by installing iTunes, or with the stand alone installer found here. Bonjour also enables accessing the BrewPi web page with  “{servername}.local” without having to apply a static IP or remember an IP address.  If you use Linux you will need libavahi; under Mac, Bonjour should be installed with the base OS.

RDP Errors

There is a new desktop interface called “Pixel” released with the latest Jessie, dated 2016-09-23. There is a bug between this and xrdp which a lot of us use to connect to our Raspberry Pi’s desktop with Microsoft Terminal Server Client (mstsc). It will connect to the familiar X window and hang, displaying something like this:

connecting to sesman ip 127.0.0.1 port 3350
sesman connect ok
sending login info to sesman
login successful for display 10
started connecting connecting to 127.0.0.1 5910
error - problem connecting

If you press “ok” it will present you with a credentials prompt and if you re-enter credentials it will give the same error.

To fix this, issue the following commands:

sudo apt-get --purge remove xrdp
sudo apt-get --purge realvnc-vnc-server

sudo apt-get install tightvncserver tightvnc-java
sudo apt-get install xrdp
sudo reboot

 Notes:

    1. A “headless” install is now possible.  Previously one needed to boot the Raspberry Pi in order to connect to wireless networking.   This is no longer necessary.  To do this, perform the following two steps while the SD card is mounted after flashing the boot image:
      • Create a file called “ssh” (without any extension) on the root of the boot partition of the SD card.  This allows SSH to work on first boot, circumventing new behavior in Raspbian which disables SSH by default.
      • Create a file called “wpa_supplicant.conf” on the root of the boot partition of the SD card.  In it, place the following information:
        country=US
        ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
        update_config=1
        
        network={
            ssid="SSID"
            scan_ssid=1
            psk="PASSWORD"
            key_mgmt=WPA-PSK
        }

        Replace “SSID” with the SSID of your local wireless network, and “PASSWORD” with your wireless network password.

  1. Raspbian will now automatically expand to use all of the available space on the SD card during the initial boot.

BrewPi on Windows under WAMP

BrewPi was developed to run under Rasperry Pi.  As such, tools and supporting libraries were developed to run optimally underneath that platform.  It can be made to run under Windows for testing, however you will find that there are certain compromises at times, and things may not be as polished on Windows as they are on Rasperry Pi.  That’s not to say some amount of customization may not be possible.

This list of steps will cover the bare minimum necessary to enable BrewPi on Windows with an Arduino.  Further “polish” is left to the reader.  Certain assumptions about the reader’s abilities are made such as the ability to navigate the command line and install software to other than standard locations.

  1. Install Arduino to C:\Arduino: https://www.arduino.cc/en/Main/Donate (needed for flashing Arduino only)
  2. Install Python 2.7.x: https://www.python.org/downloads/release/python-2712/
  3. Add Python to path (e.g. C:\Python27)
  4. Upgrade pip:
    python -m pip install --upgrade pip
  5. Install support libraries in Python
    python -m pip install pyserial
    python -m pip install configobj
    python -m pip install simplejson
    python -m pip install psutil
    python -m pip install pygit
  6. Install Visual C++ Support files below for WAMP.  Note:  If you have a 64-bit Windows, you must install both 32 and 64bit versions, even if you do not use Wampserver 64 bit.  This is item number 20 of TROUBLESHOOTING TIPS of Wampserver: http://forum.wampserver.com/read.php?2,134915
  7. Install WAMP:  http://www.wampserver.com/en/
  8. Install git for Windows:  https://git-scm.com/download/win
  9. Clone BrewPi website:
    git clone https://github.com/BrewPi/brewpi-www C:\wamp64\www\brewpi
    cd c:\wamp64\www\brewpi
    git checkout legacy
    git pull
  10. Create virtual host within WAMP for brewpi
  11. Download BrewPi scripts:
    git clone https://github.com/BrewPi/brewpi-script c:\brewpi
    cd c:\brewpi
    git checkout legacy
    git pull
  12. Copy c:\brewpi\settings\config.cfg.example to c:\brewpi\settings\config.cfg
  13. Edit c:\brewpi\settings\config.cfg
    # ======= settings above this line have been added automatically =======
    # uncomment settings here, these override the settings in defaults.cfg
    # scriptPath = /home/brewpi/
    wwwPath = C:\wamp64\www\brewpi
    port = COM3
    # altport = /dev/ttyACM1
    # boardType = leonardo
    # startupDelay = 1.0
    # debug = true
    
    # On a standard pi installation, the defaults should work.
    # If you are using a different linux flavor or Windows, you can set the tool locations here
    arduinoHome = C:\Arduino\
    avrdudeHome = C:\Arduino\hardware\tools\avr\bin
    avrsizeHome = C:\Arduino\hardware\tools\avr\bin
    avrConf = C:\Arduino\hardware\tools\avr\etc
    
    # on Windows, the scripts defaults to an Internet socket instead of a system socket.
    # useInetSocket=true
    # socketPort=6332
    # socketHost=127.0.0.1
  14. Copy C:\wamp64\www\brewpi\config_user.php.example to C:\wamp64\www\brewpi\config_user.php
  15. Edit C:\wamp64\www\brewpi\config_user.php:
     $scriptPath = 'c:\brewpi';
  16. Download proper 0.2.10 firmware (Uno, Leonardo, Spark): https://github.com/BrewPi/firmware/releases
  17. Execute c:\brewpi\start.bat
  18. Add a virtual host in WAMP pointing to brewpi and restart WAMP.
  19. Open a web browser:  http://brewpi

At this point, an Arduino with BrewPi firmware will communicate with the script provided the COM port is correctly configured in c:\brewpi\settings\config.cfg.  I was unable to upload the firmware with the maintenance panel tool.  Two options are:

  • XLoader:  http://russemotto.com/xloader/
  • AVRDude: Part of the Arduino software.  Command line I used (single line):
    bin\avrdude -U flash:w:brewpi-arduino-uno-revC-0_2_10.hex:i -C etc\avrdude.conf -v -p atmega328p -b 115200 -c arduino -P COM3