Lester Burnham's Blog

Samil Inverter & CurrentCost on RasPi Final…

OK, so after the post Samil Inverter & Current Cost on Raspberry Pi MKII, I still wasn’t satisfied with the one caveat the system had. The fact that if the internet failed, inverter.pl does not cache unsent data. (it does send, but is never received)

In the last few days I had been using trial and error trying to have inverter.pl produce a CSV or log file that I could use with the pvoutput integration service, to upload via it’s csv.ini and I finally succeeded! (no coding experience = miracle). I had to modify the DATE column and create a new TIME column.

This all worked fine, but I noticed I had an issue after a few uploads. Data for ETODAY (enegy column in pvoutput), was in kWh, but pvoutput required it to be in watts, so I needed to multiply by 1000. I did this in the ~/solar/inverter/config.ini

My Hardware details and software version:

Raspberry Pi Model B 512mbRS232 Adapter
Raspbian “2013-09-25-wheezy-raspbian.zip”
CurrentCost CC128 Classic (monitor house usage)
Samil Solar River 1600TL Inverter with rs232 connection
RS232 to RS485 Adapter PL2303 chipset
RS232 serial cable (straight through, not crossover)


Install x11vnc to allow us to run the Raspberry Pi headless (no monitor). I’ll list the directions here just in case the link disappears.

Open a terminal and do the following.

sudo apt-get update
sudo apt-get install x11vnc
x11vnc -storepasswd
cd .config
mkdir autostart
cd autostart
nano x11vnc.desktop

Paste the following into the above terminal

[Desktop Entry]
Exec=x11vnc -forever -usepw -display :0 -ultrafilexfer

To exit & save the file in nano after pasting. Type ctrl+x, then y for yes and enter to save with the above filename x11vnc.desktop

You now need to make sure your Raspberry Pi boots to desktop, ssh is enabled and

hdmi_force_hotplug=1 in /boot/config.txt is set.

To do all of the above, you can run in a terminal:

sudo raspi-config

Thanks to Deepesh Agarwal and megaleecher for the instructions.

Another way to do this is by shutting down the Pi and inserting the SD card into a reader, then mounting and editing /boot/config.txt manually. Now we will connect via VNC and SSH from another computer for the rest of this tutorial. You can complete this on the Pi with a monitor connected, but it may be harder with other USB devices connected.

As a prerequisite to running the below scripts, you will need to install java  and the perl modules for inverter.pl

Open a terminal and run the following:

sudo apt-get install oracle-java7-jdk

Everthing went pretty well except for the mismatch errors when trying to run pvoutput.sh

WARNING: RXTX Version mismatch

Following this Post fixed the problem. Who knows, you might be able to install Oracle Java 1.8 now without any problems. The next thing is to install the prerequisites for the inverter perl scripts

sudo apt-get install libdevice-serial-perl libappconfig-perl libwww-perl

First task was to download the complete set of files for the whole shebang from here solar folder.

Save the solar.zip to your home directory (/home/pi) and extract all the files and folders. You will see three folders inside the solar folder, inverter, logs, pvoutput and a list of commands to paste to your crontab. (pvoutput version is pvoutput.v1.4.7)

You will need to add your pvoutput “API key” & “System ID” to the ~/solar/pvoutput/conf/pvoutput.conf file. Read the install.html file in the pvoutput folder for configuration settings. Make sure the cron_delete.sh, inverter.pl, postpvoutput & pv_start.sh files are executable.

Time to give it all a go. What I did originally was work on one device at a time. With the inverter, I set up the software on windows first to prove the communication, as I didn’t know if I needed a straight through or crossover cable for the RS232. (inverter to adapter, from outside to inside house) Once working in Windows, I knew communication was OK.

Plug the CC128 into the Pi with no other USB devices, open a terminal and run the following. (pvoutput.ini is currently set as /dev/ttyUSB0)

cd /home/pi/solar/pvoutput/bin/
bash pvoutput.sh

If you don’t drop back to a prompt, or see mismatch errors as explained above, everything should be OK. Check out /home/pi/solar/pvoutput/logs/pvoutput.log and check the debugging info. If all is OK, you will see a /home/pi/solar/logs/CC0-yyyy-mm-dd.log file with data.

I then plugged the inverter into the Pi with the CC128 still connected (inverter set on /dev/ttyUSB1 in /home/pi/solar/inverter/config.ini) and ran the following in a new terminal:

cd /home/pi/solar/inverter
perl inverter.pl

If  you see data like the following, you should be OK. There shouldn’t be a problem, unless inverter.pl is not executable or the perl modules didn’t install.

Starting up at 10/01/2014 06:05:29 running on linux …
Initialise Serial Port… port = /dev/ttyUSB1
Send -> req init inverter: 55aa000000000004000103
Send -> req serial: 55aa0000000000000000ff
Recv <- 55aa0000000000800a5331363132394834353603c6
Send -> confirm serial: 55aa0000000000010b53313631323948343536010349 
Recv <- 55aa00010000008101060188
Send -> req version: 55aa000000010103000104


If the above is Ok, you should now see a ~/solar/logs/yyyy-mm-dd.log file with data in it. Leave it running for a while and log in to pvoutput.org and check out your data. Hopefully 🙂

Now we’ll sort out the combination of USB devices. Stop both processes with a ctrl+c and close the terminal. Leave both devices plugged in and reboot. Run both processes again manually and check the terminal for the inverter and the logs for the CC128. If no joy, try either changing the USB devices and reboot again, or change the config files.

Copy and paste the lines below (# m h dom mon dow command) in the /home/pi/solar/crontab file into your users crontab, by opening a terminal and running:

crontab -e

To exit Ctrl+x, then y for yes and enter to close.

The current lines are for the following:

1. cron_delete: deletes the log files in the inverter folder (Second entry in the cron_delete bash script can be removed)
2. Start the inverter at 6.01am (Valid inverter operating hours set at 6.00am – 9.00pm in config). This will run in the background (no terminal)
3. Start the pvoutput service (Not tested yet and checks at 5.00am to see if it’s running, if not, it will start it.) I should run it every 5mins and remove the log. (*/5 * * * *)
4. Delete logs from /solar/logs directory. (Meant to only leave last 2 behind. Leaves 4 or 5) 
30 21 * * * ./solar/inverter/cron_delete > /dev/null
1 6 * * * cd /home/pi/solar/inverter ; perl inverter.pl >> inverter.log 2>&1
* 5 * * * cd /home/pi/solar/pvoutput/bin/ ; bash pv_start.sh >> pv_start.log 2>&1
* 22 * * * find /home/pi/solar/logs/*.log -mtime +2 -exec rm {} \;

I would hold off on the autostart section below until you know pvoutput.sh is uploading data correctly. You can do testing by just running bash pvoutput.sh from a terminal and checking the pvoutput.log via SSH or in a terminal in real time by running this command: (to exit Ctrl+C)

tail -f ~/solar/pvoutput/logs/pvoutput.log

I autostart pvoutput.sh at desktop startup by calling it from another file with some fancy stuff that checks it stays running, in this case called pvoutput_autostart.sh. To create the file type:

nano /home/pi/solar/pvoutput/bin/pvoutput_autostart.sh

Add this text below and save.


ps -ef|grep -v grep|grep pvoutput.sh > /dev/null

if [ $? != 0 ]
cd /home/pi/solar/pvoutput/bin;
DISPLAY=:0.0 /usr/bin/x-terminal-emulator -e bash pvoutput.sh >/home/pi/solar/pvoutput/bin/setsid.log

Now create the autostart file in /home/pi/.config/lxsession/LXDE/. Do this by running

nano /home/pi/.config/lxsession/LXDE/autostart

and entering the following and save:

@bash /home/pi/solar/pvoutput/bin/pvoutput_autostart.sh

I would comment out the above with a # until you know pvoutput.sh is uploading data correctly

The pv_start.sh is currently un-tested, but should be OK. It will also run in the background and write data to ~/solar/pvoutput/bin/pv_start.log

The inverter.pl will run in the background when started by cron, but you will see the /solar/inverter/inverter.log filling with data if within operating hours. A handy command to check if it is running. Use for pvoutput also.

ps -ef | grep -v grep | grep inverter.pl
ps -ef | grep -v grep | grep pvoutput.sh 

To kill the processes use the following: (13903 being the process listed by previous command)

sudo kill -s 15 13903 

This is still only more than a week running, so use at your own risk 🙂

UPDATED: 04/03/2017

I hope I’ve captured all the improvements I’ve made over time, but it is super reliable now and has up-times longer than 365 days when running on a UPS. Hope you get the same result 🙂

Leave a Reply