Create SD Image Version 0.8.4

From HiveTool
Revision as of 05:08, 19 September 2019 by Paul (talk | contribs) (Features)
Jump to: navigation, search

Bug fixes

  1. Fix problem with config.pl taking a long time to load
  2. Fix problem with data on charts not aligning properly.

Features

  1. Change graph generation to gnuplot.
  2. Added additional graphs for wind and battery voltage.
  3. Add support for BME680
  4. Add support for DS18B20
  5. Increase resolution of the weight from xxx.xx to xxx.xxx
  6. Added video monitoring with RasPi Cam.

Install gnuplot

sudo apt-get install gnuplot


add -r Retries option to driver wrappers

The maximum number of retries to read a sensor before giving up can be specified.

The shell script wrappers around the sensor drivers (dht22.sh, hx711.sh, hx711py.sh, etc) now accept a -r retries command line argument.

#
# Get the command line options (which device/GPIO pin to read), maximum number of times to try reading the sensor
#
while getopts "d:r:" option
do
        case "${option}"
        in
                d) DEVICE=${OPTARG};;
                r) MAXRETRIES=${OPTARG};;
        esac
done 

#
# If max number of retires not specified, default to 10
#
if [ -z $MAXRETRIES ]
then
  MAXRETRIES=10
fi 

#echo "DEVICE = $DEVICE"
#echo "MAXRETRIES = $MAXRETRIES"
#
# Loop up to MAXRETRIES times trying to read the sensor
#

DATA_GOOD=0
COUNTER=0
while [ $COUNTER -lt $MAXRETRIES ] && [ $DATA_GOOD -eq 0 ]
do



In config.pl, the -r1 option is added to the command line when the driver is called:


  if ( $hive_weight_sensor eq "cpw200plus" ) {
           $raw_hive_weight=`/usr/bin/sudo /home/hivetool/cpw200plus.sh -r1 -d $hive_weight_device`;
       }
  elsif ( $hive_weight_sensor eq "HX711") {
      $raw_hive_weight=`/usr/bin/sudo /home/hivetool/hx711.sh -r1 2>&1`;
       }
   elsif ( $hive_weight_sensor eq "HX711py") {
      $raw_hive_weight=`/usr/bin/sudo /home/hivetool/hx711py.sh -r1 2>&1`;
       }


How the image was created

Get latest image

Download, verify the SHA256 checksum, unzip, burn image.

Version: November 2018
Release date: 2018-11-13
Kernel version: 4.14
Image with desktop and recommended software based on Debian Buster
Version: July 2019
Release date: 2019-07-10
Kernel version: 4.19
Size: 1945 MB
SHA-256: 2bd0613ec8739b6fa4274ea186ec859046f79e6aee4b8c6af0acb6d88f3f533a

Verify the checksum:

$ openssl dgst -sha256 -hex 2018-11-13-raspbian-stretch-full.zip

SHA256(2018-11-13-raspbian-stretch-full.zip)= 0ca644539fdaf4e19ec7cebf9e61c049b82ba45b1a21cdec91fa54bd59d660d2
$ openssl dgst -sha256 -hex 2019-07-10-raspbian-buster-full.zip
SHA256(2019-07-10-raspbian-buster-full.zip)= 2bd0613ec8739b6fa4274ea186ec859046f79e6aee4b8c6af0acb6d88f3f533a


Unzip the image

$ unzip 2018-11-13-raspbian-stretch-full.zip
Archive:  2018-11-13-raspbian-stretch-full.zip
  inflating: 2018-11-13-raspbian-stretch-full.img
$ unzip 2019-07-10-raspbian-buster-full.zip 
Archive:  2019-07-10-raspbian-buster-full.zip
 inflating: 2019-07-10-raspbian-buster-full.img


Copy it to the SD card

# dd bs=40M if=2018-11-13-raspbian-stretch-full.img of=/dev/sdc
126+1 records in
126+1 records out
5297405952 bytes (5.3 GB, 4.9 GiB) copied, 890.612 s, 5.9 MB/s
# dd bs=40M if=2019-07-10-raspbian-buster-full.img  of=/dev/sdb
153+1 records in
153+1 records out
6434062336 bytes (6.4 GB, 6.0 GiB) copied, 819.132 s, 7.9 MB/s

Boot

Stretch boots directly into the window system.

                     ....

Update, upgrade

update your system's package list and then upgrade all your installed packages to their latest versions:

sudo apt-get update
sudo apt-get dist-upgrade

Install RPi-Cam-Web-Interface

https://elinux.org/RPi-Cam-Web-Interface

First install motion:

sudo apt-get install motion

Then install RPi-Cam-Web-Interface

git clone https://github.com/silvanmelchior/RPi_Cam_Web_Interface.git
cd RPi_Cam_Web_Interface
./install.sh

Remove packages we don't need

sudo apt-get remove --purge scratch dillo squeak-vm squeak-plugins-scratch sonic-pi
sudo apt-get autoremove
sudo apt-get clean
rm -rf /home/pi/python_games
sudo rm -rf /opt/minecraft-pi
sudo apt-get remove --purge scratch dillo squeak-vm squeak-plugins-scratch sonic-pi

Install packages we need

sudo apt-get -y install gawk bc apache2 libusb-dev libgd-graph-perl libexpat1-dev sqlite3
sudo apt-get install dh-autoreconf libudev-dev
sudo apt-get install gnuplot

Install perl modules

sudo cpan CGI Date::Format XML::Simple DBI DBD::SQLite Chart::Gnuplot
sudo cpan DateTime

Web Server

Configure apache

  1. Link the cgi.load and include.load module to mods-enabled
    ln -s /etc/apache2/mods-available/cgi.load /etc/apache2/mods-enabled
    ln -s /etc/apache2/mods-available/include.load /etc/apache2/mods-enabled
  2. Add .pl to AddHandler cgi-script
    sudo vi /etc/apache2/mods-enabled/mime.conf
    uncomment #AddHandler cgi-script .cgi (around line 219) and add ".pl .py" so it looks like:
    AddHandler cgi-script .cgi .pl .py
  3. add Includes and +ExecCGI to Options:
    sudo vi /etc/apache2/apache2.conf
    In stanza <Directory /var/www/>
    change
    Options Indexes FollowSymLinks
    to
    Options Indexes FollowSymLinks Includes ExecCGI
  4. Add index.shtml to DirectoryIndex:
    sudo vi /etc/apache2/mods-enabled/dir.conf
    Change
    DirectoryIndex index.html index.cgi index.pl index.php index.xhtml index.htm
    to
    DirectoryIndex index.html index.cgi index.pl index.php index.xhtml index.htm index.shtml
  5. Set up apache to listen on port 8080 if using port forwarding:
    sudo vi /etc/apache2/ports.conf
    add Listen 8080
  6. Restart Apache
sudo apachectl restart   or      sudo/etc/rc4.d/S02apache2 restart

Set sudo user privileges for Apache

This is necessary to allow config.pl to read the sensors. Run visudo to edit the sudo config file:

sudo visudo

and insert these line in the "User privilege specification" section:

# User privilege specification
root    ALL=(ALL:ALL) ALL
www-data ALL=NOPASSWD: /home/hivetool/hive.sh
www-data ALL=NOPASSWD: /home/hivetool/hx711pyB.sh, /home/hivetool/hx711.sh, /home/hivetool/hx711b.sh
www-data ALL=NOPASSWD: /home/hivetool/HX711a128.py, /home/hivetool/hx711py.sh
www-data ALL=NOPASSWD: /home/hivetool/dht22_adafruit.sh
www-data ALL=NOPASSWD: /usr/bin/nice
www-data ALL=NOPASSWD: /home/hivetool/temperhum.sh
www-data ALL=NOPASSWD: /usr/local/bin/2591, /usr/local/bin/2561
www-data ALL=NOPASSWD: /usr/local/bin/hx711, /usr/local/bin/hx711wp_chanB, /usr/local/bin/AdafruitDHT.py, /usr/local/bin/Seeed_DHT22


Test wiringPi library

WiringPi is PRE-INSTALLED with standard Raspbian systems. To update (or install):

sudo apt-get install wiringpi

To test:

$ gpio -v

gpio version: 2.50
Copyright (c) 2012-2018 Gordon Henderson
This is free software with ABSOLUTELY NO WARRANTY.
For details type: gpio -warranty 

Raspberry Pi Details:
  Type: Pi 3B+, Revision: 03, Memory: 1024MB, Maker: Sony 
  * Device tree is enabled.
  *--> Raspberry Pi 3 Model B Plus Rev 1.3
  * This Raspberry Pi supports user-level GPIO access.

http://wiringpi.com/download-and-install/

To display all the I/O:

$ gpio readall


phpLiteAdmin 1.9.8.2

Install SQLite database administration tools. Download zipped file from

https://www.phpliteadmin.org/download/

and save in /home/downloads.

mkdir /home/downloads/phpLiteAdmin
cd /home/downloads/phpLiteAdmin

wget https://bitbucket.org/phpliteadmin/public/downloads/phpLiteAdmin_v1-9-8-2.zip

Unzip and copy the php files to/var/www/html/admin

unzip phpLiteAdmin_v*.zip
sudo mkdir /var/www/html/admin
sudo cp *.php /var/www/html/admin

Install php

sudo apt install php7.0 php7.0-cli
sudo apt-get install php-sqlite3


Configure phpliteadmin

cd /var/www/html/admin/
sudo cp phpliteadmin.config.sample.php phpliteadmin.config.php
vi phpliteadmin.config.php

change

$directory = '.';  

to

$directory = '..';

gnuplot

sudo apt-get install gnuplot
pip install PyGnuplot

gEDA Schematic/PCB layout software

Install the Electronic Design Automation tools

sudo apt-get update
sudo apt-get install geda
sudo apt-get install pcb
sudo apt-get install gerbv

In /home/pi/.gEDA create /home/pi/.gEDA/gschem

vi /home/pi/.gEDA/gschem

and add the following line

(component-library "/home/hardware/symbols")

Copy the schematics and PCB layouts to /home/hardware.

Install streaming software

Install ffmpeg

Install ffmpeg streaming software for streaming audio and video from the hive

sudo apt-get update
sudo apt-get install ffmpeg
sudo apt-get install ffmpeg-doc

Oops! ffserver has been dropped from ffmpeg! Replace with mjpg-streamer?


DHTxx Temperature/Humidity Sensor

This code uses the PiGPIO libraries (pigpiod).

  1. Download the DHT11/21/22/33/44 Sensor code from http://abyz.me.uk/rpi/pigpio/code/DHTXXD.zip
  2. Unzip
  3. compile

Note that this code uses the Broadcom GPIO numbering so Ras Pi GPIO 2 <=> Broadcom GPIO 27 Ras Pi GPIO 3 <=> Broadcom GPIO 22

mkdir /home/downloads/DHTxx
cd /home/downloads/DHTxx
wget http://abyz.me.uk/rpi/pigpio/code/DHTXXD.zip
unzip DHTXXD
gcc -Wall -pthread -o DHTXXD test_DHTXXD.c DHTXXD.c -lpigpiod_if2


TLS2591 Lux Sensor

2591 Adafruit with modified code.

-rw-r--r-- 1 root root 10439 Aug  3 01:36 2591a.cpp
-rw-r--r-- 1 root root  3303 Aug  3 01:36 2591a.h
-rw-r--r-- 1 root root  1509 Aug  3 01:36 2591_pi_2.cpp
gcc 2591_pi_2.cpp 2591a.cpp -lwiringPi -o 2591 
cp 2591 /usr/local/bin


Add crontab entries

Edit crontab:

sudo crontab -e

Add to crontab:

#
# ### Start of Hivetool crontab entries ###
#
# start PIGPIO daemon on boot 
@reboot /usr/local/bin/pigpiod
# 
# start Data Acquisition Daemon on boot
@reboot /home/hivetool/dad7.sh
#
# Check hive instruments every 5 minutes. Kill process after 3 1/2 minutes.
0,5,10,15,20,25,30,35,40,45,50,55 * * * * timeout -s KILL 3.5m /home/hivetool/hive.sh >/dev/null 2>&1
#
# Check the server status. Kill process after 1 minute.
4,9,14,19,24,29,34,39,44,49,54,59 * * * * timeout -s KILL 1m /home/hivetool/server_status.sh > /var/www/html/server_status.txt
#
# Reset the rain gauge at midnight
1 0 * * * timeout -s KILL 1m /home/hivetool/rain_reset.sh
#
# ### End of HiveTool crontab entries ###
#


Install National Time Protocol Daemon (ntpd)

sudo apt-get -y install ntp


Install RTC support

Edit /boot/config.txt. Add:

#enable RTC DS3231 module
dtoverlay=i2c-rtc,ds3231


Edit /lib/udev/hwclock-set and comment out these three lines:

#if [ -e /run/systemd/system ] ; then
# exit 0
#fi