Create SD Image Version 0.8.4

From HiveTool
Revision as of 19:17, 21 July 2019 by Paul (talk | contribs)
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

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 Stretch image

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

Version: November 2018
Release date: 2018-11-13
Kernel version: 4.14

Verify the checksum:

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

SHA256(2018-11-13-raspbian-stretch-full.zip)= 0ca644539fdaf4e19ec7cebf9e61c049b82ba45b1a21cdec91fa54bd59d660d2

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

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

Boot

Stretch boots directly into the window system.

                     ....

Remove packages we don't need

sudo apt-get remove --purge penguinspuzzle scratch dillo squeak-vm squeak-plugins-scratch sonic-pi netsurf-gtk netsurf-common
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 netsurf-gtk netsurf-common

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

The above cpan DateTime seemed to work. Otherwise we will use apt-get to install the perl DateTime module

apt-get install libdatetime-perl

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


Install wiringPi library ver 2.50

  1. get wiringPi code from github and compile it
    cd /home/downloads
    git clone git://git.drogon.net/wiringPi
    cd wiringPi
    ./build
  2. Test
    gpio -v
    gpio readall
$ 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/


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

phpLiteAdmin ver 1.9.7.1

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-7-1.zip

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

unzip phpLiteAdmin_v1-9-7-1.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.