Thursday, February 13, 2014

Welcome to the family

Yes, my second princess, arrive 2 weeks early. I think she want angpao also since still Chinese New Year today.

Thanks to my wife so brave give birth naturally without any pain killer O.o

I wish my princess a happy Chinese New Year and hope you grow up happily and healthy.

Tuesday, February 11, 2014

The Humble Sid Meier Bundle


I'm a Civilization fans since I bought my very first PC when I was studying in highschool. It was the Civilization II that make me crazy about computer games. After Civilization II, I played few other series of Civilization, but time always not allow me to finish it.

This time Humble Bundle bring the Sid Meier series to everyone. Basically you just need to pay USD1 and you can have 5 Sid Meier's games, yes it is all genuine games. You may don't know who is Humble Bundle, you can read it here. Basically, it is a type of charity funding site. When you buy those games, part of the fees will be donated to the charity.

So, if you like Civilization games, or you want to try it, and at the same time you want to do some charity donation, you may go here to buy the title. I bought mine although I really don't know when I can have some spare time to play these games. Anyway, just few USD and I can have my favorite games and at the same time do some charity.

Tuesday, February 04, 2014

Plot.ly and Pi

I found Plotly since early last year, it is a very interesting online data visualization tool. I always want to use it for some logging purpose. So finally I got my Pi and I start to do a simple task, to log the CPU temperature, and here is the result.



I use Python as the programming language since it is the most famous language for Pi. If you new to Pi, here is the step to install Python.

  • sudo apt-get install python-dev
  • wget http://python-distribute.org/distribute_setup.py
  • python distribute_setup.py
  • wget https://raw.github.com/pypa/pip/master/contrib/get-pip.py
  • python get-pip.py
  • sudo pip install virtualenv

Once you have installed the Python on your Pi, the next task is to install plot.ly API.

  • pip install plotly

At the same time you can register an account with plot.ly in order to use their services.

Now everything is ready, and we need to create a Python program to get the temperature data and upload it to plot.ly. Before I continue, there is something about Python that you should know, especially C/C++ programmer.

First, you do not need to put semicolon (;) at the end of the line. It looks like a Basic code.
Second, do not mix tap and space. You will get an error if you mixed it.
Third, you do not need to declare the variable. Ok, it looks like Basic now.

I'm very new to Python with nearly zero knowledge about this language. Thanks to the Internet, you will get some examples to help you to get the code you needed.

So here is the code.

  • #!/usr/bin/env python
  • import plotly
  • import os
  • import subprocess
  • import datetime

  • def update_temp():
  •   py = plotly.plotly(username_or_email='YOUR_USERNAME', key='YOUR_API_KEY')
  •   i = datetime.datetime.now()
  •   proc = subprocess.Popen(["cat", "/sys/class/thermal/thermal_zone0/temp"], stdout=subprocess.PIPE)
  •   t = proc.stdout.read()
  •   r =  py.plot(i.strftime('%Y-%m-%d %H:%M:%S'),float(t)/1000,
  •   filename='RPiTempCont',
  •   fileopt='extend',
  •   layout={'title': 'Raspberry Pi Temperature Status'})

  • if __name__ == '__main__':
  •   import sys
  •   update_temp() 

So that is the code that get the current date, time and temperature and upload to your plot.ly account.

In order to do it automatically, you need to add the program to cron job. But before that you need to save the Python program to a location. For my case, I put it at

  • /home/pi/scripts/

To add the task to cron, you need the following commands

  • crontab -e

Then add the task

  • */10 * * * * usr/home/python /home/pi/scripts/YOUR_PYTHON_FILE.py > /dev/null

What it does is to run the Python program every 10 minutes for 24x7x365. Now you can monitor your Pi temperature in real time.

I believe you will not satisfy with this simple task only. So, my next project will be logging weather information including temperature, relative humidity and solar irradiation. Yes, you are right, solar irradiation, to monitor my mini PV farm.

Next post coming soon.