Updates on my solar rig: GitHub, SQLite and more

First, I would like to say that I put the little scripts I’ve been using on my GitHub: https://github.com/surak/Solar . If nothing, I learn something from using it. All the files I mention here (including the uptime data) are there.

What I’ve been doing since the last update? Well, since there is not really sunlight enough to keep a miner working (hell, there was no sun to keep the Raspberry Pi2 working through the day!), I decided to do something simpler.

  • First, I wanted to test the feasibility of having a Pi running purely on solar power, with no gimmicks for shutdown when power is not enough. That means: It is connected to battery power and the solar panels, and when energy is over, it’s over. It would NOT shutdown cleanly. Can the Pi’s sd card/filesystem handle it?
  • Secondly, I would like to see the differences the amount of sunlight per day makes on energy generation.

For those goals, what I have done:

I have left my panels facing southeast on my balcony. This is not a conscious decision because of the direction of the sun: It’s the only way I can have them in my apartment. Turns out it’s great, because they get most of the morning sun, but not much, as I am blocked by the surrounding buildings. This is what my solar panels “see”:


For the whole winter, I had one hour of direct sunlight, TOPS. It’s a very extreme environment for collecting sunlight. In fact, I’ve considered wind power for a while as well.

I set my rig as described in previous posts: The two solar panels (36v each) connected to a buck regulator set to 12V, from it to a solar controller (the cheapest crap ever, and it sucks balls), and, from it, to a 12v battery and to a second buck regulador with an USB output. This one is connected to the Raspberry PI2.

So the scheme is:

Solar panels (36V) -> Buck regulador (36v to 12v) -> Solar controller (12v) -> { Battery (12v) AND Buck-to-usb (12v to 5v) } -> Raspberry Pi2

This way, the solar controller gives either solar power or battery power to the raspberry.

Given this bad position, the raspberry won’t have enough power through the day from solar energy alone. It will use it for a couple hours, and the controller will switch to battery if necessary. The controller obviously also recharges the battery when there is enough sun.

The Raspberry will turn on, connect to the internet (important!) and will do two things:

  • Connect to my favourite bitcoin mining pool, and
  • Record the date and uptime.

Even though I don’t plan on mining anytime soon, I keep it connected to the mining pool, just for the pi to have something to do.

For the uptime keeping, first I had a cronjob that every 10 minutes wrote something like

echo "$(date) $(uptime)" >> uptime.txt

And that was it. I had some problems with this approach:

  • It sucks to filter this out later, especially because the output of the “uptime” command changes as uptime grows;
  • The file starts to get large. I am not comfortable with the Pi being turned off while writing to a huge file;

Besides, when I said that is important to have internet, the reason is obvious: THE PI HAS NO REAL-TIME CLOCK! How can I record the date and hours it worked if the date is 1970-01-01?

I only noticed that when I switched my wifi router to 5gz. The “EDIMAX” wifi cards recommended by the Raspberry community only work with 2.4gz, and I have one week of zero data collection until I noticed this. And, obviously, it was the week when the sunlight changed the most (which would be very nice on the graph).

After 4 months of data collection, I was unhappy with this large text file. So I created the most ridiculously simple SQL database possible. It’s a SQLITE file, with one table, just like this:

CREATE TABLE solaruptime(date date,time time,uptime time);

And now, crontab calls a shell script I called “saveuptime.sh”, which just does:

echo "insert into solaruptime values(strftime('%Y-%m-%d','now'),strftime('%H:%M','now'),\"$(cat /proc/uptime | cut -f1 -d.)\");" | sqlite3 ~/Devel/Solar/uptime.db

And now I have a way nicer way of keeping my uptime data.

Note that I use “cat /proc/uptime” on it instead of the uptime command. Why? This gives me the output in seconds, and that’s all I want. I want no damn formatting on it. You can check out the data on GitHub yourself.

I am also playing with the visualisation of this data, using the D3.Js javascript library. More on that later.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s