standalone installation (for experienced users)

Content

This guide is based on Windows. For other operating systems, you may need to choose a different approach (for example, describe the SD card.

Operating system RASPBIAN LITE

Download RASPBIAN LITE

We unzip this and have to write it on the SD card.

For this we download the program Win 32 Disk Imager from Sourceforge and unpack it. (On a Mac, for example, another program called “Etcher” must be used instead of Win 32 Disk Imager)

In order to access the console of the Raspberry Pi later on we need another program, e.g. Putty. We can download this here: putty (In case of Mac we need the console)

Also this we unpack after the download.

Now we put at least 8GB SD card in a card reader and wait until Windows has recognized it.

Then we start the »Win32DiskImager.exe«, select the image [Image File] and the drive letter [Device] of the memory card

Win32DiskManager GUI

and start the writing process by clicking on [Write] -> ATTENTION not the wrong drive!

When the process is complete and we have a keyboard, monitor and / or USB-Ethernet adapter, we can eject the memory card in Windows.

In case we do not have keyboard, monitor and / or USB-Ethernet adapter or we want to access directly via putty, two files have to be created in the root folder on the SD card:

An empty file named ssh without any file extension and

a file named wpa_supplicant.conf with the content (ESSID and PASSPHRASE should be replaced with the access data for our WLAN):

1
2
3
4
5
6
7
8
9
# Wpa_supplicant.conf file in the boot partition (Raspbian Stretch)
country = DE # with if US
ctrl_interface = DIR = / var / run / wpa_supplicant GROUP = netdev
update_config = 1
network = {
       ssid = "ESSID"
       psk = "PASSPHRASE"
       key_mgmt = WPA-PSK
}

If this is done we can also eject the memory card in Windows.

We put the memory card in the Raspberry PI.

If desired and available, we now connect a USB keyboard, an HDMI monitor (TV) and a min. 1A strong Micro USB power adapter. If the Raspberry PI has an Ethernet connection, we also connect a network cable.

Then the USB power supply is connected to the power.

The Raspberry Pi starts now and the boot process should be visible on the monitor.

If the two files were created in the root directory, we can access via Putty. See the instructions later.

Log in with (Attention! Keyboard still wrongly configured [z = y]):

Username: pi
Password: raspberry

Then we run the wizard

1
sudo raspi-config

(Attention! Keyboard still wrongly configured [- = ß])

and set the following settings (the individual points may be under different numbers):

2 Network Options (with raspberry pi zero)
    N2 Wi-fi
8 Update (if we have no Ethernet connection and no WLAN available, this point will be omitted or can be made up later)
7 Advanced Options
    A1 Expand file system
    A3 Memory Split to 8 for more RAM to run services
1 Change User Password for User pi
2 change hostname to e.g. "Rpi-Pi-Ager"
4 Internationalization Options
    Add I1 Standard Locale »de_DE.UTF-8 UTF-8« and select as default
    I2 Select the time zone »Europe / Berlin«
    I3 Confirm the "Generic 105-key (Intel) PC" keyboard and select "other" / "German" as the language, leaving all other options at their default values
    Select I4 DE as WiFi
5 interface options
    P2 SSH »enable«
    P6 Serial »disable« (So click on NO two times !!)
finish

After that we should be asked if we want to restart. We answer this with Yes.

If the question is not asked, we have to start the Raspberry manually.

1
2
sudo sync
sudo reboot

If there is no Ethernet connection, but a WLAN stick is available, point WiFi connection should now be preferred.

From now it is also possible by means of PC and additional program such. Putty to access the Raspberry PI. For this we have to look in our router, which IP was assigned. By means of this we can then connect via Putty. The port is 22

Once we have logged in again, we will make an update (if no LAN cable is connected, or can (eg Rapberry PI Zero first follow the instructions WiFi connection below!)

1
sudo apt-get update && sudo apt-get upgrade -y && sudo apt-get dist-upgrade

Now we activate the “root” user by assigning a password for the user:

1
sudo passwd

And if we want to log in as root using SSH, we need to adjust the config:

1
sudo nano / etc / ssh / sshd_config

Here we search for the following line:

1
2
3
4
5
6
#authentication:
#LoginGraceTime 2m
#PermitRootLogin prohibit-password
#StrictModes yes
#MaxAuthTries 6
#MaxSessions 10

and change them as follows

1
2
3
4
5
6
#authentication:
LoginGraceTime 2m
PermitRootLogin yes
StrictModes yes
MaxAuthTries 6
Max sessions 10

Now we save with “STRG + o”, “RETURN” and close with “STRG + x

Restart once

1
2
sudo sync
sudo reboot

to the top

WiFi connection

(if not already set up via raspi-config)

Only plug in the USB WIFI stick if the PI is switched off or if we use an active USB HUB -> otherwise the Raspberry PI will start by itself because of the voltage dip …

If the USB WIFI stick is plugged in and the PI is powered up, or if it is a Raspberry PI Zero W, we enter the following to see if it has been detected as a USB device:

1
lsusb

It should then be displayed in something like this:

1
2
3
4
5
Bus 001 Device 002: ID 0424: 9512 Standard Microsystems Corp.
Bus 001 Device 001: ID 1d6b: 0002 Linux Foundation 2.0 root hub
Bus 001 Device 003: ID 0424: ec00 Standard Microsystems Corp.
Bus 001 Device 004: ID 046a: 0023 Cherry GmbH CyMotion Master Linux Keyboard
Bus 001 Device 005: ID 0bda: 8176 Realtek Semiconductor Corp. RTL8188CUS 802.11n WLAN adapter (or similar)

Then we test if the stick was recognized as a USB WIFI stick:

1
iwconfig wlan0

It should look something like this:

1
2
3
4
5
6
7
8
wlan0 unassociated nickname: "<WIFI @ REALTEK>"
          Mode: Managed Frequency = 2.412 GHz Access Point: Not-Associated
          Sensitivity: 0/0
          Retry: off RTS thr: off Fragment thr: off
          Power Management: on
          Link Quality: 0 Signal level: 0 Noise level: 0
          Rx invalid: 0 Rx invalid: 0 Rx invalid: 0
          Tx excessive retries: 0 Invalid misc: 0 Missed beacon: 0

A Note on Power Management: If on, this should be set to off and then checked:

1
2
Sudo iw wlan0 set power_save off
iw wlan0 get power_save

With the following command we can list the available networks:

1
iwlist wlan0 scanning

To write the WLAN key higher rights are necessary (root)

1
sudo su -

Now we enter the following and adjust the ESSID and the PASSPHRASE for our WLAN. In order for spaces in the ESSID or password to be recognized as well, they must be masked with “(the password and the ESSID must be set in” Gänsefüßchen “eg” MY ESSID WITH SPACE “” MY PASSPHRASE WITH SPACE “)

1
wpa_passphrase "ESSID" "PASSPHRASE" >> /etc/wpa_supplicant/wpa_supplicant.conf

with [STRG] + [D] we return to the user PI. Now we can look at whether the WLan was also registered:

1
sudo nano /etc/wpa_supplicant/wpa_supplicant.conf

Result in something like this:

1
2
3
4
5
6
7
ctrl_interface = DIR = / var / run / wpa_supplicant GROUP = netdev
update_config = 1
network = {
        ssid = "DEIN_WLAN_NAME"
        # psk = "BlaBla-Real Key"
        psk = lksdfj09o4pokpofdgkpß0jppkspdfkpsß09i4popok
}

If there are configurations in the file that are not needed, we can delete them and use “STRG + o”, “RETURN” and close with “STRG + x

Now we activate the WLAN configuration and see if it worked:

1
2
sudo ifdown wlan0
sudo ifup wlan0

Possibly. can also help a reboot:

1
sudo reboot

input

1
iwconfig wlan0

Result in about:

1
2
3
4
5
6
7
8
wlan0 IEEE 802.11bgn ESSID: "PK-NEW" nickname: "<WIFI @ REALTEK>"
          Mode: Managed Frequency: 2.412GHz Access Point: DC: 9F: DB: FD: E7: A0
          Bit Rate: 150 Mbps Sensitivity: 0/0
          Retry: off RTS thr: off Fragment thr: off
          Power Management: on
          Link Quality = 83/100 Signal level = 50/100 Noise level = 0/100
          Rx invalid: 0 Rx invalid: 0 Rx invalid: 0
          Tx excessive retries: 0 Invalid misc: 0 Missed beacon: 0

Input:

1
ifconfig wlan0

Result in about:

1
2
3
4
5
6
7
wlan0 Link encap: Ethernet Hardware Address 64: 70: 02: 23: ef: 11
          inet Address: 192.168.0.52 Bcast: 192.168.200.255 Mask: 255.255.255.0
          UP BROADCAST RUNNING MULTICAST MTU: 1500 Metric: 1
          RX packet: 10 errors: 0 dropped: 17 overruns: 0 frame: 0
          TX packets: 4 errors: 0 dropped: 0 overruns: 0 carrier: 0
          Collisions: 0 Send Queue Length: 1000
          RX bytes: 2001 (1.9 KiB) TX bytes: 1036 (1.0 KiB)

If we see an IP from your DHCP area, we have made it and can now connect via Wi-Fi.

to the top

Software packages

lighttpd

First we update the packages:

1
2
sudo apt-get update
sudo apt-get upgrade

Now we install the webserver lighttpd

1
sudo apt-get install lighttpd

The question of whether we really want that, we answer with “yes”.

After installation, the service starts automatically. We can check this:

1
sudo systemctl status lighttpd

So that the functionality is given also with other operating versions, we must change the DocumentRoot directory for the Web server. By default, the new path is / var / www / html /, change this to / var / www / (it used to be like this). For this we edit the configuration file 000-default.conf in / etc / apache2 / sites-available /

1
sudo nano /etc/lighttpd/lighttpd.conf

and change the parameter

1
server.document-root = "/ var / www / html"

after

1
server.document-root = "/ var / www"

and save this with “STRG + o”, “RETURN” and close with “STRG + x

In order to be able to store files in the web server directory, we still have to set some rights.

1
2
3
4
sudo groupadd www-data
sudo usermod -G www-data -a pi
sudo chown -R www-data: www-data / var / www
sudo chmod -R 775 / var / www

For testing, we create an html page in the web directory:

1
sudo nano / var / www / test.html

with the content

1
2
3
4
5
6
<Html>
<Head> <title> Test Page </ title> </ head>
<Body>
<h1> This is a test page. </ h1>
</ Body>
</ Html>

save this with “STRG + o”, “RETURN” and close with “STRG + x” and test the installation now.

Possibly. can also help a reboot:

1
    sudo reboot

For this we give in our browser to the IP address of our Raspberry PI followed by /test.html (http: // {IP} Adresse_des_Raspberry_Pi /test.html) and should see the website.

Now we have to set up password authentication for the settings page. For this we activate the necessary module

1
sudo lighty-enable-mod auth

We still have to configure this and open it in the editor

1
sudo nano /etc/lighttpd/conf-enabled/05-auth.conf

The following lines are added under server.modules + = (“mod_auth”):

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
auth.backend = "htdigest"
auth.backend.htdigest.userfile = "/var/.htcredentials"

auth.require = ("/settings.php" =>
                                   (
                                    "method" => "digest",
                                    "realm" => "Pi-Ager",
                                    "require" => "user = pi-ager"
                                   )
                                    "/admin.php" =>
                                   (
                                    "method" => "digest",
                                    "realm" => "Pi-Ager",
                                    "require" => "valid-user"
                                    )
                                    "/webcam.php" =>
                                   (
                                    "method" => "digest",
                                    "realm" => "Pi-Ager",
                                    "require" => "valid-user"
                                    )
                                  )

save this with “STRG + o”, “RETURN” and close with “STRG + x” and restart the web server

1
sudo service lighttpd force-reload

to the top

PHP 7

Now we install PHP7 support for lighttpd

1
2
sudo apt-get update
sudo apt-get install php7.0-common php7.0-cgi php7.0 php7.0-sqlite3

The question of whether we really want to answer with “Yes”.

After installing PHP7, we need to enable the FastCGI module for PHP and reload the ighttpd configuration.

1
2
3
sudo lighty-enable-mod fastcgi
sudo lighty-enable-mod fastcgi-php
sudo service lighttpd force-reload

Now we create a test phpinfo.php in the web directory

1
sudo nano /var/www/phpinfo.php

Content:

<? php phpinfo (); ?>

save this with “STRG + o”, “RETURN” and close with “STRG + x” and test the installation now.

To do this we enter in our browser the IP address of our Raspberry PI followed by /test.html (http: // {IP_address_of_Raspberry_Pi} /phpinfo.php) and should see an info website about PHP.

Now let’s speed up the whole system a bit by enabling caching.

1
2
sudo apt-get update
sudo apt-get install php7.0-apcu

The question of whether we really want to answer with “Yes”.

Then we have to make some settings on the APC cache. To do this, open the APC configuration file

1
sudo nano /etc/php/7.0/mods-available/apcu_bc.ini

and make the following changes:

extension = apc.so
apc.enabled = 1
apc.file_update_protection = 2
apc.optimization = 0
apc.shm_size = 32M
apc.include_once_override = 0
apc.shm_segments = 1
apc.gc_ttl = 7200
apc.ttl = 7200
apc.num_files_hint = 1024
apc.enable_cli = 0

save this with “STRG + o”, “RETURN” and close with “STRG + x”.

Furthermore, we authorize files to be downloaded via the website via x-send-file. For this we edit the fcgi-configuration:

1
sudo nano /etc/lighttpd/conf-enabled/15-fastcgi-php.conf

and complete at the end of the line

"broken-scriptfilename" => "enable"

a “,” and in a new line

"allow-x-send-file" => "enable"

save this with “STRG + o”, “RETURN” and close with “STRG + x” and test the installation now.

To apply the changes, we need to reload the configuration of the web server.

1
sudo service lighttpd force-reload

to the top

pip

This is followed by pip, with which Python modules can be installed

1
sudo apt-get install python3-pip

The question of whether we really want that, we answer with “yes”.

to the top

git

We need GIT to access the repository.

1
sudo apt-get install git

The question of whether we really want that, we answer yes.

to the top

sqlite3

Now we install sqlite3 support

1
sudo apt install sqlite3

to the top

sht sensors

Support for SHT sensor

1
sudo pip3 install pi-sht1x

to the top

DHT sensors

Now we install the support for the DHT sensors

1
2
3
4
git clone https://github.com/bob60/DHT-sensors-python3
sudo apt-get install build-essential python3-dev
cd DHT-sensors-python3
sudo python3 setup.py install

and go back to the home directory

1
cd

to the top

wiringpi

Now we install Wiring Pi. This is a useful framework for switching the GPIO inputs and outputs on the Raspberry Pi.

For this we clone wiringPi

1
2
3
4
sudo git clone git: //git.drogon.net/wiringPi
cd wiringPi
sudo ./build
cd

to the top

ZIP

So that we e.g. Zipping logfiles, we now install ZIP support

1
sudo apt-get install zip

to the top

webcam

Now we install mjpegstreamer to stream the webcam image.

1
2
3
4
sudo apt-get install subversion libjpeg8-dev imagemagick -y
sudo svn co https://svn.code.sf.net/p/mjpg-streamer/code/mjpg-streamer/mjpg-streamer
cd mjpg streamer
sudo make

move the program to / opt

1
2
cd
sudo mv mjpg streamer / / opt /

create a startup script

1
sudo nano /opt/mjpg-streamer/webcam.sh

with the content (without line break)

1
2
#! / Bin / bash
/ opt / mjpg-streamer / mjpg_streamer -i "/opt/mjpg-streamer/input_uvc.so -d / dev / video0 -y -n -f 2" -o "/opt/mjpg-streamer/output_http.so -n -w / opt / mjpg-streamer / www "&

save this with “STRG + o”, “RETURN” and close with “STRG + x

Then we allow the execution of the script

1
sudo chmod + x /opt/mjpg-streamer/webcam.sh

to the top

fswebcam

To occasionally save a picture from the webcam we install fswebcam

1
sudo apt-get install fswebcam

The question of whether we really want that, we answer with “yes”.

This completes our installation preparations and allows us to focus on the maturity cabinet control

to the top

Program maturity cabinet control

Now create a folder (pi-ager) in the directory / opt:

1
sudo mkdir / opt / pi-ager

We now download the files provided in the GitHub from the branch master and unzip them.

Download

On our PC we install an FTP software (for example FileZilla), with which we establish a connection to our Raspberry Pi.

We connect with sftp: // IP-DES_RASPBERRY-PI and the user root with the associated password

and then copy the files from the download directory RSS into the directory of the same name on the Raspberry Pi under / opt / pi-ager.

then we copy from the download directory var the files sudowebscript.sh and .htcredentials into the directory of the same name on the Raspberry Pi under / var.

We start now putty and log in with the user pi and the assigned password for pi.

About putty we have to enter this shell script in / etc / sudoers so that the www-data user (user of the website) can do this. Since I find nano easier to edit, we set this first as the default editor

1
export EDITOR = nano

then open etc / sudoers with

1
EDITOR = nano sudo -E visudo

and then follow up in sudoers following

1
2
3
4
...
#User privilege specification
root ALL = (ALL: ALL) ALL
...

on:

1
www-data ALL = NOPASSWD: /var/sudowebscript.sh

Save with STRG + O and finish with STRG + X

Next, let’s take care of the autostart of the cabinet. This is used e.g. allows the cabinet to restart automatically after a power failure. For this we create a file:

1
sudo nano /etc/init.d/pi-ager-main.sh

Note: The following content can be copied here and then inserted into putty.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#! / Bin / sh
### BEGIN INIT INFO
# Provides: pi-ager-main.sh
# Required-Start: $ syslog
# Required-Stop: $ syslog
# Default start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: pi-ager main.py
# Description:
### END INIT INFO

case "$ 1" in
    begin)
        echo "pi-ager main.py will start"
        # Start program
        / usr / bin / python3 /opt/pi-ager/main.py> / dev / null 2> / dev / null &
        echo "start process completed"
        ;;
    Stop)
        echo "pi-ager main.py is closing"
        # Exit program
        pkill -f main.py
        ;;
    *)
        echo "Uses: /etc/init.d/pi-ager-main.sh {start | stop}"
        exit 1
        ;;
esac

exit 0

save this with “STRG + o”, “RETURN” and close with “STRG + x” and then give the file the right to be executable

1
sudo chmod 755 /etc/init.d/pi-ager-main.sh

We test the whole function by entering the following command on the console:

1
sudo /etc/init.d/pi-ager-main.sh start

The following issue should appear:

1
2
pi-ager main.py is started
startup process completed

after that we land again in the so-called prompt and can issue another command, which stops the service again:

1
sudo /etc/init.d/pi-ager-main.sh stop

If all this was successful, enter this file as a startup routine

1
sudo update-rc.d pi-ager-main.sh defaults

Now we need a .htcredentials file for the settings page that contains our user and password.

For this we use the online tool https://websistent.com/tools/htdigest-generator-tool/

Username: pi-ager
REALM: Pi-Ager
Password: your password

Attention! Case sensitive!

We open the file with

1
sudo nano / var /.htcredentials

and paste the generated string into the file (preferably by copying / pasting).

save this with “STRG + o”, “RETURN” and close with “STRG + x

The files from the download directory www we copy to / var / www /

Now we need to allocate a few write permissions via Putty or FileZilla on certain files:

Here are the commands for Putty:

1
2
3
4
5
6
sudo chmod 666 /var/www/logs/logfile.txt
sudo chmod 775 / var / www / logs /
sudo chmod 664 /var/www/config/pi-ager.sqlite3
sudo chown -R www-data: www-data / var / www / config /
sudo chmod 555 /var/sudowebscript.sh
sudo chmod 777 / var / www / csv /

The user ‘pi’ is a member of the group ‘gpio’ by default and therefore has access to the virtual files / sys / class / gpio / … The webserver runs as a user ‘www-data’ and is not a member of this special Group. To change that, you have to add the ‘www-data’ user to the group ‘gpio’ and restart the web server:

1
2
sudo usermod -G gpio -a www-data
sudo service lighttpd force-reload

Now we drive the Raspberry Pi via

1
sudo stop

down and unplug the power supply.

Now the sensor is connected to the Raspberry Pi. See the Construction and Connection Manual

Once this is done, we can restart the Raspberry by reconnecting the power plug.

If we now call the webiste http: //IPADRESSE/index.php everything should work fine.

to the top