[vz-dev] Anleitung zum konfigurieren eines IR Lesekopf am Rpi

Wolfgang Fahl wf at bitplan.com
Tue May 13 11:11:50 CEST 2014


Hallo Ludger,

hier findest Du meine notizen und unten ein script mit dem ich gerade
experimentiere. Bitte gib mir feedback dazu. Kannst mich auch gerne per
Telefon anrufen- Angaben sind
unten in der Signature.

Wenn die Infos was taugen würde ich sie gerne auf die Wikiseite bringen
- was muss ich dafür tun?


      Udo's Lesekopf

  * Bus 001 Device 012: ID 10c4:ea60 Cygnal Integrated Products, Inc.
    CP210x UART Bridge / myAVR mySmartUSB light


      Middleware

  * http://wiki.volkszaehler.org/software/middleware/installation

apt-get update
sudo apt-get install git-core libapache2-mod-php5 php5-cli php5-mysql php-apc mysql-server mysql-client
sudo bash install.sh

and apache configuration
anschliessend geht:

http://rpi.bitplan.com

add S0-Impulszähler 10000 Impulse pro kwh


      uuids

mysql> select * from entities;
+----+--------------------------------------+-------+---------+
| id | uuid                                 | type  | class   |
+----+--------------------------------------+-------+---------+
|  1 | a301d8d0-903b-1234-94bb-d943d061b6a8 | power | channel |
|  2 | 38c6fb60-d9f9-11e3-aa75-7509b3b28371 | power | channel |
|  3 | 89f3ff60-da16-11e3-9b7d-615684429384 | power | channel |
|  4 | f2184180-da16-11e3-9709-7f3f3c090c10 | power | channel |
+----+--------------------------------------+-------+---------+

38c6fb60-d9f9-11e3-aa75-7509b3b28371 is the S0-Impuls for the digital meter


      vzlogger

  * http://www.goller-online.de/index.php/raspberry-pi/vzlogger/91-vzlogger-mit-apt-get-installieren


Ihr könnt das einbinden, indem Ihr folgenden Eintrag zu /etc/apt/sources.list hinzufügt:
deb http://packages.volkszaehler.org/vz/ wheezy main

Damit die Prüfung der Paket-Signatur klappt, müsst Ihr den Signierschlüssel importieren (als root):
wget -O- http://packages.volkszaehler.org/vz/justinotherguy.asc | apt-key add -

Jetzt noch ein
apt-get update

und ein
apt-get install vzlogger

- das war's.


Entpacken von vzlogger (aus .../vzlogger_0.3.3-rc3_armhf.deb) 


        vzlogger konfigurieren

  * http://www.lexxi.at/2013/05/02/start-und-kontrolle-von-vzlogger/
  * http://wiki.volkszaehler.org/howto/emh_pv-anlage

udevadm info --query=all --name=/dev/ttyUSB0 | grep -i serial_short
E: ID_SERIAL_SHORT=0079E5B9


    Troubleshooting


      get rid of invalid data

mysql> select count(*),channel_id from data group by channel_id order by 1 desc;
+----------+------------+
| count(*) | channel_id |
+----------+------------+
|    21345 |          1 |
|      575 |          3 |
|      575 |          4 |
+----------+------------+
mysql> delete from data where channel_id>1;


      Zähler

  * http://wiki.volkszaehler.org/hardware/channels/meters/power/edl-ehz/edl21-ehz

  * http://wiki.volkszaehler.org/hardware/channels/meters/power/edl-ehz/emh-ehz-h1



hier findest Du ein Script, dass ich gerade auf dem raspberry teste

#!/bin/bash
# install script for vzlogger
# WF 2014-05-12
# $Header:
/media/fdf64846-7c1a-4a44-8ef6-b4f9177e893e/home/wf/volkszaehler/RCS/vzlinstall.sh,v
1.10 2014/05/13 07:07:43 wf Exp wf $
#set -x

#
# 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
}

#
#  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 $scrlist 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
}

#
# 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
}

#
# configure vzlogger
#
configure() {
  rm /etc/vzlogger.conf
  # configure vzlogger
  # anpassen!
cat << EOF | vzlogger_configure
949808f0-da6f-11e3-9d0e-6757e6f50dbd 15.7.0 Haus-15.7.0_Wirkleistung
4e57e880-da74-11e3-8ea0-2743cd8e7e3f  1.8.0 Haus-1.8.0_EVU_Bezug
f2184180-da16-11e3-9709-7f3f3c090c10  2.8.0 Haus-2.8.0_PV_Einspeisung
b657c960-da69-11e3-be9c-830351251385  2.7.0 Haus-2.7.0-Leistung
EOF
#  efaaee80-da67-11e3-9d0e-f36cf67c5b5b 16.7.0 "Leistung_Verbrauch"
#  b657c960-da69-11e3-be9c-830351251385 2.7.0 "Leistung_Lieferung"
}

restart() {
  pid=`pgrep -l vzlogger`
  if [ $? -eq 0 ]
  then
    echo "killing  vzlogger $pid"
    pkill vzlogger
  fi
  vzlogger
}

# auskommentieren was Du brauchst!
# first install vzlogger / check if it is already installed
vzlogger_install
# configure vzlogger
vzlogger_udevrules
# test the usb devices directly and with vzlogger
vzlogger_test 0
sql_query | mysql -u vz --password='demo' volkszaehler
#uuid    value
#38c6fb60-d9f9-11e3-aa75-7509b3b28371    S0-Impulse
#949808f0-da6f-11e3-9d0e-6757e6f50dbd    Haus 15.7.0 Wirkleistung
#a301d8d0-903b-1234-94bb-d943d061b6a8    S0-Zaehler
#b657c960-da69-11e3-be9c-830351251385    Haus 2.7.0 Leistung
#efaaee80-da67-11e3-9d0e-f36cf67c5b5b    Haus 16.7.0 Leistung
#f2184180-da16-11e3-9709-7f3f3c090c10    Haus 2.8.0 (Lieferung -A)
#stty_usb 0
#service vzlogger start

Am 10.05.14 17:50, schrieb Ludger Bremenkamp:
>
> Hallo zusammen,
>
>  
>
> ich möchte meinen Landis&Gyr ZMD120APECS mit der Raspberry Pi
> Erweiterung + Lesekopf von Udo auslesen und suche nach einer Anleitung!
>
>  
>
> Ich kann im Netz nichts finden hat jemand einen Link oder eine Anleitung!
>
>  
>
> Danke!!
>
>  
>
> Grüße Ludger
>

-- 

BITPlan - smart solutions
Wolfgang Fahl
Pater-Delp-Str. 1, D-47877 Willich Schiefbahn
Tel. +49 2154 811-480, Fax +49 2154 811-481
Web: http://www.bitplan.de
BITPlan GmbH, Willich - HRB 6820 Krefeld, Steuer-Nr.: 10258040548, Geschäftsführer: Wolfgang Fahl 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://demo.volkszaehler.org/pipermail/volkszaehler-dev/attachments/20140513/462b679f/attachment-0001.html>


More information about the volkszaehler-dev mailing list