CMS2000 inverter RS232 Serial Port Hack. (CMS 2000 RS232)..

The latest and greatest cells. New technologies, anything on the forefront of solar tech.

Re: CMS2000 inverter RS232 Serial Port Hack. (CMS 2000 RS232

Postby shell_l_d » Sat Nov 12, 2011 7:19 pm

Excellent :)

So hopefully the data_*h (high bit) configs come in to play...

extract from config.ini
Code: Select all
[data_etotalh]
hexcode  = "47"         # "07" for 3phase
multiply = 256
measure  = "kWh"
index    = -1
descr    = "Accumulated Energy (high bit)"

[data_etotall]
hexcode  = "48"         # "08" for 3phase
multiply = 0.1
measure  = "kWh"
index    = -1
descr    = "Accumulated Energy (low bit)"

[data_htotalh]
hexcode  = "49"         # "09" for 3phase
multiply = 256
measure  = "hrs"
index    = -1
descr    = "Working Hours (high bit)"

[data_htotall]
hexcode  = "4a"         # "0a" for 3phase
multiply = 1
measure  = "hrs"
index    = -1
descr    = "Working Hours (low bit)"
Last edited by shell_l_d on Sat Nov 12, 2011 7:24 pm, edited 1 time in total.
Regards
Shell :)
shell_l_d
 
Posts: 102
Joined: Fri Jan 28, 2011 9:02 am

Re: CMS2000 inverter RS232 Serial Port Hack. (CMS 2000 RS232

Postby shell_l_d » Sat Nov 12, 2011 7:24 pm

& hopefully this code will be correct...

inverter.pl extract:
Code: Select all
#######################################################################
#
# Write certain inverter data to a csv file
#
sub writeToFile() {
  my $logfile = getLogFileName();
  my $rrdfile = getRrdFileName();

  #
  # open logfile in 'append' mode
  #
  if ( open(LOGFILE, ">>$logfile") ) {
    print "Logging to: $logfile\n";

    #
    # add file header to logfile (if file exists & is empty)
    #
    if ( -z $logfile ) {
#      print LOGFILE "DATE,TIMESTAMP,TEMP,VPV,IAC,VAC,FAC,PAC,ETOTAL,HTOTAL,MODE,ETODAY\n";
      print LOGFILE "DATE,TIMESTAMP,TEMP,VPV,IAC,VAC,FAC,PAC,ETOTAL,HTOTAL,MODE,ETODAY" .
                    ",ETOTALH,HTOTALH,ERR_GV,ERR_GF,ERR_GZ,ERR_TEMP,ERR_PV1,ERR_GFC1,ERR_MODE,UNK10\n";
    }

    my $etotal = ($HoH{ETOTALL}{VALUE} + $HoH{ETOTALH}{VALUE});
    my $htotal = ($HoH{HTOTALL}{VALUE} + $HoH{HTOTALH}{VALUE});
    if ($config->flags_debug) {
      print "etotal=$etotal   htotal=$htotal\n";
    }
Regards
Shell :)
shell_l_d
 
Posts: 102
Joined: Fri Jan 28, 2011 9:02 am

Re: CMS2000 inverter RS232 Serial Port Hack. (CMS 2000 RS232

Postby JinbaIttai » Sun Nov 13, 2011 3:58 pm

It just ticked over, and the output went from
aaaa0001010001822801b207d2002309fb138c0358ffff0000ffff000021830001000000000000000000000000000000000a4f
to
aaaa0001010001822801b307b2002209f1138d035affff0001000000002183000100000000000000000000000000000000082b

which means you were right, hexcode 47 represents the high bits. :)

Nice work, Shell!
User avatar
JinbaIttai
 
Posts: 29
Joined: Tue Feb 09, 2010 11:13 pm

Re: CMS2000 inverter RS232 Serial Port Hack. (CMS 2000 RS232

Postby shell_l_d » Sun Nov 13, 2011 5:50 pm

lol no prob, but it's all based on your nice work in the first place, for creating the initial code :)
Regards
Shell :)
shell_l_d
 
Posts: 102
Joined: Fri Jan 28, 2011 9:02 am

Re: CMS2000 inverter RS232 Serial Port Hack. (CMS 2000 RS232

Postby wildcat » Thu Nov 24, 2011 3:12 pm

Hi all,

Could someone kindly point me in the right direction or help me with installing the perl script for win7 64bit.
I currently have a KLNE Sunteams Inverter which I would like to use the perl script to upload to PVoutput.
I have installed active perl on my Win7 64bit machine, installed "using ppm.bat install" the Appconfig perl module but the module Win32::SerialPort fails as no package for Win32::SerialPort can be found but is needed for serial comms.
Is it because I'm running Win7 64bit??

Please help.
Thanks
Nick
wildcat
 
Posts: 9
Joined: Thu Nov 24, 2011 2:53 pm

Re: CMS2000 inverter RS232 Serial Port Hack. (CMS 2000 RS232

Postby shell_l_d » Thu Nov 24, 2011 3:35 pm

Good question wildcat... I did a really quick google & found this: http://openmoco.org/node/176
whereby the user installed the 32bit version on a 64bit machine to get around the problem you are having.

http://www.activestate.com/activeperl/downloads
http://code.activestate.com/ppm/Win32-SerialPort/
Regards
Shell :)
shell_l_d
 
Posts: 102
Joined: Fri Jan 28, 2011 9:02 am

Re: CMS2000 inverter RS232 Serial Port Hack. (CMS 2000 RS232

Postby wildcat » Thu Nov 24, 2011 8:10 pm

Thanks Shell I had to use activeperl 5.12 w32 version, Activeperl 5.14 32bit or 64bit doesn't seem to have W32:SerialPort
So far the perl script is able to communicate to my KLNE Inverter and get the updated info from it.
However it won't upload to pvoutput.org, it says "Sending to pvoutput.org" but then says "Couldn't submit data to pvoutput.org:401 unauthorized".
I have my API key, System ID and Inverter Serial number in pvoutput.pl. Config.ini is set for 5 minute intervals.
Also pvoutput.org is set for API enabled and 5 minute update intervals.
Is there anything else I may have left out?

Thanks
Wildcat
wildcat
 
Posts: 9
Joined: Thu Nov 24, 2011 2:53 pm

Re: CMS2000 inverter RS232 Serial Port Hack. (CMS 2000 RS232

Postby shell_l_d » Thu Nov 24, 2011 8:31 pm

So there's definitely quote marks around the 3 settings in pvoutput.pl?
Can you double check the entries in pvoutput.pl exactly match those in pvoutput.org?

Extract from README.txt
Code: Select all
5) Setup your pvoutput settings per http://pvoutput.org/help.html#api

6) Open pvoutput.pl in notepad and enter your details for SERIAL_NUM, API_KEY & SYSTEM_ID
   per your pvoutput settings in step 3.


Extract from pvoutput.pl
Code: Select all
my @PVOUTPUT = (
   {
      SERIAL_NUM    => "1234567890",
      API_KEY       => "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
      SYSTEM_ID     => "XXX",
   },
);
Regards
Shell :)
shell_l_d
 
Posts: 102
Joined: Fri Jan 28, 2011 9:02 am

Re: CMS2000 inverter RS232 Serial Port Hack. (CMS 2000 RS232

Postby shell_l_d » Thu Nov 24, 2011 8:37 pm

Also have a look at the output... does it look correct, eg:

Extract from README.txt ... 0123456789 should be whatever your inverter's serial number is.
Code: Select all
PVOUTPUT as at 21/05/2011 09:57:29 ...
  ran: perl pvoutput.pl 580 778 20110521 09:57 0123456789
Sending to PVOUTPUT [ d => 20110521, t => 09:57, v1 => 580, v2 => 778 ]


Extract from config.ini ... you could set debug to 1 to help troubleshoot
Code: Select all
#-------
# flags
#-------

[flags]
debug           = 0             # 0 = NO, 1 = YES
use_pvoutput    = 1             # 0 = NO, 1 = YES       to export data to http://pvoutput.org
use_rrdtool     = 1             # 0 = NO, 1 = YES       to export data to rrdtool for graphing
Regards
Shell :)
shell_l_d
 
Posts: 102
Joined: Fri Jan 28, 2011 9:02 am

Re: CMS2000 inverter RS232 Serial Port Hack. (CMS 2000 RS232

Postby wildcat » Fri Nov 25, 2011 11:14 am

@shell

Yep definitely quote marks around the 3 settings in pvoutput.pl and matches pvoutput.org.
Output appears correct similar to that in the readme.txt

I have set debug to 1 but doesn't give any more info than can't submit unauthorized 401.
How to I check whether the HTTP header with API key and System ID being sent to pvoutput.org is correct?

Thanks
wildcat
 
Posts: 9
Joined: Thu Nov 24, 2011 2:53 pm

Re: CMS2000 inverter RS232 Serial Port Hack. (CMS 2000 RS232

Postby shell_l_d » Fri Nov 25, 2011 12:09 pm

You could turn on the DEBUG_SCRIPT flag in pvoutput.pl I guess & manually call it from the command line...

Extracts from pvoutput.pl
Code: Select all
# Usage examples:
#       perl pvoutput.pl 5500 1813 20110307 12:15 1234567890
#
# Arguments:
#  $ARGV[0] = (ETODAY) watt hrs exported so far today
#  $ARGV[1] = (PAC) current watts
#  $ARGV[2] = date (YYYYMMDD)
#  $ARGV[3] = time (HH:MM)
#  $ARGV[4] = inverter serial number - in case of multiple inverters

use constant {
    DEBUG_SCRIPT         => 0,      # 0 = NO, 1 = YES
    LIVE_DATA_URL        => "http://pvoutput.org/service/r1/addstatus.jsp",
};
Regards
Shell :)
shell_l_d
 
Posts: 102
Joined: Fri Jan 28, 2011 9:02 am

Re: CMS2000 inverter RS232 Serial Port Hack. (CMS 2000 RS232

Postby shell_l_d » Fri Nov 25, 2011 12:19 pm

http://pvoutput.org/help.html#api > Common Errors shows 3 different types of the 401 unauthorised error... which one is yours please?

* Unauthorized 401: Missing system information (X-Pvoutput-SystemId)
The required parameter X-Pvoutput-SystemId or sid is missing from the request

* Unauthorized 401: Missing, invalid or inactive api key information (X-Pvoutput-Apikey)
The API key is missing in the header request or the API key is invalid or the API key has not been enabled

* Unauthorized 401: System Id [id] is not in your profile
The System-Id provided in the header does not match any of the systems in your profile
Regards
Shell :)
shell_l_d
 
Posts: 102
Joined: Fri Jan 28, 2011 9:02 am

Re: CMS2000 inverter RS232 Serial Port Hack. (CMS 2000 RS232

Postby wildcat » Fri Nov 25, 2011 12:38 pm

Sorry shell I wish I knew which type of 401 error it was also.
I have uploaded a screen dump of the problem.
Thanks
Attachments
KlnePerl.bmp
wildcat
 
Posts: 9
Joined: Thu Nov 24, 2011 2:53 pm

Re: CMS2000 inverter RS232 Serial Port Hack. (CMS 2000 RS232

Postby shell_l_d » Fri Nov 25, 2011 1:44 pm

I can see the problem, your serial number is being stored as decimal instead of hexadecimal, I'll fix it up shortly :)

Being stored as: 41354853323136303836
Instead of: A5HS216086

Can you confirm the serial number stored in pvoutput.org is the latter please?
Regards
Shell :)
shell_l_d
 
Posts: 102
Joined: Fri Jan 28, 2011 9:02 am

Re: CMS2000 inverter RS232 Serial Port Hack. (CMS 2000 RS232

Postby shell_l_d » Fri Nov 25, 2011 2:11 pm

try this one :)

Code: Select all
# AS AT 25Nov2011
# + editions by shell_l_d:
#          + edited calcReqConfSerial() - fixed $HASH{SERIAL} = was hex not decimal (KLNE fix) & added print SERIAL.

sub calcReqConfSerial() {
  ...
  $HASH{SERIAL} = pack ("H*", $hexSerial);
  ...
  if ($config->flags_debug) {
    print "hexSerial=$hexSerial\n";          # decimal string
    print "SERIAL=$HASH{SERIAL}\n";          # hexadecimal string, for pvoutput.org
  }
Attachments
inverter.pl.txt
25Nov2011 - KLNE fix x 1
(54.71 KiB) Downloaded 35 times
Regards
Shell :)
shell_l_d
 
Posts: 102
Joined: Fri Jan 28, 2011 9:02 am

Re: CMS2000 inverter RS232 Serial Port Hack. (CMS 2000 RS232

Postby wildcat » Fri Nov 25, 2011 2:14 pm

I do have my serial in hexadecimal A5H216086 in the pvoutput.pl script but I can't find anywhere in http://www.pvoutput.org settings that require you to include your serial. The only relevant details are the API Key and System ID in the settings page.
I'll give the new script a go.

Thanks
wildcat
 
Posts: 9
Joined: Thu Nov 24, 2011 2:53 pm

Re: CMS2000 inverter RS232 Serial Port Hack. (CMS 2000 RS232

Postby wildcat » Fri Nov 25, 2011 2:32 pm

Shell YOU ROCK!!
That new script fixed it!
Thank you very much for your help.

All I need to do now is check whether the serial comms will work/reinitialize when the inverter turns back on in the morning with the PC running all night.
I'll have to have another look through this thread, I think Birdman solved this issue with his Klne inverter.

Thanks again Shell

Cheers

wildcat
wildcat
 
Posts: 9
Joined: Thu Nov 24, 2011 2:53 pm

Re: CMS2000 inverter RS232 Serial Port Hack. (CMS 2000 RS232

Postby shell_l_d » Fri Nov 25, 2011 4:07 pm

lol, no prob... that's next on the agenda, to fix that... 2 ppl have posted fixes so far but i haven't put their code in yet... I'll have to go back & find the posts :)

Oh yes you are right, the serial # isn't on pvoutput.org ;)
Regards
Shell :)
shell_l_d
 
Posts: 102
Joined: Fri Jan 28, 2011 9:02 am

Re: CMS2000 inverter RS232 Serial Port Hack. (CMS 2000 RS232

Postby wildcat » Fri Nov 25, 2011 4:21 pm

Cool that'll be great

Thanks
wildcat
 
Posts: 9
Joined: Thu Nov 24, 2011 2:53 pm

Re: CMS2000 inverter RS232 Serial Port Hack. (CMS 2000 RS232

Postby 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 :)
shell_l_d
 
Posts: 102
Joined: Fri Jan 28, 2011 9:02 am

PreviousNext

Return to Tech Talk.

Who is online

Users browsing this forum: No registered users and 0 guests

cron