Skip to content
This repository has been archived by the owner on Nov 8, 2024. It is now read-only.

software.raspberrypi

Pascal de Sélys edited this page Dec 28, 2018 · 28 revisions

Raspberry pi

Prerequisites

Configure raspbian

Change options in raspi-config

pi@raspberrypi:~ $ sudo raspi-config

Select "Interfacing" options and enable:

  • I2C
  • SSH

Select "Update" for update OS

Installation

Save you sd card 😏 use log2ram (1)

pi@raspberrypi:~ $ curl -Lo log2ram.tar.gz https://github.com/azlux/log2ram/archive/master.tar.gz
pi@raspberrypi:~ $ tar xf log2ram.tar.gz
pi@raspberrypi:~ $ cd log2ram-master 
pi@raspberrypi:~ $ chmod +x install.sh && sudo ./install.sh
pi@raspberrypi:~ $ cd ..
pi@raspberrypi:~ $ rm -r log2ram-master

Modify line "Before=" and add nginx.service

pi@raspberrypi:~ $ nano /etc/systemd/system/log2ram.service

piclog2ram

Install openbox (2)

pi@raspberrypi:~ $ sudo apt-get install --no-install-recommends xserver-xorg x11-xserver-utils xinit openbox

Install firefox and chromium (chromium will used only for the tests)

pi@raspberrypi:~ $ sudo apt-get install firefox chromium-browser

Install supervisor

pi@raspberrypi:~ $ sudo apt install supervisor

Install python 3

pi@raspberrypi:~ $ sudo apt install python3.5

Install rabbitmq

pi@raspberrypi:~ $ sudo apt install rabbitmq-server

Install virtualenv

pi@raspberrypi:~ $ sudo apt install python3-virtualenv 

Install nginx

pi@raspberrypi:~ $ sudo apt install nginx

clone the repository

pi@raspberrypi:~ $ git clone https://github.com/scwall/cocktail_engine.git

Create pipenv

pi@raspberrypi:~ $ cd cocktail_engine
pi@raspberrypi:~/cocktail_engine $ pipenv install --ignore-pipfile
(cocktail_engine) pi@raspberrypi:~/cocktail_engine $ exit

Configuration

Openbox Configuration (2)

pi@raspberrypi:~ $ sudo nano /etc/xdg/openbox/autostart

and replace its content with the following:

# Disable any form of screen saver / screen blanking / power management
xset s off
xset s noblank
xset -dpms
# Start firefox
firefox

.bash_profile Configuration (2)

pi@raspberrypi:~ $ sudo nano .bash_profile

add line

[[ -z $DISPLAY && $XDG_VTNR -eq 1 ]] && startx -- -nocursor`

Firefox configuration

Add all modules in firefox to the folder firefox_addons, modify kiosk mod and add main page http://127.0.0.1:14050

addons

nginx configuration (3)&(4)

Create file cocktailengine in 'sites-available'

pi@raspberrypi:~ $ sudo touch /etc/nginx/sites-available/cocktailengine

Edit the file cocktailengine

pi@raspberrypi:~ $ sudo nano /etc/nginx/sites-available/cocktailengine

and paste the code below

server {

    listen 14050; server_name ~^.*$;
    root /home/pi/cocktail_engine/;
location /static {
        alias /home/pi/cocktail_engine/static/;
    }
location /media/ {
        alias /home/pi/cocktail_engine/media/;
    }
    location / {
satisfy any;
allow 192.168.0.1/24;
allow 192.168.1.1/24;
allow 127.0.0.1;
deny  all;
        auth_basic "Restricted Content";
        auth_basic_user_file /etc/nginx/.htpasswd;
        proxy_set_header Host $http_host;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_redirect off;
        proxy_pass http://127.0.0.1:8000;
    }

}

Change the address ip "192.168.0.1" and "192.168.1.1 to your configuration router and the port at your convenience

Create symbolic link between 'site-available' and 'site-enabled'

pi@raspberrypi:~ $ sudo ln -s /etc/nginx/sites-available/cocktailengine  /etc/nginx/sites-enabled/cocktailengine

Add user in nginx for external connection (4)

pi@raspberrypi:~ $ sudo sh -c "echo -n 'youname:' >> /etc/nginx/.htpasswd"

indicate your username in 'yourname'

Create pass for user (4)

pi@raspberrypi:~ $ sudo sh -c "openssl passwd -apr1 >> /etc/nginx/.htpasswd"

Supervisor configuration (5)&(6)

Add cocktail-engine.conf

pi@raspberrypi:~ $ sudo touch cocktail-engine.conf

Edit cocktail-engine.conf and add codes below

pi@raspberrypi:~ $ sudo nano cocktail-engine.conf

Change "/home/pi/cocktail_engine/venv/bin/celery" and "/home/pi/cocktail_engine/",for show where is located venv, use

pi@raspberrypi:~ $ cd cocktail_engine
pi@raspberrypi:~/cocktail_engine $ pipenv shell
(cocktail_engine) pi@raspberrypi:~/cocktail_engine $ pipenv --venv
(cocktail_engine) pi@raspberrypi:~/cocktail_engine $ exit
[program:cocktail-engine-celery]
command=/home/pi/cocktail_engine/venv/bin/celery -A cocktail_engine worker --loglevel=INFO
directory=/home/pi/cocktail_engine/
user=pi
numprocs=1
stdout_logfile=/var/log/celery-cocktail-engine.log
stderr_logfile=/var/log/celery-cocktail-engine.log
autostart=true
autorestart=true
startsecs=10

; Need to wait for currently executing tasks to finish at shutdown.
; Increase this if you have very long running tasks.
stopwaitsecs = 600

stopasgroup=true

; Set Celery priority higher than default (999)
; so, if rabbitmq is supervised, it will start first.
priority=1000

[program:cocktail-engine-gunicorn]
command = /home/pi/cocktail_engine/venv/bin/gunicorn cocktail_engine.wsgi:application
user = pi
directory = /home/pi/cocktail_engine
autostart = true
autorestart = true
environment = ENV="PRODUCTION",SECRET_KEY="~CK$8u_\x0bo+S8O\x0b8[dCh*P@FF"

Change the secret key with the random key (https://www.miniwebtool.com/django-secret-key-generator/)

Project configuration

Active pipenv in terminal

pi@raspberrypi:~/cocktail_engine $ pipenv shell

Create database and apply migration

(venv) pi@raspberrypi:~/cocktail_engine $ ./manage.py migrate

Create migration from the engine

(venv) pi@raspberrypi:~/cocktail_engine $ ./manage.py makemigrations engine

Create apply new migrations

(venv) pi@raspberrypi:~/cocktail_engine $ ./manage.py migrate

Apply initial data in the table solenoidValve

(venv) pi@raspberrypi:~/cocktail_engine $ ./manage.py loaddata engine/solenoidvalve.json

⚠️ The solenoid valves and the steps are configured by default. For change the number attributed at relay, it will be necessary to modify "first_pin" and "second_pin" in the database,the steps can be readjusted during the creation of bottles. In the future, I will think about putting a menu to configure the pins ⚠️

Collect static files and answer yes to the question

(venv) pi@raspberrypi:~/cocktail_engine $ ./manage.py collectstatic

Finish :bowtie:

Reboot the raspberry pi

(venv) pi@raspberrypi:~/cocktail_engine $ sudo reboot

If everything has been respected the project should be displayed on the touch screen

How to use the project

Main page

main page

Bottle admin page

bottle admin page

Cocktail admin page

cocktail admin page

Source

Clone this wiki locally