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/05/12

Adding Bluetooth support to the TonidoPlug2


I'm planning to use my TonidoPlug2 (TP2) for reading out the electricity production of my solar panels. I attached a very small USB bluetooth dongle to my TP2. The USB bluetooth device is detected, but the default kernel has no bluetooth support:
root@TonidoPlug2:~# lsusb 
... 
Bus 001 Device 003: ID 0a5c:4500 Broadcom Corp. BCM2046B1 USB 2.0 Hub (part of BCM2046 Bluetooth) 
... 
The only solution to this problem is to build a new TP2 kernel with bluetooth enabled. The next section details the specific steps that did the trick for me.
Important note: Do NOT change the kernel on the internal flash memory as it might brick your device! Configure your TP2 to boot from the SATA HD first. I created a dedicated 32GB boot partition on my SATA device. Details:
Once you are booting from the SATA HD, you can proceed with the instructions below.

Building a TP2 kernel with bluetooth
The arm-kernel can be built on a linux desktop. I used my regular Ubuntu laptop.
First start with building a normal TP2 kernel:
After you built the kernel and modules you can enable bluetooth by modifying the .config file:
   make menuconfig 
  • Options to enable: (toggle by pressing 'space' until an * or M appears)
    • Networking → <*>Bluetooth subsystem support (CONFIG_BT)
    • Networking → Bluetooth subsystem support → <*>L2CAP protocol support (CONFIG_BT_L2CAP)
    • Networking → Bluetooth subsystem support → <*>SCO links support (CONFIG_BT_SCO)
    • Networking → Bluetooth subsystem support → <*>RFCOMM protocol support (CONFIG_BT_RFCOMM)
    • Networking → Bluetooth subsystem support → [*]RFCOMM TTY support (CONFIG_BT_RFCOMM_TTY)
    • Networking → Bluetooth subsystem support → <*>BNEP protocol support (CONFIG_BT_BNEP)
    • Networking → Bluetooth subsystem support → <*>HID protocol support (CONFIG_BT_HID)
    • Networking → Bluetooth subsystem support → Bluetooth device drivers → HCI USB driver (CONFIG_BT_HCIUSB)
  • this is how my .config file was modified:
    ~/tonido/kernel-2.6.31$ diff .config.old .config 
    4c4 
    < # Sat May 12 21:21:58 2012 
    --- 
    > # Sat May 12 22:24:11 2012 
    654c654,673 
    < # CONFIG_BT is not set 
    --- 
    > CONFIG_BT=y 
    > CONFIG_BT_L2CAP=y 
    > CONFIG_BT_SCO=y 
    > CONFIG_BT_RFCOMM=y 
    > CONFIG_BT_RFCOMM_TTY=y 
    > CONFIG_BT_BNEP=y 
    > # CONFIG_BT_BNEP_MC_FILTER is not set 
    > # CONFIG_BT_BNEP_PROTO_FILTER is not set 
    > CONFIG_BT_HIDP=y 
    >  
    > # 
    > # Bluetooth device drivers 
    > # 
    > CONFIG_BT_HCIBTUSB=m 
    > # CONFIG_BT_HCIBTSDIO is not set 
    > # CONFIG_BT_HCIUART is not set 
    > # CONFIG_BT_HCIBCM203X is not set 
    > # CONFIG_BT_HCIBPA10X is not set 
    > # CONFIG_BT_HCIBFUSB is not set 
    > # CONFIG_BT_HCIVHCI is not set 
    1351a1371,1372 
    > CONFIG_HID_APPLE=y 
    > CONFIG_HID_WACOM=y 
    
You can continue with the instructions for building a TP2 kernel at step 15:
make uImage 
... 
Some attention points with the last activation step:
  • remove two unnecessary symlinks before running scp:
    ~/tonido/kernel-2.6.31$ rm ../current_kernel/lib/modules/2.6.31.8-topkick1281p2-001-004-20101214/build 
    ~/tonido/kernel-2.6.31$ rm ../current_kernel/lib/modules/2.6.31.8-topkick1281p2-001-004-20101214/source 
    
  • run scp (don't forget the -r for a directory):
    ~/tonido/kernel-2.6.31$ scp ../current_kernel/boot/uImage root@tp2-ip:/boot 
    ~/tonido/kernel-2.6.31$ scp -r ../current_kernel/lib/modules root@tp2-ip:/lib/ 
    
  • double-check if all transfers were OK before rebooting
If the TP2 booted successfully you can now enable and test bluetooth:
  • apt-get install bluez
  • test with hcitool:
    root@TonidoPlug2:~# hcitool scan 
    Scanning ... 
     E4:D5:3D:EB:EA:E4 ubuntu-0 
     00:80:25:1F:9A:F4 SMA001d SN: ... 
    
Background info:

2012/05/01

Ubuntu: Undeleting Files on FAT Partition

I accidentally deleted all photos on an SD card in my camera. Luckily, it is very easy to recover those deleted files on a FAT partition under Ubuntu. Simply install the excellent "testdisk" utility and run it from the command line:

sudo apt-get install testdisk 
testdisk

I was able to recover all files back from the SD card to my hard disk.

Instructions: http://www.cgsecurity.org/wiki/TestDisk:_undelete_file_for_FAT

Details: https://help.ubuntu.com/community/DataRecovery