Showing posts with label sma-bluetooth. Show all posts
Showing posts with label sma-bluetooth. Show all posts

2012/05/15

Using the TonidoPlug² as a Datalogger for Photovoltaic Panels

I managed to setup my TonidoPlug² (TP2) as a data-logger that automatically uploads live statistics of my solar panels to pvoutput.org. This post details the steps I followed to run sma-bluetooth on the TP2 .
After ssh'ing to your TP2, prepare a build environment on the plug pc:
  • follow the steps in: http://www.tonido.com/communitywiki/doku.php?id=advanceduses:setupbuildenvironment
  • step 4 & 5 are slightly outdated:
    • (4a) I had to install the deb-multimedia-keyring package first:
      apt-get install deb-multimedia-keyring 
      
    • (4b) the url for wget is diffent:
      wget http://www.debian-multimedia.org/pool/main/d/debian-multimedia-keyring/debian-multimedia-keyring_2010.12.26-3_all.deb 
      
    • (5) dpkg -i debian-multimedia-keyring_2010.12.26-3_all.deb
After that you can follow the steps I detailed in my previous post: http://michael-peeters.blogspot.com/2012/04/sb-inverter-bluetooth-connection-on.html. Summarized:
  • compile sma-bluetooth:
    wget http://sma-bluetooth.googlecode.com/files/sma-bluetooth-0.17b.tar.gz 
    tar -xzf sma-bluetooth-0.17b.tar.gz 
    cd sma-bluetooth-0.17 
    sudo apt-get install mysql-server mysql-client  libmysqlclient-dev 
      # (don't forget to enter a non-blank password for mysql!) 
     
     gcc -c smatool.c 
     gcc smatool.o -L/usr/lib -lmysqlclient -lbluetooth -lcurl -lm -o smatool 
    
  • edit the configuration. This can be tricky! Check the details first.
    # nano ./smatool.conf 
    
  • install the mysql tables:
    ./smatool --INSTALL 
    
  • run / debug errors:
    ./smatool -d -v 
    
Once smatool runs OK from the command-line, you can consider scheduling the run in cron.
  • create a smatool.cron file in your home-directory. Contents:
    # /etc/cron.d/smatool: crontab entries for smatool (monitoring of Sunnyboy Grid Interactive Inverter) 
     
    SHELL=/bin/sh 
    PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/home/smatool/bin 
     
    # The following line runs the smatool every 15 minutes between 0500 and 2300 and logs all output to the /var/log/smatool.log file. 
    */15 5-23 * * *   root cd /root/sma-bluetooth-0.17; ./smatool 2>&1 | logger -t smatool -p local5.info 
    
  • activate the new cron entry:
    cp ./smatool.cron /etc/cron.d/smatool 
    chmod 744 /etc/cron.d/smatool 
    
  • checkout /var/log/syslog for errors
  • each run is logged in /var/log/syslog
The result:



Possible improvements:
  • sma-bluetooth requires mysql which is a relatively heavy database for a plugpc. Sqlite would be a better choice. I experimented with the excellent fork http://rcphills-sma-bluetooth-dbabstraction.googlecode.com/ that supports sqlite, but the connection to pvoutput.org didn't work anymore.
  • the current setup does too much I/O preventing the SATA HD to sleep. Unfortunately booting from an external USB flash disk is not easy on TP², so I'll have to investigate other alternatives.

2012/04/24

Bluetooth Connection of the Sunny Boy Inverter on Ubuntu


My photovoltaic panels are connected to the power grid through a Sunny Boy SB5000TL inverter. Although, this inverter comes out-of-the-box with bluetooth connectivity, this feature is only supported on Windows. Luckily, there exists a free tool that reads out the generation data on Linux: sma-bluetooth. This involves a few manual commands detailed in http://code.google.com/p/sma-bluetooth/wiki/ubuntu_compile_guide. The guide didn't work a 100% for me, so the next section details the steps I followed.

The code can be downloaded from http://code.google.com/p/sma-bluetooth.

In the terminal ( Ctl + Alt + T):
  • sudo apt-get install mysql-server mysql-client mysql-query-browser libmysqlclient-dev (the libmysqlclient-dev package is needed for compilation)
  • sudo apt-get install bluez libbluetooth-dev curl libcurl3 libcurl4-nss-dev
  • create a new Makefile in the sma-bluetooth-0.17 directory:
    gedit Makefile 
    
    Contents (make sure you use a tab, not spaces, in front of the gcc commands):
    smatool: smatool.o 
     
            gcc smatool.o -L/usr/lib -lmysqlclient -lbluetooth -lcurl -lm -o smatool  
     
    smatool.o: smatool.c 
     
            gcc -c smatool.c 
     
    
  • make
Now prepare the Bluetooth connection:
  • my bluetooth USB dongle is automatically up & read on ubuntu 11.10:
    $ lsusb | grep -i bluetooth 
    Bus 002 Device 002: ID 0a5c:4500 Broadcom Corp. BCM2046B1 USB 2.0 Hub (part of BCM2046 Bluetooth) 
    
  • hcitool scan
  • workaround if hcitool scan gives no result: (seehttps://help.ubuntu.com/community/BluetoothSetup#Setup_Devices for details)
    sudo hciconfig hci0 inqmode 0 
    
  • cp smatool.conf.new smatool.conf
  • gedit smatool.conf
    • modify the lines as explained in the comments
    • you can optionally upload your data to the excellent pvoutput.org service - see http://pvoutput.org/account.jsp for details:
      • get the API key
      • configure your unique SID
    • use the bluetooth password for 'normal' usage (by default 0000 in some devices). I had trouble with the different password reserved for maintenance.
If you use mysql:
  • install the database / create the tables (this requires a user with admin rights):
    ./smatool --INSTALL 
    
  • an empty password is not supported
Running:
  • ./smatool
  • debug & verbose can help identifying errors:
    ./smatool -d -v 
    
  • ./smatool -? lists out all options available
My pv-output: http://pvoutput.org/list.jsp?userid=9300

Next steps:
  • schedule the smatool in cron
  • replace mysql with sqlite for easier is
  • deploy the config on a plug computer