Jan092012

Solar application on Android

The past couple of weeks I’ve been working on an Android application to look at the solar panel production. The following screenshots show what this has lead to.

The left picture shows the start-up screen, with a photograph of the actual panels and six buttons for each of the screens. The middle picture shows the production in tabular form. The red coloring is for the 10% worst production days overall, the green coloring for the 10% best days overall. The grey background is for Saturdays and Sundays. The right picture shows the temperature of the inverter and the booster. It seems that the inverter tries to keep the temperature of the booster below 50 degrees. It does something – I don’t know what yet – until the temperature reaches 40 degrees:
The application works in both portrait mode and landscape mode. The left picture shows the production for each day from installation until the current day. The right picture shows the production on a single day, with buttons to select the day:

Dec192011

A sunny day with three clouds

The 19th of December 2011 was a good day for solar panels. The production that day was about 3.5 kWh and you can clearly see that the inverter got enough power to awake at around 9:00, being at peak around noon and going back to sleep at around 15:00. This looks hopeful for the summer, probably showing similar graphs with higher tops and wider bottoms.

Dec162011

Solar panel graphs

The last couple of weeks I’ve been running monitoring software that is connected to the Aurora inverter and receives measurements from it. The setup is as follows:

A lot of measurements are available, such as voltage, current and power of both inputs (solar panel strings) and the grid, temperature of the inverter and its booster, etc. The most interesting graphs are shown below. The first one shows the energy produced on each day since the solar panels were installed.

The second one shows the power of a single day, from both the input (solar panel string) and the grid. There is a difference in these two readings, because the inverter is not one hundred percent efficient in transforming DC input into AC output.

The third one shows the voltage outputs of the solar panels. Although not perfectly stable, it tries to keep quite constant at about 200V.

The fourth one shows the current outputs of the solar panels. This is what matters for the production of the panels.

The fifth one shows the temperature of the inverter itself and its booster. It seems that the inverter tries to keep the temperature of the booster below 50 degrees. As soon as it hits 50 degrees, it cools down to 40 degrees and rises again.

Nov272011

Solar inverter readout

I hooked up the Aurora Uno PVI-2000 solar inverter to a laptop with an RS-232 serial cable. Note that we need an RS-232 cable with a male connector on one end and a female connector on the other end. It also needs to be a straight connection, i.e. no cross between RX and TX. If you don’t have such as cable handy, you might link two cross cables to acquire a straight cable.


Curt Blank has made an open source Linux program called aurora that uses this connection to get readouts from the inverter. The program is included in the Ubuntu packages since 10.04 LTS, so it is really easy to install:

sudo apt-get install aurora

The serial connection on my laptop is called /dev/ttyS0 by Linux, so this is what we use as one of the parameters. Another required parameter is the address of the inverter. Several inverters might be present in a solar installation, so an address is needed to target a specific one. Note that this is only relevant if they are linked together with RS-485 cables. In my case there is only one and the inverter has address 2.

Let’s start with the energy in the last 10 seconds:

# aurora -a 2 -j /dev/ttyS0

Energy in the last 10 seconds (Joules) :    1948.365882

More interesting is the energy produced for today, weekly, monthly, yearly and since the inverter was installed:

# aurora -a 2 -e /dev/ttyS0

Daily Energy               =       0.094 KWh
Weekly Energy              =       0.094 KWh
Monthly Energy             =      12.447 KWh
Yearly Energy              =      12.471 KWh
Total Energy               =      12.469 KWh
Partial Energy             =      12.444 KWh

There are also readings about voltage and current. To be honest, I don’t understand the input 2 readings because there is nothing connected there.

# aurora -a 2 -d /dev/ttyS0

Input 1 Voltage            =  184.667801 V
Input 1 Current            =    2.804785 A
Input 1 Power              =  517.953552 W

Input 2 Voltage            =    0.650100 V
Input 2 Current            =    1.859635 A
Input 2 Power              =    1.208949 W

Grid Voltage Reading       =  225.644196 V
Grid Current Reading       =    1.965952 A
Grid Power Reading         =  458.323853 W
Frequency Reading          =   49.991001 Hz.

DC/AC Coversion Efficiency =        88.3 %
Inverter Temperature       =   38.024002 C
Booster Temperature        =   35.868004 C

There is also a Windows program made by Power One that shows current and historical readings called Aurora Communicator. A partial screenshot is shown below with some values when the sun shines brightly (for a November day that is).

The screenshot below shows the readings for a complete day. The lower graph shows the Watts (W) produced at each timestamp and the upper graph shows the accumulated Watt hours (Wh) values.

Nov232011

Solar panel installation

On Wednesday the 16th of November 2011 we installed some solar panels on our roof. The panels are from Trina Solar. Each panel produces 235 Watt peak (Wp), which means that the panels produce at most 235 Watt at any moment in time. If the light conditions are less favorable, the production will be less.

An inverter was also installed inside the house. The inverter is made by Power One and is called Aurora Uno PVI-2000. The inverter transforms the DC from the solar panels into AC that is fed straight into the mains of our house.

Unfortunately, the last week has seen unprecedented levels of mist, which means that our energy production was far lower than expected. Ah well, enough time left as the lifetime expectancy of the panels is around 30 years, while the inverter should last around 15 years.

I’ve been tinkering with the inverter a bit and got the monitoring software working on both Windows and Linux. More about that in the next post.

Jul212011

CentOS Cassandra init (start / stop) script

For CentOS I created an init script to start it at boot time and shut it down for rebooting or power off. If you want to use this init script for your own machine please look through the script and change the necessary parameters, e.g. CASSANDRA_HOME.

Please also note that in the stop function it decommissions the node from the cluster. This is probably not what you want in production environments.

#!/bin/bash
# chkconfig: 2345 99 01
# description: Cassandra

. /etc/rc.d/init.d/functions

CASSANDRA_HOME=/opt/apache-cassandra-0.7.4
CASSANDRA_BIN=$CASSANDRA_HOME/bin/cassandra
CASSANDRA_NODETOOL=$CASSANDRA_HOME/bin/nodetool
CASSANDRA_LOG=$CASSANDRA_HOME/log/cassandra.log
CASSANDRA_PID=/var/run/cassandra.pid
CASSANDRA_LOCK=/var/lock/subsys/cassandra
PROGRAM="cassandra"

if [ ! -f $CASSANDRA_BIN ]; then
  echo "File not found: $CASSANDRA_BIN"
  exit 1
fi

RETVAL=0

start() {
  if [ -f $CASSANDRA_PID ] && checkpid `cat $CASSANDRA_PID`; then
    echo "Cassandra is already running."
    exit 0
  fi
  echo -n $"Starting $PROGRAM: "
  daemon $CASSANDRA_BIN -p $CASSANDRA_PID >> $CASSANDRA_LOG 2>&1
  usleep 500000
  RETVAL=$?
  if [ $RETVAL -eq 0 ]; then
    touch $CASSANDRA_LOCK
    echo_success
  else
    echo_failure
  fi
  echo
  return $RETVAL
}

stop() {
  if [ ! -f $CASSANDRA_PID ]; then
    echo "Cassandra is already stopped."
    exit 0
  fi
  echo -n $"Stopping $PROGRAM: "
  $CASSANDRA_NODETOOL -h 127.0.0.1 decommission
  if kill `cat $CASSANDRA_PID`; then
    RETVAL=0
    rm -f $CASSANDRA_LOCK
    echo_success
  else
    RETVAL=1
    echo_failure
  fi
  echo
  [ $RETVAL = 0 ]
}

status_fn() {
  if [ -f $CASSANDRA_PID ] && checkpid `cat $CASSANDRA_PID`; then
    echo "Cassandra is running."
    exit 0
  else
    echo "Cassandra is stopped."
    exit 1
  fi
}

case "$1" in
  start)
    start
    ;;
  stop)
    stop
    ;;
  status)
    status_fn
    ;;
  restart)
    stop
    start
    ;;
  *)
    echo $"Usage: $PROGRAM {start|stop|restart|status}"
    RETVAL=3
esac

exit $RETVAL

If all looks alright, name the script cassandra and place it in /etc/init.d/
After that run the following commands:

mkdir /opt/apache-cassandra-0.7.4/log
chmod +x /etc/init.d/cassandra
chkconfig --add cassandra
service cassandra start
Jul212011

Grep lines before and after matched line

The command grep is really useful for finding matches of a certain word in files or streams. However, until recently I didn’t know how to display lines before and after the matched line(s).

Let’s say we have a file named test.txt that contains the following content:

ALICE was beginning to get
very tired of sitting by
her sister on the bank
and of having nothing to do:
once or twice she had peeped
into the book her sister was reading,
but it had no pictures or conversations in it,
"and what is the use of a book," thought Alice,
"without pictures or conversations?'

If we use grep to find lines matching “bank”, we write:

grep bank test.txt

and get:

her sister on the bank

If we want to list some line(s) before the matched line, we write:

grep -B1 bank test.txt

where the 1 denotes the number of lines to list, and get:

very tired of sitting by
her sister on the bank

If we want to list some line(s) after the matched line, we write:

grep -A2 bank test.txt

where the 2 denotes the number of lines to list, and get:

her sister on the bank
and of having nothing to do:
once or twice she had peeped

The two options can be combined as well, but I leave that as an exercise to the reader :-) .

Jun292011

Deleting XenServer templates


Sometimes XenServer doesn’t allow you to delete templates from the XenCenter GUI or even the CLI. Here is how to delete templates from the CLI in three steps:

  • Tell XenServer the template is not a default template
  • Convert the template to a VM
  • Delete the VM
xe template-param-set other-config:default_template=false uuid=[uuid]
xe template-param-set is-a-template=false uuid=[uuid]
xe vm-destroy uuid=[uuid]

where [uuid] is the UUID of the template you want to delete.

Dec062010

Creating backups of running VMs in XenServer

With XenServer it is possible to create backups of VMs, even if they are running. The process is as follows:

  • Search for the uuid of the VMs to backup
  • Create a snapshot of each (running) VM
  • Save the snapshot to file
  • Remove the created snapshot

First look for the uuid of the VMs to backup. We don’t want to backup the control domain itself, so we add is-control-domain=false to the vm-list command:

xe vm-list is-control-domain=false

Now we create a snapshot of the VMs we want to backup, replacing the uuid one by one with the ones we found with the previous command. Also replace the name of the snapshot if desired:

xe vm-snapshot uuid=d61bfc1a-33b2-5406-7ea5-76e4f7113220 new-name-label=snapshotname

This command has a return value: the uuid of the created snapshot. Then we transform the snapshot into a VM to be able to save it to a file, replacing uuid with the return value of the previous command:

xe template-param-set is-a-template=false ha-always-run=false uuid=b759625c-eab5-4e0f-be5e-a05bcbad869a

In the next step we save the snapshot to a file, replacing uuid with the snapshot uuid and providing a meaningful filename:

xe vm-export vm=b759625c-eab5-4e0f-be5e-a05bcbad869a filename=filename.xva

In the final step we delete the snapshot:

xe vm-uninstall uuid=b759625c-eab5-4e0f-be5e-a05bcbad869a force=true

Python is installed by default on XenServer hosts, so the following script will work out of the box. Download the script from this location to save it to your XenServer host, replacing the .txt extension with .py.

#!/usr/bin/python

import commands, time

def get_backup_vms():
   result = []

   cmd = "xe vm-list is-control-domain=false"
   output = commands.getoutput(cmd)

   for vm in output.split("nnn"):
      lines = vm.split("n")
      uuid = lines[0].split(":")[1][1:]
      name = lines[1].split(":")[1][1:]
      result += [(uuid, name)]

   return result

def backup_vm(uuid, filename, timestamp):
   cmd = "xe vm-snapshot uuid=" + uuid + " new-name-label=" + timestamp
   snapshot_uuid = commands.getoutput(cmd)

   cmd = "xe template-param-set is-a-template=false ha-always-run=false uuid=" +
   snapshot_uuid
   commands.getoutput(cmd)

   filename = filename.replace(" ", " ")
   filename = filename.replace("(", "(")
   filename = filename.replace(")", ")")
   cmd = "xe vm-export vm=" + snapshot_uuid + " filename=" + filename
   commands.getoutput(cmd)

   cmd = "xe vm-uninstall uuid=" + snapshot_uuid + " force=true"
   commands.getoutput(cmd)

for (uuid, name) in get_backup_vms():
   timestamp = time.strftime("%Y%m%d-%H%M", time.gmtime())
   print timestamp, uuid, name
   filename = timestamp + " " + name + ".xva"
   backup_vm(uuid, filename, timestamp)
Nov302010

Assigning more than 8 virtual CPUs in XenServer


With the XenServer Windows client called XenCenter it is possible to manage multiple XenServer hosts, create virtual machines, watch the console of virtual machines, etc. One of the limitations I recently ran into (this is a luxury problem, I know) is that it doesn’t allow you to assign more than 8 virtual CPUs (vCPUs) to a single VM.

However, on the command line you can increase this value to 32 for Linux VMs. First, let’s see which uuid is assigned to the VM we want to give more than 8 vCPUs:

xe vm-list

Now make sure that the VM is halted and then use this uuid in the following commands:

xe vm-param-set VCPUs-max=32 uuid=replace_with_uuid
xe vm-param-set VCPUs-at-startup=32 uuid=replace_with_uuid

If you want to increase the memory size beyond 16GB as well, e.g. to 32GB, add the following commands:

xe vm-param-set memory-static-max=34359738368 uuid=replace_with_uuid
xe vm-param-set memory-dynamic-max=34359738368 uuid=replace_with_uuid
xe vm-param-set memory-dynamic-min=34359738368 uuid=replace_with_uuid
xe vm-param-set memory-static-min=34359738368 uuid=replace_with_uuid

Restart the VM and enjoy! For a quick look if everything worked out, watch the output of this command inside the VM:

cat /proc/cpuinfo | grep processor | wc -l