Showing posts with label tonido plug². Show all posts
Showing posts with label tonido plug². 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/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/04/29

Tonido Plug² SATA Harddrive spindown



I recently purchased a Tondido Plug² Computer. Unfortunately, the ARM / linux-based device has some rough edges. But, as this plug device comes with command line access, you can easily tweak it.

One problem is that the embedded SATA drive is continuously spinning. This is particularly annoying as the device advertises itself as a "go green" solution. The following community forum topic explains how to solve this issue with a few commands by using the Debian  laptop-mode-tools package:
http://www.tonido.com/forum/viewtopic.php?f=32&t=4219. It contains updates and more details and also has info on tweaking SSD drives. Other references:http://samwel.tk/laptop_mode/faq.

Warning: Although the solution below works on a default setup booting from flash, it is not supported nor recommended and it might brick your device! First install a boot partition on your SATA HD and experiment from there. 
More info: 
The steps that did the trick for me:
  1. SSH into your plug.
  2. apt-get interaction:
    • Update your repositories and upgrade your packages.
      apt-get update 
      apt-get upgrade 
      
    • Install laptop-mode-tools.
      apt-get install laptop-mode-tools 
      
  3. Modify the config file:
    • Open the config file in nano.
      nano /etc/laptop-mode/laptop-mode.conf 
      
    • Change the following settings.
      • Enable Laptop Tools
        ENABLE_LAPTOP_MODE_TOOLS=1 
        ENABLE_LAPTOP_MODE_ON_AC=1 
        ENABLE_AUTO_MODULES=1 
        
      • Set Drive Spin down Time In Seconds
        LM_AC_HD_IDLE_TIMEOUT_SECONDS=600 
        NOLM_HD_IDLE_TIMEOUT_SECONDS=600 
        
    • Save and close the file: CTRL-o, ENTER, CTRL-x
  4. Restart the laptop tools
    /etc/init.d/laptop-mode restart 
    
    
    


If it causes you problems, stop it and remove it:
/etc/init.d/laptop-mode stop 
apt-get remove  laptop-mode-tools