Dies ist eine alte Version des Dokuments!
Inhaltsverzeichnis
vzlogger Installation Script
we recommend the manual installation: installation_cpp-version
As of 2014-05-14/2014-05-24 this script is in Alpha-state.
Please send your feedback to Wolfgang wf (at) bitplan.com. This Script was successfully used on a raspberry-pi With this Script an Installation on a raspberry-pi with wheezy 3.10.27+ connected to an EHZ counter using the USB-Lesekopf was done.
Feedback as of 2014-10-06 results of testing, credits to Wolfgang for his support!!!:
- Linux version 3.12.28+ (dc4@dc4-XPS13-9333) (gcc version 4.8.3 20140303 (prerelease) (crosstool-NG linaro
- 1.13.1+bzr2650 - Linaro GCC 2014.03) ) #709 PREEMPT Mon Sep 8 15:28:00 BST 2014
1) script executed/started in /home/pi
2) script for some reason picked wrong path while installing vzlogger/libsml, i.e. under apache2/sites-avialable:
... make[1]: Entering directory '/etc/apache2/sites-available/libsml/sml' ... make[1]: Leaving directory '/etc/apache2/sites-available/libsml/sml' make[1]: Entering directory '/etc/apache2/sites-available/libsml/examples' cc -I../sml/include/ -g -Wall -c sml_server.c -o sml_server.o cc -I../sml/include/ -g -Wall sml_server.o -luuid ../sml/lib/libsml.a -o sml_server make[1]: Leaving directory '/etc/apache2/sites-available/libsml/examples' make[1]: Entering directory '/etc/apache2/sites-available/libsml/test' make[2]: Entering directory '/etc/apache2/sites-available/libsml/sml' make[2]: Nothing to be done for 'libsml'. make[2]: Leaving directory '/etc/apache2/sites-available/libsml/sml' ...
3) later on error while installation prompt while installing vzlogger/libsml:
...
make[1]: Leaving directory '/etc/apache2/sites-available/libsml/test'
cp: cannot stat `libsml/sml/lib/libsml.*': No such file or directory
cp: cannot stat `libsml/sml/include/*': No such file or directory
cp: cannot stat `libsml/sml.pc': No such file or directory
...
==> GNUTLS_LIBRARIES='/usr/lib/arm-linux-gnueabihf/libgnutls.a;/lib/arm-linux-gnueabihf/libgcrypt.a;/usr/lib/arm-linux-gnueabihf/libgpg-error.a;/usr/lib/arm-linux-gnueabihf/libtasn1.a;/usr/lib/arm-linux-gnueabihf/libz.a;-lp11-kit;-lsasl2;/lib/arm-linux-gnueabihf/libgcrypt.a'-- Found GNUTLS: /usr/lib/arm-linux-gnueabihf/libgnutls.a;/lib/arm-linux-gnueabihf/libgcrypt.a;/usr/lib/arm-linux-gnueabihf/libgpg-error.a;/usr/lib/arm-linux-gnueabihf/libtasn1.a;/usr/lib/arm-linux-gnueabihf/libz.a;-lp11-kit;-lsasl2;/lib/arm-linux-gnueabihf/libgcrypt.a
***** Configuration parameters *****
prefix: /usr/local
json: -L/usr/lib/arm-linux-gnueabihf/libjson.a;-lrt -I/usr/include
sml: -LSML_LIBRARY-NOTFOUND;-lrt -ISML_INCLUDE_DIR-NOTFOUND
microhttpd: -L/usr/lib/arm-linux-gnueabihf/libmicrohttpd.a;-lrt -I/usr/include
CMake Error at CMakeLists.txt:118 (message):
libsml ist required.
Install libsml or call cmake -DSML_HOME=path_to_sml_install
4) Solved by editing CMakeCache.txt and replace /etc/apache2/sites-available/libsml with /opt/src/libsml
5) then moved mv /etc/apache2/sites-available/libsml /opt/src/libsml
6) and then followed instructions on http://wiki.volkszaehler.org/software/controller/vzlogger/installation_cpp-version
a) carried out chapter "building libsml" manually b) carried out chapter "building vzlogger" manually and then it worked
change history
* 2014-05-14 initial version * 2014-05-24 uses dialog for interactive input - now also has a menu entry for middleware installation
Usage of the Script
In the alpha state the full necessary logic for installing vzlogger has not been implemented yet. There is still one step that is manual where you need to modify the script. Most of the functions are now selectable via a menu. With your feedback i hope to be able to improve on this script. I am looking forward to your responses!
The following functions are available (and are explained with a help menu in the script):
middleware_install
- installs packages
- downloads install.sh
- runs install.sh
vzl_apache2
- a2enmods rewrite module if necessary
- modfies apache2 configuration
- restarts apache2
vzlogger_install_source
Automated installation from sources as described in installation_cpp-version The necessary packages for compilation will be installed as necessary.
vzlogger_install
Installs from debian packages (for raspberry) as described at http://www.goller-online.de/index.php/raspberry-pi/vzlogger/91-vzlogger-mit-apt-get-installieren As of 2014-05-14 this will install a Version 0.3.3 (i think) which is not the most current one (0.3.5)
vzlogger_udevrules
Set's up the udev rules for the device as outlined in emh_pv-anlage
vzlogger_test
Runs a test as outlined in emh_pv-anlage and displays whether test is o.k. or not
sql_query
Supplies a query for the uuids - to run it you might want to check the user and password in the script
vzlogger_create_conf
Create a vzlogger.conf as outlined in emh_pv-anlage using the settings from the sqlquery You might want to modify the lines between
cat << EOF | vzlogger_configure 02645710-da9e-11e3-b298-118f244e89f4 15.7.0 15.7.0-Wirkleistung bdb79b20-da9d-11e3-ae1c-4ba69b063fb6 2.8.0 2.8.0-PV-Einspeisung e5f9c890-da9d-11e3-a023-4bbff9188d3a 1.8.0 1.8.0-EVU-Bezug EOF
according to the results of the sql-query Each line has three entries
- uuid e.g. 02645710-da9e-11e3-b298-118f244e89f4
- obis i.d. e.g. 1.8.0
- comment e.g. 1.8.0-EVU-Bezug (no spaces here or the comment will be truncated)
vzlogger_restart
(Re)starts vzlogger
Todos
- Check platform and act accordingly
- add logic parts for selection of installation choices
- rename this page - the script not only installs vzlogger
vzlinstall.sh Script
installation
nano vzlinstall.sh
past and modify code
chmod +x vzlinstall.sh sudo ./vzlinstall.sh
vzlinstall.sh
#!/bin/bash # install script for vzlogger # WF 2014-05-12 # $Header: /home/wf/volkszaehler/RCS/vzinstall.sh,v 1.16 2014/05/24 13:37:27 wf Exp $ #set -x backtitle="Vzlogger installation" INPUT=/tmp/vz_install_menu.sh.$$ OUTPUT=/tmp/vz_install_output.sh.$$ # trap and delete temp files trap "rm $INPUT; rm $OUTPUT; exit" SIGHUP SIGINT SIGTERM # # Purpose - display output using msgbox # $1 -> set msgbox height # $2 -> set msgbox width # $3 -> set msgbox title # function display_output(){ local h=${1-10} # box height default 10 local w=${2-41} # box width default 41 local t=${3-Output} # box title dialog --backtitle "$backtitle" --title "${t}" --clear --msgbox "$(<$OUTPUT)" ${h} ${w} } # # wait for user input # function userwait() { echo "press enter to continue ..." read x } # # show the help # show_help() { local l_help=$(<"${INPUT}") local l_helptext="see http://wiki.volkszaehler.org/vzlogger-installation for more details" case $l_help in "HELP readme") l_helptext="This script tries to help install your Volkszaehler middleware and vzlogger As of 2014-05-24 the script is available via: http://wiki.volkszaehler.org/vzlogger-installation The Script is in alpha state - please send feedback to wf(@)bitplan.com. This script was successfully used on a raspberry pi using Udo's USB Lesekopf. You might want to 1) read this readme 2) install the middleware via mw_install 3) configure apache webserver 4) install vzlogger from source via src_install 5) setup your udev rules via udev_rules 6) test the Lesekopf via test_usb then configure your channels using the frontend. http://wiki.volkszaehler.org/howto/emh_pv-anlage shows a good way to assign your channels. 7) query the database for the channel configuration 8) create configuration - here you need to modify this script see function vzlogger_create_conf() 9) (re)start vzlogger please note as of 2014-05-24 this is alpha software so if something doesn't work as expected look at the script and give feedback to wf(@)bitplan.com or via the wiki at http://wiki.volkszaehler.org/vzlogger-installation registration for the wiki is simple and you'll be able to access the wiki immmediately! ";; "HELP mw_install") l_helptext="Installs the Middleware as outlined at http://wiki.volkszaehler.org/software/middleware/installation 1) installs necessary packages 2) retrieves install script from git 3) runs bash install which will a) install the middleware via PHP Composer b) let you configure the middleware";; "HELP src_install") l_helptext="Installs vzlogger from source as outlined at http://wiki.volkszaehler.org/ software/controller/vzlogger/installation_cpp-version 1) installs necessary packages 2) builds libsml 3) builds vzlogger";; "HELP pkg_install") l_helptext="Installs vzlogger from a debian package as outlined at http://www.goller-online.de/ index.php/raspberry-pi/vzlogger/91-vzlogger-mit-apt-get-installieren 1) modifies /etc/apt/sources.list 2) gets the key 3) apt-get update 4) apt-get intall vzlogger the version installed seems to be outdated as of 2014-05-12";; "HELP udev_rules") l_helptext="sets up udev rules as outlined at http://wiki.volkszaehler.org/howto/emh_pv-anlage for USB0 ... ";; "HELP test_usb") l_helptext="tests USB output as outlined at http://wiki.volkszaehler.org/howto/emh_pv-anlage for USB0 ... ";; "HELP query_sql") l_helptext=`sql_query` l_helptext="runs a mysql query to retrieve the channel information the sql query used is: $l_helptext the result are needed for configuring vzlogger"; ;; *) l_helptext="there is no special help here for $l_help $l_helpttext";; esac tmphelp=/tmp/vzinstall_help.$$ echo "$l_helptext" > $tmphelp #display_output 6 60 "$l_helptext" dialog --title "$l_help" --textbox $tmphelp 18 76 rm $tmphelp } # # # error # error() { local l_msg="$1" local l_hint="$2" echo "error: $l_msg" 1>&2 echo " you might want to $l_hint" 1>&2 exit 1 } # # check and optionally install a package # install_package() { local l_package="$1" PKG_OK=$(dpkg-query -W --showformat='${Status}\n' $l_package|grep "install ok installed") echo Checking for $l_package: $PKG_OK if [ "" == "$PKG_OK" ]; then echo "$l_package not installed yet. Installing $l_package" sudo apt-get --force-yes --yes install $l_package fi } # # install middleware as outlined in http://wiki.volkszaehler.org/software/middleware/installation # middleware_install() { for package in git-core libapache2-mod-php5 php5-cli php5-mysql php-apc mysql-server mysql-client do install_package $package done sudo wget --no-check-certificate https://raw.github.com/volkszaehler/volkszaehler.org/master/misc/tools/install.sh sudo bash ./install.sh } # # build libsml # build_libsml() { if [ -f /usr/lib/libsml.o ] then echo "libsml already installed at /usr/lib/libsml.o" return else if [ ! -d libsml ] then echo "getting and installing libsml sources" git clone https://github.com/dailab/libsml.git cd libsml make else echo "libsml already installed from sources" fi cp libsml/sml/lib/libsml.* /usr/lib/. cp -R libsml/sml/include/* /usr/include/. cp libsml/sml.pc /usr/lib/pkgconfig/. fi } # # build vzlogger # build_vzlogger() { if [ ! -d vzlogger ] then echo "getting and installing vzlogger sources" git clone https://github.com/volkszaehler/vzlogger.git cd vzlogger cmake . make make install else echo "vzlogger already installed from sources" fi } # # install vzlogger from source # see http://wiki.volkszaehler.org/software/controller/vzlogger/installation_cpp-version # vzlogger_install_source() { for package in build-essential cmake pkg-config libcurl4-openssl-dev libjson0-dev libmicrohttpd-dev libgnutls-dev libsasl2-dev uuid-dev uuid-runtime do install_package $package done build_libsml build_vzlogger } # # install vzlogger from debian package # vzlogger_install() { vzl=`which vzlogger` if [ $? -eq 0 ] then echo "vzlogger is already installed at $vzl" return fi package="deb http://packages.volkszaehler.org/vz/ wheezy main" srclist=/etc/apt/sources.list # check that source.list exists if [ ! -f $srclist ] then error "$srclist is missing" "install apt" fi # check that package.volkszaehler.org ist in source.list grep "$package" $srclist > /dev/null # if not we need to add it if [ $? -ne 0 ] then echo "adding $package to $scrlist ..." sudo echo "$package" >> $scrlist echo "importing key for apt" sudo wget -O- http://packages.volkszaehler.org/vz/justinotherguy.asc | apt-key add - echo "running apt-get update" sudo apt-get update echo "installing vzlogger" sudo apt-get install vzlogger else error "vzlogger not available but $srclist already modified" "check apt-get update/install" fi } # # add udev rules to the given udev rules file # param 1: the rules file # param 2: the serial number # param 3: the usb number # addrules() { local l_rules="$1" local l_serial="$2" local l_usb="$3" local l_symlink="usb-ir-lesekopf$l_usb" echo "adding rule for $l_serial/USB$l_usb to $l_rules" echo 'SUBSYSTEM=="tty", ENV{ID_SERIAL_SHORT}=="'$l_serial'", SYMLINK+="'$l_symlink'"' >> "$l_rules" udevadm trigger ls -la /dev/$l_symlink if [ ! -h /dev/$l_symlink ] then error "symbolic link $l_symlink was not created" "check udevadm trigger worked" fi } # # configure udevrules for vzlogger # vzlogger_udevrules() { rules=/etc/udev/rules.d/99-usb-ir-lesekopf.rules lsusb | grep CP210x if [ $? -ne 0 ] then error "no CP210x USB device found" "check Lesekopf/USB connected" else # check IR Lesekopf for usb in 0 1 do query="udevadm info --query=all --name=/dev/ttyUSB$usb" $query 2>&1 | grep -i serial_short > /dev/null if [ $? -eq 0 ] then serial=`$query | grep -i serial_short | cut -f2 -d=` echo "device with serial $serial at USB$usb" if [ ! -f $rules ] then addrules $rules $serial $usb else grep $serial $rules > /dev/null if [ $? -ne 0 ] then addrules $rules $serial $usb else echo "$serial/USB$usb already installed in udev rules" fi fi fi done fi } # # stty settings for the given usb device # stty_usb() { local l_usb="$1" stty -F /dev/ttyUSB$l_usb 1:0:8bd:0:3:1c:7f:15:4:5:1:0:11:13:1a:0:12:f:17:16:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0 } # # test the given usb device # test_usb() { local l_usb="$1" local l_expected="1b 1b 1b 1b" stty_usb $l_usb timeout 2 cat /dev/ttyUSB$l_usb | od -tx1 | grep "$l_expected" if [ $? -eq 0 ] then echo "USB$l_usb sends expected data $l_expected" else error "USB$l_usb sends unexpected data" "check stty settings" fi userwait } # # vzlogger test # vzlogger_test() { cat << EOF /** * vzlogger configuration * * use proper encoded JSON with javascript comments * * take a look at the wiki for detailed information: * http://wiki.volkszaehler.org/software/controller/vzlogger#configuration */ { "retry" : 30, /* how long to sleep between failed requests, in seconds */ "daemon": false, /* run periodically */ "foreground" : true, /* dont run in background (prevents forking) */ "verbosity" : 15, /* between 0 and 15 */ "log" : "/var/log/vzlogger.log",/* path to logfile, optional */ "local" : { "enabled" : false, /* should we start the local HTTPd for serving live readings? */ "port" : 8080, /* the TCP port for the local HTTPd */ "index" : true, /* should we provide a index listing of available channels? */ "timeout" : 30, /* timeout for long polling comet requests, 0 disables comet, in seconds */ "buffer" : 600 /* how long to buffer readings for the local interface, in seconds */ }, "meters" : [{ "enabled" : true, /* disabled meters will be ignored */ "protocol" : "sml", /* use 'vzlogger -h' for list of available protocols */ "device" : "/dev/usb-ir-lesekopf0", } ]} EOF } # # test the device # vzlogger_test() { local l_usb="$1" test_usb $l_usb tst_conf=/etc/vzlogger.test if [ ! -f $tst_conf ] then # only usb0 echo "creating $tst_conf (only USB$l_usb!)" vzlogger_test > $tst_conf else echo "$tst_conf already exists" fi timeout 5 vzlogger -c $tst_conf } # # output a vzlogger configuration # vzlogger_config() { local l_mode="$1" local l_uuid="$2" local l_id="$3" local l_comment="$4" local l_delim="$5" case $l_mode in header) cat << EOF /** * vzlogger configuration * * use proper encoded JSON with javascript comments * * take a look at the wiki for detailed information: * http://wiki.volkszaehler.org/software/controller/vzlogger#configuration */ { "retry" : 30, /* how long to sleep between failed requests, in seconds */ "daemon": true, /* run as server */ //"foreground" : true, /* dont run in background (prevents forking) */ "verbosity" : 5, /* between 0 and 15 */ "log" : "/var/log/vzlogger.log", /* path to logfile, optional */ "local" : { "enabled" : true, /* should we start the local HTTPd for serving live readings? */ "port" : 8080, /* the TCP port for the local HTTPd */ "index" : true, /* should we provide a index listing of available channels if no UUID was requested? */ "timeout" : 30, /* timeout for long polling comet requests, 0 disables comet, in seconds */ "buffer" : 600 /* how long to buffer readings for the local interface, in seconds */ }, "meters" : [{ "enabled" : true, /* disabled meters will be ignored */ "protocol" : "sml", /* see 'vzlogger -h' for list of available prot$ */ "device" : "/dev/usb-ir-lesekopf0", "channels": [ EOF ;; channel) cat << EOF $l_delim{ "uuid" : "$l_uuid", "middleware" : "http://localhost/middleware.php", "identifier" : "1-0:$l_id", /* $l_comment */ } EOF ;; footer) cat << EOF ] } ]} EOF ;; esac } # # configure vzlogger # vzlogger_configure() { vz_conf=/etc/vzlogger.conf if [ ! -f $vz_conf ] then # only usb0 echo "creating $vz_conf (only USB$l_usb!)" vzlogger_config header > $vz_conf local l_delim="" while read l_uuid l_id l_comment do vzlogger_config channel $l_uuid $l_id $l_comment $l_delim >> $vz_conf l_delim=", " done vzlogger_config footer >> $vz_conf else echo "$vz_conf already exists" fi } # # get the sqlquery # sql_query() { cat << EOF select e.uuid,p.value from entities e join properties p on e.id=p.entity_id where pkey='title'; EOF } # # run the sql query # run_sqlquery() { tmpsql=/tmp/vzinstall_sql$$ sql_query | mysql -u vz --password='demo' volkszaehler > $tmpsql dialog --title "sql query result" --textbox $tmpsql 18 76 rm $tmpsql } # # configure vzlogger # vzlogger_create_conf() { # uncomment if you are reconfiguring / experimenting # rm /etc/vzlogger.conf # configure vzlogger # # use your result of the database query and modify the here # document between << EOF and EOF so that # there are three columns per channel: # # 1. uuid - from database # 2. obis id - by convention also part of the name of the channel # 3. name of channel - only used as a comment # # the third column is just a comment - you might want to remove # blanks to make sure it fully appears in the configuration file cat << EOF | vzlogger_configure 73083260-dfdb-11e3-9a77-e3b0419b9496 1.8.0 Haus-1.8.0-EVU-Bezug 7fb770d0-dfdb-11e3-97ce-a35538f32d73 2.8.0 Haus-2.8.0-PV-Einspeisung ea629860-dfdb-11e3-bce5-4bf2ba21bc48 15.7.0 Haus-15.7.0-Wirkleistung EOF userwait } # # restart vzlogger # vzlogger_restart() { pid=`pgrep -l vzlogger` if [ $? -eq 0 ] then echo "killing vzlogger $pid" pkill vzlogger fi vzlogger userwait } # # configure volkszaehler for apache2 # vzl_apache2() { if [ ! -f /etc/apache2/mods-enabled/rewrite.load ] then echo "enabling apache2 rewrite module" sudo a2enmod rewrite fi ts=`date +%F_%T` a2confdir="/etc/apache2/sites-available" a2conf="$a2confdir/default" if [ ! -f $a2conf ] then error "couldn't find apache configuration file $a2conf" fi grep volkszaehler $a2conf > /dev/null if [ $? -eq 0 ] then echo "Apache configuration $a2conf already contains volkszaehler" else echo "putting $a2conf under RCS configuration management" echo "you can get back original versions any time with co -r1.1 $a2conf" install_package rcs cd $a2confdir if [ ! -d RCS ] then mkdir RCS echo "Apache default configuration file" | ci -l $a2conf else ci -l -m"forced backup revision at $ts" $a2conf fi tmpconf=/tmp/vzinstall_apache$$ cat $a2conf | awk -v a2conf=$a2conf -v ts=$ts ' /DocumentRoot \/var\/www/ { print " # modified by vzinstall.sh at " ts print " # you can retrieve the original using co -l -r1.1 " a2conf print " Documentroot /var/www/volkszaehler.org/htdocs/" next } /.Directory.*\/var\/www/ { print $0 inwww=(1==1) next } /AllowOverride/ && inwww { print " # modified by vzinstall.sh at " ts print " AllowOverride FileInfo Limit Options Indexes" inwww=(1==0) next } { print }' > $tmpconf mv $tmpconf $a2conf fi service apache2 restart userwait } # install the dialog package if it is not there yet install_package dialog # # selection loop # while true do ### display main menu ### dialog --clear --help-button --backtitle "$backtitle" \ --title "Main Menu" \ --menu "Select task or get specific help for task" 18 65 11 \ readme "1 - Read me before your start" \ mw_install "2 - Install Middleware from git" \ apache_cfg "3 - Configure Apache web server" \ src_install "4 - Install Vzlogger from source (recommended)" \ pkg_install " Install Vzlogger from package (outdated?)" \ udev_rules "5 - Setup udev rules" \ test_usb "6 - Test vzlogger via usb (USB0)" \ query_sql "7 - Query Database for configured channels" \ conf_create "8 - Create a vzlogger configuration file" \ vzl_restart "9 - (Re)Start vzlogger" \ Exit " Exit to the shell" 2>"${INPUT}" retval=$? case $retval in 0) menuitem=$(<"${INPUT}") case $menuitem in readme) echo "HELP readme" > ${INPUT}; show_help;; # middleware install mw_install) middleware_install;; # configure apache webserver apache_cfg) vzl_apache2;; # vzlogger install from package pkg_install) vzlogger_install;; # vzlogger install from source src_install) vzlogger_install_source;; # configure vzlogger udev rules udev_rules) vzlogger_udevrules;; # test the usb devices directly and with vzlogger test_usb) vzlogger_test 0;; # run the sql query query_sql) run_sqlquery;; # create vzlogger configuration conf_create) dialog --title "Create vzlogger configuration" \ --backtitle "$backtitle" \ --yesno "did you modify $0 according to your database query results? press ESC if you don't have a clue and see readme" 7 60 case $? in 0) vzlogger_create_conf;; 1) nano $0;; esac;; # restart vzlogger vzl_restart) vzlogger_restart;; # exit menu loop Exit) echo "Bye"; break;; *) display_output 6 60 "menu item: $menuitem not linked to a function" esac ;; 1) echo "cancelled"; break; ;; 2) show_help ;; 255) echo "esc"; break; ;; *) echo "return value $retvalue" break; ;; esac done # if temp files found, delete em [ -f $INPUT ] && rm $INPUT [ -f $OUTPUT ] && rm $OUTPUT