Central Queensland Linux User Group

  • home
  • faq's
  • hints, help and information
  • links
  • linux programming
  • media
  • events
  • about us
Home

Publishing Solar River inverter stats using a Raspberry PI computer

belly — Sun, 2013-06-09 17:36

I thought I would document how I managed to get solar stats from my Solar River 5.0 KW inverter (SR5KTLA1 - Manufacture SAMILPOWER) using a mini Linux computer (Raspberry PI) and publishing the data to pvoutput.org.  See http://pvoutput.org/intraday.jsp?id=22304&sid=20196 for “my” solar stats.

Acknowledgements

Before providing any details, I would like to acknowledge the following information/people which assisted greatly to get something up and running:

  • http://whirlpool.net.au/wiki/solar_software - central location for links to solar software and protocols used by various inverters
  • http://www.solarfreaks.com/cms2000-inverter-rs232-serial-port-hack-cms-2000-rs232-t271-240.html#p3410 – Provided the  “perl scripts” that I used to capture data from a RS-232 connection on the inverter.  inverter_monitor_120308.zip provides the downloadable package containing the scripts, etc.  A special to the developers who helped to develop the inverter and pvoutput perl scripts.  These include (as listed on within the *.pl files)
    • jinba @ jinba-ittai.net
    • Eric Sandeen
    • shell_l_d
    • mmcdon23
    • nigol2
    • slampt

Okay – to obtain information from my Solar River 5.0 KW inverter, I needed a computer with a RS-232 connection (I believe the newer versions of the inverter have wireless capabilities). To ensure the computer was low in power usage and could do the job, I decided to use a “Raspberry PI” computer.  These things are great - they are small, fairly cheap and because it runs Linux, it is quite powerful!

Image obtained from "http://element14.com"!

Some useful links for Raspbery Pi’s and various components that was used to build the system:

  • http://www.raspberrypi.org/faqs
  • I purchased my Raspberry Pi from Element 14 (some various Raspberry PI links)
    • http://au.element14.com/jsp/search/productdetail.jsp?SKU=2217851&MER=MER-BN-PR-PG-2217851
    • http://au.element14.com/jsp/search/productdetail.jsp?SKU=2217158&MER=MER-BN-PR-PG-2217158
    • http://downloads.element14.com/raspberryPi3.html?SKU=2191863&MER=MER-BN-PR-PG-2191863
  • Wireless USB dongle (needed to talk to home network via WIFI)
    • http://www.ebay.com.au/itm/Raspberry-Pi-compatible-802-11b-g-n-Wireless-USB-Network-Adapter-LAN-Wifi-Dongle-/251276177081?pt=AU_Components&hash=item3a813a2eb9
  • I had trouble with this USB 2.0 to RS232 SERIAL Cable (needed to connect to solar inverter) - as the system kept "locking up" when the inverter would first start (first light) or when it would stop (ie, no more sun) - http://www.ebay.com.au/itm/USB-2-0-to-RS232-SERIAL-Cable-9PIN-9-PIN-DB9-Adapter-Cord-PDA-GPS-XP-VISTA-/300842105372?ssPageName=ADME:L:OC:AU:3160
  • The more expensive USB 2.0 to RS232 SERIAL Cable, in which I have had no issues was a "ATEN UC-232A USB to Serial Adapter".  I obtain this adaptor cable from http://www.pccasegear.com/index.php?main_page=product_info&products_id=3590&cPath=625&utm_source=googlebase&utm_medium=cse&utm_campaign=export_feed&gclid=CNj-38qN6rcCFUUipQodVnoAkg#googlebase 
  • Fedora 17 – remix (Operating System used - this is my preferred Linux distribution, but should work with other Linux distributions)
    • https://fedoraproject.org/wiki/Raspberry_Pi

Image obtained from "http://element14.com"!

Setup instructions

With the default image installed (Fedora 17 Remix) and wireless configured to the home network, this provided me with a base configuration to work with.

I had to installed additional packages so the RS232 device could be communicated to and the various applications required.

yum install libserializer.noarch perl-Device-SerialPort conserver conserver-client perl-YAML-LibYAML 

yum install perl-libwww-perl perl-AppConfig ntp

To ensure the correct time and date, the ntpd service needs to be enabled.  To do this, issue the following commands (ensure you have root permissions to do this):

service ntpd start 

chkconfig ntpd on 

ntpq -p

Once the correct time is configured, we can download the “solar” software.  This can be done by:

wget http://www.solarfreaks.com/download/file.php?id=1010&sid=77ed169611d8e8d83195fff07ef5d11e

Rename the file to inverter_monitor_120308.zip

mv file.php\?id\=1010 inverter_monitor_120308.zip

Then unzip the software

$ unzip inverter_monitor_120308.zip
    Archive:  inverter_monitor_120308.zip
   creating: solar/
  inflating: solar/config.ini
   creating: solar/configs/
  inflating: solar/configs/config_klne.ini
  inflating: solar/configs/config_phoenixtec.ini
  inflating: solar/configs/config_samilpower.ini
  inflating: solar/create_rrd.pl
  inflating: solar/inverter.pl
extracting: solar/MonitorInverter.bat
  inflating: solar/pvoutput.pl
  inflating: solar/README.txt
  inflating: solar/VersionInfo.txt

change to the directory

cd solar

You need to change to configure file to suit the “samilpower inverter”.  Overwrite the current config.ini file with the config_samilpower.ini found in the (configs) directory.

  • cp configs/config_samilpower.ini config.ini

Now, issue the following command and see if you can connect to the inverter (note you will need to issue this command during 5am – 10pm, as these times are set as valid poll times).

  • perl inverter.pl /dev/ttyUSB0

You should get something like the following

Starting up at 04/06/2013 08:03:27 running on linux ...
Initialise Serial Port... port = /dev/ttyUSB0
Send -> req init inverter: 55aa000000000004000103
Send -> req serial: 55aa0000000000000000ff
Recv <- 55aa0000000000800a5335303131383234313603a8
Send -> confirm serial: 55aa0000000000010b5335303131383234313601032b
Recv <- 55aa00010000008101060188
Send -> req version: 55aa000000010103000104
Recv <- 55aa000100000183403120203436303056312e3030536f6c6172526976657220352e304b5753414d494c504f5745522020202020205335303131383234313600000000000033363030101d
* Version info:
asciiVers=Uª@1  4600V1.00SolarRiver 5.0KWSAMILPOWER      ##################
CAPACITY : 4600
FIRMWARE : V1.00
MANUF    : SAMILPOWER
MODEL    : SolarRiver 5.0KW
OTHER    : 3600
SERIAL   : ##<Your serial number>##
Send -> req param format: 55aa000000010101000158
Recv <- 55aa00010000018101000183
* Parameter Format:
dataToFollow = hex(01) = 1
 9 = 00
Send -> req params: 55aa00000001010400015b
Recv <- 55aa00010000018401000186
* Parameters:
Send -> req data format: 55aa000000010100000101
Recv <- 55aa00010000018014000104090a0c111213161718313233343536373803d8
* Data Format:
dataToFollow = hex(14) = 20
 9 = 00 = TEMP     =  0 = Internal Temperature
10 = 01 = VPV1     =  1 = Panel 1 Voltage
11 = 04 = IPV1     =  2 = Panel 1 DC Current
12 = 09 = ETOTALH  =  3 = Accumulated Energy (high bit)
13 = 0a = HTOTALL  =  4 = Working Hours (low bit)
14 = 0c = ETODAY   =  5 = Accumulated Energy Today
15 = 11 = MODE     =  6 = Operating Mode
16 = 12 = HTOTALH  =  7 = Working Hours (high bit)
17 = 13 = ERR_GV   =  8 = Error message: GV fault value?
18 = 16 = ERR_GF   =  9 = Error message: GF fault value?
19 = 17 = ERR_GZ   = 10 = Error message: GZ fault value?
20 = 18 = ERR_TEMP = 11 = Error message: Tmp fault value?
21 = 31 = IAC      = 12 = Grid Current
22 = 32 = VAC      = 13 = Grid Voltage
23 = 33 = FAC      = 14 = Grid Frequency
24 = 34 = PAC      = 15 = Output Power
25 = 35 = ERR_PV1  = 16 = Error message: PV1 fault value?
26 = 36 = ETOTALL  = 17 = Accumulated Energy (low bit)
27 = 37 = ERR_GFC1 = 18 = Error message: GFC1 fault value?
28 = 38 = ERR_MODE = 19 = Error mode?
Send -> req data as at 04/06/2013 08:03:34 : 55aa000000010102000103
Recv <- 55aa0001000001822800c90ae70025000017b20105002c00000000000000000000002a097d1390044c00019e7800000000073f
* Data:
TEMP    :     20.1 deg C = Internal Temperature
VPV1    :    279.1 V     = Panel 1 Voltage
IPV1    :      3.7 A     = Panel 1 DC Current
ETOTALH :        0 kWh   = Accumulated Energy (high bit)
HTOTALL :     6066 hrs   = Working Hours (low bit)
ETODAY  :     2.61 kWh   = Accumulated Energy Today
MODE    :       44       = Operating Mode
HTOTALH :        0 hrs   = Working Hours (high bit)
ERR_GV  :        0       = Error message: GV fault value?
ERR_GF  :        0       = Error message: GF fault value?
ERR_GZ  :        0       = Error message: GZ fault value?
ERR_TEMP:        0       = Error message: Tmp fault value?
IAC     :      4.2 A     = Grid Current
VAC     :    242.9 V     = Grid Voltage
FAC     :    50.08 Hz    = Grid Frequency
PAC     :     1100 W     = Output Power
ERR_PV1 :        1       = Error message: PV1 fault value?
ETOTALL :   4056.8 kWh   = Accumulated Energy (low bit)
ERR_GFC1:        0       = Error message: GFC1 fault value?
ERR_MODE:        0       = Error mode?
*** WARNING Could not open logfile: /tmp/solar/inverter_S501182416_20130604.csv

Hopefully you are able to connect to the device!

I noticed (on my system anyway) that the “ETODAY” value remained constant from my inverter data output.  Also I noticed the value for “MODE” was increasing.  It was determined that I need to swap these values around.

I edited the “config.ini” file with the following changes (replace yellow text with green text)

other           = "/tmp/solar"          # unix/linux

other           = "/location_of_solar_directory/"          # unix/Linux

I changed the pvoutput command to contain the full path, so it can be used within a cron job.

pvoutput        = "perl pvoutput.pl"            # to export data to http://pvoutput.org

pvoutput        = "/bin/perl /location_of_solar_directory/pvoutput.pl"            # to export data to http://pvoutput.org

Swap the “hex” codes for the variables ETODAY and MODE.

[data_etoday]
hexcode  = "0c"
hexcode  = "11"
multiply = 0.01
measure  = "kWh"
index    = -1
descr    = "Accumulated Energy Today"
[data_mode]
hexcode  = "11"
hexcode  = "0c"
multiply = 1
measure  = " "
index    = -1
descr    = "Operating Mode"

I changed the number of retries – as I found if it failed once, it would keep on failing.  But this isn’t necessary, as a "cron job" would re-run the command every 5 minutes.

reinit          = 5             # -1 = infinite num of times (ie dont die)

reinit          = 1             # -1 = infinite num of times (ie dont die)

PVOutput Setup

  • I setup the pvoutput settings per http://pvoutput.org/help.html#api
  • I modified the pvoutput.pl file and enter the details for SERIAL_NUM, API_KEY & SYSTEM_ID

Modifying the inverter.pl script

One thing that I did, that others might choose not to do, is I modified the "inverter.pl" script so it wouldn’t continuously “loop”.  Given I am using a “cron job” in which will executes every 5 minutes, there was no need for the program to “loop”.  The “Yellow” sections were modified with a lead “#”, which commented out that line of code.

   #
   # The main loop starts here
   #
   #while (1) {
     #
     # Request Inverter Data (regular data poll)
     #
     print "Send -> req data as at " . &getDateTime() . " : " . $config->sendhex_data . "\n";
     &setPollTimes();
     $hexResponse = &writeReadBuffer($config->sendhex_data,$config->recvhex_data);
     &parseData($hexResponse) if ($hexResponse ne "");
     &writeToFile();
     #
     # Export data to http://pvoutput.org
     #
     if ($config->flags_use_pvoutput) {
       if ( &isNextPvoutputDue() ) {
         my $date = &getDate_YYYYMMDD();
         my $time = &getTime_HHMM();
         print "PVOUTPUT as at " . &getDateTime() . " ...\n";
         print "  ran: " . $config->scripts_pvoutput . " " . ($HoH{ETODAY}{VALUE} * 1000) . " $HoH{PAC}{VALUE} $date $time $HASH{SERIAL}\n";
         system ($config->scripts_pvoutput . " " . ($HoH{ETODAY}{VALUE} * 1000) . " $HoH{PAC}{VALUE} $date $time $HASH{SERIAL}" );
         &setPvoutputTimes();
       }
     }
     #
     # Sleep until next time data needs to be polled (per $config->secs_datapoll_freq)
     #
     #&sleepTilNextPoll();
     #&sleepTilNextPoll();
#   } #end while

I changed the location of config.ini to contain the full path, so it can be used within a cron job.

$config->file( "config.ini" ) || die "FAILED to open and/or read config file: config.ini\n";

$config->file("/location_of_solar_directory/config.ini" ) || die "FAILED to open and/or read config file: config.ini\n";

runme.sh shell script

I also developed a “shell script” (runme.sh), in which it gather all the data and export the output

/bin/perl /location_of_solar_directory/inverter.pl /dev/ttyUSB0 > /location_of_solar_directory/current.txt

cat /location_of_solar_directory/current.txt >> /location_of_solar_directory/output/`date +%d%m%Y`-output.txt

What this script does, is place the output from the inverter.pl perl script to the current.txt file.  Additionally, so records are kept, I amended the output to a “date stamped” text file, so a record of daily results can be recorded (to the sub directory “output”).

Scheduling the “gathering of solar data” every 5 minutes using as cron job

Issue the command crontab -e and enter the following record into the “cron” schedule.  This will ensure the "runme.sh" shell script is executed every 5 minutes.

*/30 * * * * /location_of_solar_directory/runme.sh



 

I hope this document is of use to some of you.  If you have any comments or feedback - feel free to contact me at : bellfamily <at> gmail.com

  • Special Interest

Navigation

  • Recent posts

User login

  • Request new password

Events

Coming to a meeting soon!
Meetings for 2020
more

Who's online

There are currently 0 users and 0 guests online.
  • home
  • faq's
  • hints, help and information
  • links
  • linux programming
  • media
  • events
  • about us