≡ Menu

Home Automation Part 6 – The Server Is (Mostly) Finalized

It’s been awhile since I last posted… And much has changed.

First, I made the decision to go with a RaspberryPi for the server that would be running everything.  It was so simple to get running right away the way I wanted it’s crazy. So let’s talk about what it is I “got running”.

  • Installed “Raspbian” (Debian for RaspberryPi). This was very very straight forward.
  • Installed my typical LAMP setup (Linux, Apache, Mysql, and PHP). With PHP I included GD libraries (for graphing), and the CURL libraries (for communication with my thermostat).
  • I then installed OWFS. It’s a nifty software package to aid in communicating with 1-wire devices (such as my temperature sensors).
  • I then installed the PHP module for OWFS (so I could talk to it directly from PHP without to much additional hassle.
  • And lastly, I installed phpMyAdmin, just to save myself some time managing the mysql databases I intend to create.

From there, I created a basic PHP script that I ran as a cron job ever 5 minutes, that did the following:
1) Pinged each sensor for it’s current temperature.
2) Logged that to a MySQL table.
3) Pinged my Thermostat with the updated temps to allow me to see the updated temps on the display.

You would think I would stop there… but I have a long term goal of having this data easily viewable from the web. And while remotely accessing my RaspberryPi from outside my home is already possible… it’s not exactly how I want to be serving up webpages to the general public. So I needed to find a way to mirror the data to a real web server, in a near-realtime, fault tolerant way.

I considered simply having my php script talk directly to a remote web server via a remote MySQL connection… but that had the problem that it would stop logging data in the event of an internet outage.

So instead, I went back to my favorite way of replicating MySQL data…  MySQL Replication.

It’s been awhile since I had set that up for a server… so I was pleasantly surprised that since the last time I had done it, phpMyAdmin had added 2 things to it’s interface:

1) A Mysql “Sync” interface to allow you to get 2 servers in sync with one another… and
2) A Mysql Replication interface so you could start and stop replication without having to look up the “index number” and then run the various commands to start the replication.

Those were both some great time savers.

There was one other development in this project that came up in the last week, which I’ll address in my next post. We ended up deciding to replace our Air Conditioner. That’s got it’s own mini story, and isn’t entirely something that was done as part of the home automation project… But it was something that needed to be done non the less.

In any case, more updates to come as I start getting ready to move into the actual “automation” phase of this project (I’ve got the data now, just need to use it!)