Auteur Topic: Zonnepanelen data monitoren met PHP MySQL  (gelezen 9797 keer)

Offline dorustd

  • Bedankjes
  • -Gegeven: 0
  • -Ontvangen: 0
  • Berichten: 3
Zonnepanelen data monitoren met PHP MySQL
« Gepost op: 21 januari 2013, 20:30:54 »
Sinds mei 2012 heb ik 10 zonnepanelen op mij dak. De omvormer heb ik met netwerk kabel aangesloten  op mijn router.
Meer informatie Solarmax Watcher
http://sourceforge.net/projects/solarmaxwatcher/

Nu wil ik Solarmax Watcher installeren. Dit is een PHP SQl applicatie om data (kWh) te monitoren.

Ben ook in het bezit NAS DS211J. PHPMyAdmin heb ik daarop geïnstalleerd. Kan inloggen via PHPmyAdmin. Telnet en SSH service heb ik ingeschakeld. Kan via Uitvoeren-->Telnet diskstation  een telnet sessie opzetten.

SolarmaxWatcher-0.4.0.tar.gz heb ik gedownload / uitgepakt en geïnstalleerd op de Synology NAS.
Bevat kleine install beschrijving. INSTALL.SH

Nu weet ik niet hoe ik dit moet doen? Wie kan mij helpen?

Offline wizjos

  • Administrator
  • MVP
  • *
  • Bedankjes
  • -Gegeven: 123
  • -Ontvangen: 181
  • Berichten: 1.996
Re: Zonnepanelen data monitoren met PHP MySQL
« Reactie #1 Gepost op: 21 januari 2013, 22:14:07 »
....kan handig zijn om de inhoud van die install.sh even mee te geven... :mrgreen:  Is er niet ook een install.php o.i.d.? Lijkt mij gebruikelijker...

Wizjos
Wizjos.


DS409+    4 x WD10EADS DSM 4.2-3243       [TEST]
DS214play 1 x WD20EARX DSM 6.1.4-15217-3  [PROD]
DS1513+   5 x WD80EFZX DSM 6.1.4-15217-5  [PROD]
RT1900ac               SRM 1.1.6-6931-1   [PROD]


Is RAID hetzelfde als een backup?
Goeie schijven voor je NAS? Neem Western Digital!

Offline dorustd

  • Bedankjes
  • -Gegeven: 0
  • -Ontvangen: 0
  • Berichten: 3
Re: Zonnepanelen data monitoren met PHP MySQL
« Reactie #2 Gepost op: 21 januari 2013, 23:26:44 »
#!/bin/bash

#some definitions
conffile=/usr/local/etc/smw-logger.conf
tabelle=log       ## The Mysql DB tab-prefix
db=solarmax       ## The Mysql DB name
newuser=solaruser ## The Mysql DB user
realpath=$0
instpath="${realpath%/*}"
if [ "$instpath" = "." ]; then
instpath=`pwd`
fi
sitehead=$instpath/web-custom/sitehead.php
installerversion=`cat $instpath/HISTORY|grep -m 1 Version|cut -d' ' -f2`

######################################
### definition for custom commands ###
######################################

#Ask for number of inverters
ask_anz(){
   echo -n -e "n For how many inverters should the watcher be configured? "
   read anz_wr
   echo -n -e "n Is the given input correct? [y/n] "
   korrekt1(){
     read RICHTIG1
     case "$RICHTIG1" in
       y)
         return 0
         ;;
       n)
         ask_anz
         ;;
       *)
         echo -n -e "n Input error, is the number of inverters correct? [y/n] "
         korrekt1
         ;;
     esac
   }
   korrekt1
}

#Ask for Mysql Host
ask_mysql_host(){
echo -n -e "nn IP-address or hostname of your Mysql server [localhost]: "
read dbhost
   if [ -z $dbhost ]; then
     dbhost=localhost
   fi
   if [ $dbhost != localhost ]; then
     echo -e "n Please secure, that the user 'root' may access the Mysql-server $dbhost from "
     echo -e " external and that the regarding firewall rules and port forwardings are adjusted. n"
   fi
   echo -n -e "n Is the DB-host '$dbhost' correct? [y/n] "
   korrekt6(){
     read RICHTIG6
     case "$RICHTIG6" in
       y)
         return 0
         ;;
       n)
         ask_mysql_host
         ;;
       *)
         echo -n -e "n Input error, is the given hostname correct? [y/n] "
         korrekt6
         ;;
     esac
   }
   korrekt6
}

#Ask for Mysql-root-PW
ask_mysqlroot_pw(){
  mysql -u root -h $dbhost -e "show databases" >/dev/null 2>&1
  if [ $? -ne 0 ]; then
    korrekt2(){
      echo -n -e "nn Allready existing Mysql password for user 'root': "
      read -s rootpw
      echo -n -e "n Repeat password input                           : "
      read -s rootpw2
      if [ "$rootpw" == "$rootpw2" ]; then
        echo -e "n"
        return 0
      else
        echo -e "nn The passwords don't match, try again ... "
        korrekt2
      fi
    }
    korrekt2
  else
    korrekt3(){
      echo -e "n Until now, no password is set for Mysql-user 'root'. We'll set it now ... "
      echo -n -e "n Mysql password for user 'root': "
      read -s rootpw
      echo -n -e "n Repeat password input         : "
      read -s rootpw2
      if [ "$rootpw" == "$rootpw2" ]; then
        echo -e "n"
        return 0
      else
        echo -e "nn The passwords don't match, try again please... "
        korrekt3
      fi
    }
    korrekt3
    mysqladmin -u root -h $dbhost password @rootpw
  fi
}

#Ask for Mysql-user-PW
ask_mysqluser_pw(){
  echo -e "n The DB-user for the Solarmax-DB needs a password, which is asked here ... "
    korrekt4(){
      echo -n -e "n Mysql password for DB-User '$newuser': "
      read -s userpw
      echo -n -e "n Repeat password input                 : "
      read -s userpw2
      if [ "$userpw" == "$userpw2" ]; then
        echo -e "n"
        return 0
      else
        echo -e "nn The passwords don't match, try again please... "
        korrekt4
      fi
    }
    korrekt4
}

##Proof, if DB exists, otherwise create it
create_db(){
  if [ `mysql -u root -h $dbhost -p$rootpw -e "show databases"|grep -c $db` = 1 ]; then
    echo -e "n The 'solarmax' database is allready existing. Nothing to do here ... "
    else
    echo -e "n A new 'solarmax' database will be created now ... "

    ## create Database
    command1="create database if not exists $db;
    GRANT ALL PRIVILEGES ON $db.* to $newuser@'localhost' IDENTIFIED BY '$userpw';
    GRANT ALL PRIVILEGES ON $db.* to $newuser IDENTIFIED BY '$userpw';
    flush privileges;"

    mysql -uroot -h $dbhost -p"$rootpw" -e "$command1"

    ## create tables
    i=1
    while [ $i -le $anz_wr ]
    do
    command2="use $db;CREATE TABLE IF NOT EXISTS $tabelle$i (
    created timestamp NOT NULL default CURRENT_TIMESTAMP,
    kdy int(11) unsigned default NULL,
    kmt int(11) unsigned default NULL,
    kyr int(11) unsigned default NULL,
    kt0 int(11) unsigned default NULL,
    tnf int(11) unsigned default NULL,
    tkk int(11) unsigned default NULL,
    pac int(11) unsigned default NULL,
    prl int(11) unsigned default NULL,
    il1 int(11) unsigned default NULL,
    idc int(11) unsigned default NULL,
    ul1 int(11) unsigned default NULL,
    udc int(11) unsigned default NULL,
    sys int(11) unsigned default NULL,
    PRIMARY KEY  (created)
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8;"

    mysql -u$newuser -h $dbhost -p"$userpw" -e "$command2"
    i=`expr $i + 1`
    done

    ## show tables and status
    command3="show databases;
    use $db;
    show tables;
    status;"

    mysql -u$newuser -h $dbhost -p"$userpw" -e "$command3"

  fi
}

## ask for debugging
ask_debug() {
echo -n -e "nn Shall debugging be enabled? (y/n) [N] "
read debug
if [ -z $debug ]; then
DEBUGENABLE=0
else
case "$debug" in
y|n)
if [ $debug == "y" ]; then
DEBUGENABLE=1
else
DEBUGENABLE=0
fi
return 0
;;
*)
echo -e "nEither use y or n for your choice, please."
ask_debug
;;
esac
fi
}

## compile logger and move into filesystem
compile_logger(){
mkdir -p $instpath/logger-bin
gcc -W -Wall -Wextra -Wshadow -Wlong-long -Wformat -Wpointer-arith -rdynamic -pedantic-errors -std=c99 -o $instpath/logger-bin/smw-logger $instpath/logger-src/smw-logger.c -lmysqlclient
cp -f $instpath/logger-bin/smw-logger /usr/local/bin/
}

#Creation of config-file
config_file_logger(){
echo -e "nn Define a logging interval in seconds here (60 might be a good choice) ... n"
echo -n " Logging interval: "
read loginterval

echo -e "nn LAN-Settings for 1st inverter"
echo -e " -------------------n"
echo -n " Hostname or IP: "
read invhost
echo -n " Port          : "
read invport

mkdir -p /usr/local/etc
cp $instpath/example-config/smw-logger.conf $conffile
chmod 0600 $conffile
chown root.root $conffile
sed -e "s/Debug=0/Debug=$DEBUGENABLE/"
-e "s/Loginterval=60/Loginterval=$loginterval/"
-e "s/DBhost=localhost/DBhost=$dbhost/"
-e "s/DBtabprefix=log/DBtabprefix=$tabelle/"
-e "s/DBname=solarmax/DBname=$db/"
-e "s/DBuser=solaruser/DBuser=$newuser/"
-e "s/DBpass=userpassword/DBpass=$userpw/"
-e "s/Hostname=192.168.178.35/Hostname=$invhost/"
-e "s/Hostport=12345/Hostport=$invport/"
-e "s/NumberOfInverters=1/NumberOfInverters=$anz_wr/"
$conffile > atempfile
mv atempfile $conffile

echo -e "nn If any of the settings above was incorrect or should change in the future, "
echo -e " please edit the file '$conffile' to change these settings.n"
}

#activation and start of the smw-logger
activation(){
cp -f $instpath/init.d/solarmax-logger /etc/init.d/
/etc/init.d/solarmax-logger start
insserv solarmax-logger >/dev/null 2>&1
chkconfig solarmax-logger >/dev/null 2>&1
update-rc.d solarmax-logger defaults >/dev/null 2>&1

if [ `cat /etc/crontab| grep -c 'solarmax-logger'` = 0 ]; then
echo "00 4 * * *  root  /etc/init.d/solarmax-logger start" >> /etc/crontab
echo "00 23 * * *  root  /etc/init.d/solarmax-logger stop" >> /etc/crontab
fi
}

#Creation of Web
create_web(){
mkdir $instpath/web-custom
cp -R $instpath/web/* $instpath/web-custom/
echo -e -n "nn Which amount of remuneration do you get per kwh [ EUR, e. g. 0.3914 ] ? "
read earnings
fontpath=`find /usr/share/ |grep DejaVuSansMono.ttf`
sed -e "s/'user'/'$newuser'/"
-e "s/password/$userpw/"
-e "s/0.3405/$earnings/"
-e "s,/usr/share/fonts/truetype/ttf-dejavu/DejaVuSansMono.ttf,$fontpath,"
-e "s/localhost/$dbhost/"
-e "s/'solarmax'/'$db'/"
$instpath/web-custom/solarertrag.php > $instpath/web-custom/atempfile
mv $instpath/web-custom/atempfile $instpath/web-custom/solarertrag.php

sed -e 's/$result1 =///$result1 =/' $instpath/web-custom/drawday.php > $instpath/web-custom/neu.php
sed -e 's///$result =/$result1 =/' $instpath/web-custom/neu.php > $instpath/web-custom/drawday.php

sed -e 's/ $result =/ //$result1 =/' $instpath/web-custom/drawmonth.php > $instpath/web-custom/neu.php
sed -e 's///$result =/$result =/' $instpath/web-custom/neu.php > $instpath/web-custom/drawmonth.php

sed -e 's/ $result =/ //$result1 =/' $instpath/web-custom/drawyear.php > $instpath/web-custom/neu.php
sed -e 's///$result =/$result =/' $instpath/web-custom/neu.php > $instpath/web-custom/drawyear.php

sed -e "s|'user'|'$newuser'|g" -e "s|'password'|'$userpw'|g" -e "s|$wrnum=1|$wrnum=${anz_wr}|g" $instpath/web-custom/analyzer.php  > $instpath/web-custom/atempfile && mv $instpath/web-custom/atempfile $instpath/web-custom/analyzer.php

rm -f $instpath/web-custom/neu.php
echo -e "nn Please enter the project name, which will reside on top of the web pagen"
echo -n " Project name: "
read proname
echo -e "nn Please enter now the url to your web home, if there is one ( e. g. http://www.myweb.com )"
echo -e " Otherwise just hit ENTERn"
echo -n " Web-home: "
read webhome
echo "<?php" > $sitehead
echo "    
/*" >> $sitehead
echo "       Simple solarmax visualizer php program written by zagibu@gmx&#46;ch in July 2010" >> $sitehead
echo "       This program was originally licensed under WTFPL 2 http://sam&#46;zoy&#46;org/wtfpl/" >> $sitehead
echo "       Improvements by Frank Lassowski flassowski@gmx&#46;de in August 2010" >> $sitehead
echo "       This program is now licensed under GPLv2 or later http://www&#46;gnu&#46;org/licenses/gpl2&#46;html" >> $sitehead
echo "    */
" >> $sitehead
echo "   
$title="$proname";" >> $sitehead
if [ 
$anz_wr -eq 1 &#93;; then
 echo "   
$slogan1="unsere Photovoltaik-Anlage";" >> $sitehead
 else
  for i in {1&#46;&#46;100}; do
    if [ 
$i -gt $anz_wr &#93;; then
    break
    fi
    echo "   
$slogan$i="Inverter $i";" >> $sitehead
 done
fi
if [ -z 
$webhome &#93;; then
  echo "   
$link0="http://localhost/";" >> $sitehead
else
  echo "   
$link0="$webhome/";" >> $sitehead
fi

  for i in {1&#46;&#46;100}; do
    if [ 
$i -gt $anz_wr &#93;; then
    break
    fi
echo "   
$link$i="solarertrag&#46;php?wr=$i";" >> $sitehead
 done
echo "" >> 
$sitehead
echo "   
echo "<div id=\"header\">\n";" >> $sitehead
echo "   
echo "<h1><a href=\"" &#46; $link0 &#46; "\">" &#46; $title &#46; "</a></h1>\n";" >> $sitehead
echo "   echo "<h5";" >> $sitehead
  
for i in {1&#46;&#46;100}; do
    
if [ $i -gt $anz_wr &#93;; then
    
break
    
fi
     
echo "   echo "<a href=\"" &#46; $link$i &#46; "\">" &#46; $slogan$i &#46; "</a> ";" >> $sitehead
 
done
echo "   echo "</h5>\n";" >> $sitehead
echo "   echo "</div>\n";" >> $sitehead
echo "?>
" >> $sitehead


echo -e "nn Please enter the root of your web folder or choose one of the following ... "
echo -e "n   1. /srv/www/htdocs"
echo "   2. /var/www"
echo "   3. other choice"
echo "   4. no web-folder now"
echo -e -n "n   Your choice: "
read web_alt
no_web=0
if [ $web_alt -eq "3" ]; then
  echo -e -n "n  Your web root (without ending slash '/' ) : "
  read web_path
  elif [ $web_alt -eq "1" ]; then
  web_path=/srv/www/htdocs
  elif [ $web_alt -eq "2" ]; then
  web_path=/var/www
else
  no_web=1
  echo -e "n No web root was choosen. The web folder will stay undone in the subfolder"
  echo " 'web-custom' of the src folder of this software ..."
fi
if [ $no_web = "0" ]; then
  mkdir -p $web_path/solarmax
  cp -pfR $instpath/web-custom/* $web_path/solarmax
  chown -R wwwrun.www $web_path/solarmax >/dev/null 2>&1
  chown -R www-data.www-data $web_path/solarmax >/dev/null 2>&1
  else
  web_path=no__web
fi
}

conf_uinst(){
echo -e "nn Configuring the uninstall script, residing in the root-folder"
echo -e " of this archive ... n"
sed -e "s,someweb,$web_path," -e "s,somehost,$dbhost," -e "s,somedb,$db," $instpath/bin/SolarmaxWatcher-uninstaller-blank.sh > $instpath/Solarmax_uninstaller.sh
chmod 0777 $instpath/Solarmax_uninstaller.sh
}

function pause(){
  read -p "$*"
}

clear
echo -e "n --------------------------------------------------------------n"
echo "                     Solarmax Watcher $installerversion"
echo -e "                     ----------------------n"
echo "                Installer for the Solarmax Logger "
echo "               and the Solarmax Watcher php-scripts"
echo -e "n --------------------------------------------------------------n"

if [ `whoami` != "root" ]; then
  echo -e "n To execute this script, root privileges are required. So please "
  echo -e " login as root or use the 'sudo' command to start this installer; "
  echo -e " exiting. n"
  exit 1
fi

echo -e "nn To run the logger and the php-watcher some requirements have to "
echo -e " be fulfilled. n"
echo -e " Needed packages: n"
echo "   - GNU C compiler (gcc)"
echo "   - libmysqlclient-devel (containing /usr/include/mysql/mysql.h) "
echo "     (path may differ)"
echo "   - a running Mysql server (may reside on another machine)"
echo "   - a running webserver, e. g. Apache with installed and activated "
echo "     php extension"
echo -e "   - php-modules 'gd' and 'mysql' n"
echo " Press 'q' to quit here and improve your installation before "
echo " installing this software or press any other key to proceed. "
read -s -n 1 go_on
case $go_on in
  q)
    exit 0
    ;;
  *)
    echo -e "n OK, let's go on then ... n"
#    return 0
    ;;
esac

ask_anz
ask_mysql_host
ask_mysqlroot_pw
ask_mysqluser_pw
create_db
ask_debug
compile_logger
config_file_logger
activation
create_web
conf_uinst

echo ""
pause ' Press Enter key to proceed ...'

Offline thecell

  • Global Moderator
  • MVP
  • *
  • Bedankjes
  • -Gegeven: 502
  • -Ontvangen: 212
  • Berichten: 1.370
Re: Zonnepanelen data monitoren met PHP MySQL
« Reactie #3 Gepost op: 22 januari 2013, 08:04:17 »
Volgende keer de CODE tag gebruiken aub.
  • Mijn Synology: DS415+
Geeft iemand een nuttig antwoord? Gebruik de "Bedankt!" knop.

Offline bartmans99

  • MVP
  • *
  • Bedankjes
  • -Gegeven: 19
  • -Ontvangen: 91
  • Berichten: 737
Re: Zonnepanelen data monitoren met PHP MySQL
« Reactie #4 Gepost op: 22 januari 2013, 10:11:30 »
De eenvoudigste manier is om de juiste directory (via SSH/telnet)
./INSTALL.SH
te proberen.

Houd de gegevens van de MySQL server bij de hand (script vraagt om IP en gebruikers/wachtwoord met voldoende rechten om database te kunnen aanmaken).

Eventueel moet je de rechten van INSTALL.SH aanpassen zodat het executable wordt:
chmod 755 INSTALL.SH
en dan
./INSTALL.SH

Offline wizjos

  • Administrator
  • MVP
  • *
  • Bedankjes
  • -Gegeven: 123
  • -Ontvangen: 181
  • Berichten: 1.996
Re: Zonnepanelen data monitoren met PHP MySQL
« Reactie #5 Gepost op: 22 januari 2013, 11:47:47 »
heb je die install.sh al wel eens gestart en de vragen beantwoord?
Wizjos.


DS409+    4 x WD10EADS DSM 4.2-3243       [TEST]
DS214play 1 x WD20EARX DSM 6.1.4-15217-3  [PROD]
DS1513+   5 x WD80EFZX DSM 6.1.4-15217-5  [PROD]
RT1900ac               SRM 1.1.6-6931-1   [PROD]


Is RAID hetzelfde als een backup?
Goeie schijven voor je NAS? Neem Western Digital!

Offline dorustd

  • Bedankjes
  • -Gegeven: 0
  • -Ontvangen: 0
  • Berichten: 3
Re: Zonnepanelen data monitoren met PHP MySQL
« Reactie #6 Gepost op: 22 januari 2013, 22:38:19 »
Heb install.sh kunnen starten in telnet.
Krijg onderstaande foutmelding:

DiskStation> sh ./install.sh
./install.sh: line 378: syntax error: unexpected "<"


 

SMA zonnepanelen uitlezen via bluetooth

Gestart door supermarcieBoard Overige mods

Reacties: 5
Gelezen: 7405
Laatste bericht 10 maart 2013, 09:30:11
door interwad
nas synology taak om zonnepanelen opbrengst naar pvoutput te uploaden

Gestart door michiel_pvBoard Overige software

Reacties: 110
Gelezen: 46015
Laatste bericht 07 april 2024, 22:40:58
door Briolet
SMA sb3000tl-21 Zonnepanelen en Synology DS211j

Gestart door DokmanBoard Overige software

Reacties: 3
Gelezen: 3419
Laatste bericht 07 mei 2013, 20:59:49
door spikehome
blutooth dongle for zonnepanelen

Gestart door pettyBoard Overige 3rd party packages

Reacties: 9
Gelezen: 5012
Laatste bericht 22 april 2012, 16:15:43
door petty
zonnepanelen omvormer onzichtbaar in router

Gestart door SanderunizukiBoard Synology Router

Reacties: 21
Gelezen: 5978
Laatste bericht 21 juli 2016, 21:30:29
door Ds211