by shell_l_d » Fri Nov 25, 2011 7:23 pm
Suggestions/changes from previous posters... re: auto-startup in morning...
-----------------------------------------------------------------------
philcolbourn... I'll post my code changes once I have tidied it up. I am also thinking about an android app to wake my Eeepc each morning so I don't have to. This way, I can keep my running costs of the monitor to a minimum by making it sleep at night and 'automatically' wake each morning.
-----------------------------------------------------------------------
birdman... It seems that when the script goes into RE-init it doesn't send anything to the inverter. I usually have to stop the script and restart it each morning.
-----------------------------------------------------------------------
gaio... As just stated, i will add SQL support, when i get some spare time, and i hope on moving the project to some 'forge' sites, i dont't like forums, i'm an old-fashoned guy.
linux cronjob
*/5 * * * * ~/solar/solar &
#!/bin/bash
linux wrapper script
# Some variable
#
BASEDIR="/home/gaio/solar"
DATA=$(date +%Y%m%d)
# crude locking...
#
if [ -f "$BASEDIR/solar.lock" ]; then
spid=$(cat "$BASEDIR/solar.lock")
if [ -d "/proc/$spid" ]; then
exit 0
else
rm -f "$BASEDIR/solar.lock"
fi
fi
echo $$ > "$BASEDIR/solar.lock"
# call the script... we need to cd to the dir to correctly read the .ini files.
#
cd $BASEDIR
$BASEDIR/inverter.pl >> $BASEDIR/inverter-$DATA.log 2>&1
# Unlock
#
rm -f "$BASEDIR/solar.lock"
exit 0
-----------------------------------------------------------------------
birdman... windows wrapper script
REM @echo off
c:
cd ../../../../../../../
cd solar
:VARIABLES
title Solar Check
@echo ***Solar Check***
@echo off
set BASEDIR="C:\Solar"
set LOCKFILE=%BASEDIR%\solar.lock
:LOCKCHECK
if exist %LOCKFILE% goto :END
:CREATELOCK
echo "Running" >> %LOCKFILE%
perl inverter.pl "COM1"
:REMOVELOCK
del %LOCKFILE%
:END
exit
Just one thing that I thought about though. It may not be required on Windows with scheduled tasks. If I just create a job to run every 5 minutes then it shouldn't run again until the previous instance stops running. Will have to check it out.
-----------------------------------------------------------------------
fogger... The only problem that remains is that the script doesn't communicate with the inverter in the morning after it's been left running overnight. This looks like the same problem as one mentioned much earlier in this thread, described as the script sending only the first two requests, but no more. The problem is caused by closing and re-opening the serial port when it times out waiting for a response from the inverter. This shouldn't ever really be necessary, and in this case it seems to break things. You can confirm this by commenting out the &closeSerialPort; and &initialiseSerialPort; lines in the writeReadBuffer sub in inverter.pl. If there was a problem with a serial port device itself, I'd expect to get the errors when trying to read or write to the $serial port device itself. Not a timeout. When a timeout does occur, we're better off just flushing the receive buffer and re-sending the existing request again until the maximum number of retries is reached. If the number of retries is reached, then you would need to go through the full inverter initialisation again. You have no way of knowing what state the inverter is in when it stops communicating. Although I'm a software developer, I'm not familiar enough with perl to make anything but simple changes. This is the modified writeReadBuffer function I'm using that just flushes the buffer and re-sends the last request. This should handle a simple garbled response from the inverter, but it won't help re-initialise the inverter each morning.
#
# check if timeout was reached
#
if ($timeout==0) {
# print "Re-Init...\n";
# &closeSerialPort;
# &initialiseSerialPort;
$timeout = $config->secs_timeout;
$reinit++;
print "Waited " . $config->secs_timeout . " seconds and never saw $readPattern\n";
#die "Waited " . $config->secs_timeout . " seconds and never saw $readPattern\n";
$chars=0;
$buffer="";
$buffer2="x";
print "Re-sending request - Retry $reinit \n";
&writeToPort(&convHexToRaw($writeString));
}
-----------------------------------------------------------------------
philcolburn... My change log is not up-to-date, but my dated comments are reliable. All this relies on
* adding some entries into a root's crontab (provided);
* a script to set my eeepc's RTC (provided);
* a script to start my inverter_phoenix.pl version (provided) with extra bits for USB-RS232 loading/unloading, setting RTC to sleep, and ensuring WiFi is working;
* my version of inverter_phoenix.pl (provided); and
* my version of pvoutput.pl that uploads inverter temperature for something different to do (provided).
Note: I published a state diagram earlier. This has changed a little based on what I have learnt since and is reflected in my code.
-----------------------------------------------------------------------
philcolburn... I'm not sure how to integrate any of my work with shell's work; it is probably up to shell to take any thing from my hack that is useful to others. Shell's work supports lots of inverters and it is used by many people. Therefore experimental code would naturally be treated with caution. I also suspect that most users may have a simple design that does not attempt to minimise energy consumption between polls or even overnight.
-----------------------------------------------------------------------
gaio...why keep the script running when there's no sun? AFAIK sunset and sunrises are know and predictable, giving some input data.
$t = time();
$i = date_sun_info($t, 45.925, 12.7323);
if ( ( $t > $i['sunrise'] ) && ( $t < $i['sunset'] ) ) {
exit(0);
} else {
exit(1);
}
-----------------------------------------------------------------------
warkus (Mark)...When the inverter turns off at night, if setting the max_timeout to -1 so it infinitely loops until the sun comes up the next day, it will NOT reinitialise the inverter. The code loops the &initialiseSerialPort sub routine which does not receive a response from the inverter. I have had to take a section of the &initialiseInverter sub routine and add it to the timeout loop where it continually tries to re-connect. In doing this it now works and receives data from the inverter as soon as it turns back on in the morning. I can post the changes if you like, as I am only going off the top of my head at present. Apart from the Serial number being in Hex, when its normally not, it works PERFECTLY, and I am very happy.
-----------------------------------------------------------------------
Regards
Shell 