2009/06/12

Sunny Beam under Ubuntu: SunnyBeamTool v0.6.0

http://sourceforge.net/projects/sunnybeamtool/

The sbtool Perl script of Stefan Arts provides a nice basic setup for accessing the Sunny Beam under Linux. But the Perl solution has some drawbacks: it is quite complex to set up and the codebase, with low-level hex-manipulations, is rather complex to extend, at least for an occasional Perl-developer like me...

With this in mind I translated the sbtool into C language and put it on sourceforge:
http://sourceforge.net/projects/sunnybeamtool/
The basic functionalities are included, but additional feedback, testing and extensions are welcome. Of course use at your own risk ! :-).
$ sudo ./sunnybeamtool
Dev #6: 1587 - 002D -SMA Technologie AG -
Serial Number: 00024383
pac: 0.00 W
e-today: 12.37 kWh
e-total: 1551.83 kWh
$ sudo ./sunnybeamtool -l
Dev #6: 1587 - 002D -SMA Technologie AG -
Serial Number: 00024383
pac: 0.00 W
e-today: 12.37 kWh
e-total: 1551.83 kWh

today:
...
2009-06-11 13:00:00: 756 W
2009-06-11 13:10:00: 888 W
2009-06-11 13:20:00: 569 W
2009-06-11 13:30:00: 205 W
...

last month:
...
2009-06-07: 11.790 kWh
2009-06-08: 10.060 kWh
2009-06-09: 8.480 kWh
2009-06-10: 12.370 kWh

This commandline is much easier and cleaner than running the full blown complex Sunny Data Control application under windows.

If your Sunny Beam doesn't respond to the USB-communication, try this: unplug the USB cable, switch a few times between daily graph and monthly graph, go to the menu and select 'exit', plug the USB cable. This should 'unfreeze' the USB buffer of the Sunny Beam. I never had to remove the batteries from my Sunny Beam device during all my experiments.

If you're still having trouble, send the output of 'sudo sunnybeamtool -l -v' in your bug-reports on sourceforge.

Other background info: I kept the libusb approach, as this allows the application to run in user mode, outside of the kernel. The development is done wih Netbeans 6.5 and Subversion as development platform.

19 comments:

Anonymous said...

Michael,

Great job ! I didn't want to install more bloody drivers on my Windows system. Your litte tool is just what I need, thank you !

I made a little script I run every evening (crontab of root) that collects information from my always on tiny computer (5W consumption):

--------
#!/bin/bash
# Created by Pierre, 2009-08-19
# Collect data from the Sunny Beam device (run as root)

cd /root || exit 1
dt=`date '+%Y%m%d'`
tot=sunnybeamtool/sunnybeam-total.out
day=sunnybeamtool/sunnybeam-$dt.out
mth=sunnybeamtool/sunnybeam-${dt%??}.out
dt=`date '+%Y-%m-%d'`
sunnybeamtool/bin/sunnybeamtool -l | awk -v tot=$tot -v dt=$dt -v day=$day -v mth=$mth '
BEGIN {
OFS="\t"
while (getline <mth) { done[$1 ":"] = 1 }
close(mth)
while (getline <tot) { if($1!=dt) totals = totals $0 "\n" }
close(tot)
}
/^$/ { next }
/^e-total:/ { print totals dt, $2, $3 >tot; next }
/^today:/ { ftoday=1; next }
/^last month:/ { ftoday=0; fmonth=1; next }
ftoday==1 { print $1, substr($2,1,length($2)-1), $3, $4 >day; next }
fmonth==1 && done[$1]!=1 { print substr($1,1,length($1)-1), $2, $3 >>mth }
'

# End of script
--------

I just have noticed that sometimes when I run your tool several times I get an error message "Sunny Beam not accessible. Run this program as root.". I have to unplug/replug the Sunny Beam to fix the issue...

Thanks
Pierre
PS: Sorry for the script autowrap...

Anonymous said...

Michael,

After further tests, on 2 different computers, and after trying to change a little bit your code, I still cannot run twice your tool without unplug/replug.

I wrote an artifact on sourceforge with a log of the runs.

Pierre

SkynetBbs said...

Hi,
i have the same problem on my Ubuntu as well.

@Anonymous what is your "tiny" computer?

I would like it compiled for a fonera2g/n device..that also consumes only 5W and can get "open" plugins you could even let it "tweet" the results :-)

Unknown said...
This comment has been removed by the author.
Unknown said...

Can you make the source available so that I can compile it for my ARM SheevaPlug?

http://www.earth.org.uk/note-on-SheevaPlug-setup.html

Rgds

Damon

Unknown said...

Found the source (perhaps bundle it with the binary)...

It builds find on ARM, though still thinks it's x86!

Thanks a million: one less reason to use my failing ancient WinDoze laptop.

Rgds

Damon

Unknown said...

FYI: seems good on the daily historical values but a disaster on morning 10-minute W samples:

Dev #15: 1587 - 002D -SMA Technologie AG -
Serial Number:
pac: 0.00 W
e-today: 2.11 kWh
e-total: 3662.68 kWh
read bad crc 4883, should be 4961. Message *should* be rejected.


today:
1943-08-05 14:17:04: 0 W
1926-12-27 16:10:24: 0 W
1928-03-26 18:52:40: 0 W
1929-06-24 21:33:52: 0 W
1930-09-23 00:15:16: 0 W
1931-12-22 02:56:54: 0 W
1933-03-21 05:36:46: 0 W
1934-06-19 08:15:00: 0 W
1935-09-17 10:53:44: 0 W
1936-12-15 13:34:16: 0 W
1938-03-15 16:14:48: 0 W
1939-06-13 18:55:16: 0 W
1940-09-10 21:36:34: 0 W
1941-12-10 00:17:38: 0 W
1943-03-10 02:58:41: 0 W
1944-06-07 05:40:01: 0 W
1945-09-05 08:19:53: 0 W
1946-12-04 10:59:49: 0 W
1948-03-03 13:39:54: 0 W
1949-06-01 16:21:04: 0 W
1950-08-30 19:02:24: -0 W
1951-11-28 21:42:44: -0 W
1953-02-26 00:23:13: 0 W
1954-05-27 03:03:16: -2 W
1955-08-25 05:42:42: 2 W
1956-11-22 08:21:57: -0 W
1958-02-20 11:02:12: 0 W
1959-05-21 13:42:32: -0 W
1960-08-18 16:22:48: 0 W
1961-11-16 19:02:49: 0 W
1963-02-14 21:42:10: 0 W
1964-05-15 00:21:29: -0 W
1965-08-13 03:01:23: 0 W
1966-11-11 05:41:26: -0 W
1968-02-09 08:21:03: -0 W
1969-05-09 11:01:03: -0 W
1970-08-07 13:41:44: -0 W
1971-11-05 16:22:06: 0 W
1973-02-02 19:01:54: -0 W
1974-05-03 21:42:08: -0 W
1975-08-02 00:22:12: 0 W
1976-10-30 03:00:42: -0 W
1978-01-28 05:40:14: 0 W
1979-04-28 08:20:47: 0 W
1997-04-25 01:15:44: 0 W
2009-10-21 12:10:00: 219 W
2009-10-21 12:20:00: 140 W
2009-10-21 12:30:00: 142 W
2009-10-21 12:40:00: 88 W
2009-10-21 12:50:00: 64 W
2009-10-21 13:00:00: 59 W
2009-10-21 13:10:00: 59 W
2009-10-21 13:20:00: 45 W
2009-10-21 13:30:00: 34 W
2009-10-21 13:40:00: 28 W
2009-10-21 13:50:00: 37 W
2009-10-21 14:00:00: 30 W
2009-10-21 14:10:00: 26 W
2009-10-21 14:20:00: 25 W
2009-10-21 14:30:00: 21 W
2009-10-21 14:40:00: 14 W
2009-10-21 14:50:00: 8 W
2009-10-21 15:00:00: 0 W

last month:
2009-09-20: 7.490 kWh
2009-09-21: 7.990 kWh
2009-09-22: 6.600 kWh
2009-09-23: 4.660 kWh
2009-09-24: 9.530 kWh
2009-09-25: 9.450 kWh
2009-09-26: 8.650 kWh
2009-09-27: 8.760 kWh
2009-09-28: 5.150 kWh
2009-09-29: 7.330 kWh
2009-09-30: 3.540 kWh
2009-10-01: 7.750 kWh
2009-10-02: 6.680 kWh
2009-10-03: 3.930 kWh
2009-10-04: 5.140 kWh
2009-10-05: 1.810 kWh
2009-10-06: 3.100 kWh
2009-10-07: 1.590 kWh
2009-10-08: 7.130 kWh
2009-10-09: 2.680 kWh
2009-10-10: 5.580 kWh
2009-10-11: 3.040 kWh
2009-10-12: 4.780 kWh
2009-10-13: 5.660 kWh
2009-10-14: 2.450 kWh
2009-10-15: 5.790 kWh
2009-10-16: 4.160 kWh
2009-10-17: 3.350 kWh
2009-10-18: 5.330 kWh
2009-10-19: 2.100 kWh
2009-10-20: 2.390 kWh

Michaël said...

I've also noticed the bug when reading the 'today' measurements. It's very strange: sometimes re-running the sunnybeamtool solves it. There seems also to be a correlation with the moment you run the program: If I run the sunnybeamtool when there is no solar production, the results look more reliable.
Anyway, looking at the '-v' verbose output might help..;

Unknown said...

Hi,

OK, I've collected a mangled -l -v sample.

Do you want it pasted here or emailed? Pls email me d@hd.org to say!

Rgds

Damon

Anonymous said...

@SkynetBbs: I have a fitpc, x86 CPU.

Pierre

Unknown said...

Nice idea! It would be wonderful to have pac values also! Is it possible?

Anonymous said...

Nice tool!
Before a few months I also tried to develop a similar tool in C/C++.

But at the moment I have no time to make the program finished.

In order to give other developers an insight into my work, I've made ​​the source code available:

https://sites.google.com/site/smoggiearea/sunnybeam

But remember, it's not finished and more like an "example". Dut it might help interested developers ;)

Greetings from Germany

Anonymous said...

Hi Michael

I've tried using 'sudo ./sunnybeamtool' but keep getting "Sunny Beam not found." error message.
Ubuntu can see the drive and csv files ok. I've tried the '-l -v' options but still get the same error message. I've also tried the unplug dial turn replug dance but still with no joy.

Any ideas?

Regards

Robin

JW said...

I have the same problem as Robin: I can see the .csv files fine, but sunnybeamtool always tells me "Sunny Beam not found." :-(

Do let me know if there's anything I can do to help resolve this. I'd be happy to experiment :-)

Anonymous said...

+1 for JW & Robin

Cheers,

Greg

ba ha said...

Is it possible to get the sourcecode?

Henry said...

Hai,

Is it possible to have the source code?

thanks
Henry

Henry said...

Great job,
I want to run this on Raspi

Is it possible to release the source code?

Henry said...

Hai,
compiling and running sunnybeamtool on rpi is ok.

manytimes I have a crc error while reading sunnybeam, I escape from the script and run it the next 5 minutes.
Has anybody find out what the problem is when getting crc error.
The month data is ok every run.