Uncategorized

Home energy monitor reveals consumption horrors

I’ve moved flat recently (all planned, fancied an upgrade and the right opportunity came along), and my new flat is situated close to to the cupboard on my floor where the electricity meters are kept. This differs from previous apartment buildings in which I have lived because in those buildings the meters were all in the basement, far far away from the apartment itself. This prevented me from using an energy monitor, because for them to work you need to install a transmitter on the meter and that transmitter needs to be within a certain distance of the receiver inside the apartment.

Keen to work out why I kept getting over usage bills from my own employer, I bought an Owl Intuition-E and Micro+ bundle, which gave me the transmitter, the receiver and a network receiver, which allows me to upload usage data over the Internet to their online portal for analysis. Being within 30 metres of the meter, it works a treat.

I was a little surprised, however, with the results it gave me. I’ve found out the following:

  1. My television, surround sound and Bluray setup in the living room uses 60W on standby. 525 kWh per year (£78.75). I put a remote controlled socket on that lot straight away. I have no idea why 60W is necessary to keep four items AV equipment on standby.
  2. The TV / stereo setup in the bedroom uses 16W on standby. Another 140 kWh per year (£21.00) saved with another remote socket.
  3. I use a minimum of 241W. It never goes below that. This is during the day with no lights on (not that they bother me much, they’re all LED), with the fridge/freezer on (60W), my server and networking gear on (90W – this is lean, trust me) and my desktop computer on (60W), but with my monitors and everything else switched off. This means that there’s still 31W of background usage, 24 hours per day (271 kWh per year, £40.73).
  4. Consumption has been as high as > 9kW. This, presumably, was when I had the water heater and the cooker and the microwave and the telly on at the same time. Fortunately periods like this are always short-lived.

It’s a really good product, works very well, but I absolutely hate the web portal you have to log in to view your statistics. It’s awful. Fortunately, the network device can be configured to also sends its readings to a specified IP address on a specified UDP port, which is exactly what I’ve done and I store all my readings in a local database with a collector listening on that port. I then wrote my own software to analyse it and now I get a report like this every day. To this I have also added a web browser dashboard.

daily-electricity-report

Update 19/05/2014: I’ve now created a web dashboard (which also works well on mobile devices).

Screen Shot 2014-05-19 at 20.03.27

Code’s here if you’re interested (NodeMon isn’t really a thing, just a project framework for various bits of tinkering). Needs Phalcon.

Uncategorized

Mac, Apache, MySQL and PHP (MAMP)

Mac OS X serves as an excellent development environment, even if you are not actually developing Mac OS or iOS applications. It is the darling of many a LAMP (Linux, Apache, MySQL and PHP) developer, who enjoys a slick desktop operating system with good UNIX-like underpinnings but who don’t necessarily want to put up with all the various limitations and complications that running a Linux desktop brings, consistent improvements in this regard over recent years notwithstanding.

The only trouble with this is that if you want to develop LAMP applications and work on a Mac then traditionally you’ve needed a two-box setup; a Mac on your desk and Linux on a development server. For many this isn’t an issue, and indeed when you’ve got a team of developers, optimal, but what if you wanted a self-contained development environment that was restricted to just one box? What if you wanted that box to be your laptop so you could take it anywhere?

Solutions

“Virtual machine!”, I hear you cry. Yes, this is a possible solution, and for many works well. Good virtualisation software is free these days, but using a local VM is cumbersome. Not only does it consume a large slice of your RAM but it also puts a lot of strain on the CPU, meaning that if you are running off your battery your battery life will be decreased. It’s also cumbersome; you have to start up the VM when you need it and there can be complications with the networking, for example, if you have connected to a public wireless network it’s possible that your VM might not be extended the same resource.

There is a software package for Mac OS called MAMP (the M for Mac OS replacing the L for Linux). This is a point-and-click installer which bundles Apache, Linux and PHP for installation on Mac OS. I don’t like this solution, for a number of reasons, including:

  1. Limited functionality unless you “go pro” (at quite considerable cost). Any self-respecting developer will require multiple virtual hosts as a minimum and won’t need or want a clicky-button interface to get what they want.
  2. You are entirely at the mercy of the distributors of MAMP with regards to component software versions that are made available to you and when.

Alternative solution

There’s an alternative to this. You don’t have to fork out £39 for a package of what it otherwise freely and widely available software. With the help of my friend and colleague Ben Nimmo I present the following assembled and tested instructions for turning your Mac into a native MAMP server without using the packages download.

MySQL

  1. Download and install the latest .dmg and install both the *.pkgs within it (don’t use the TAR/GZ archives). You may wish to install the Workbench too, it’s really good these days.
  2. Find where the mysql.sock file is expected to be in /etc/php.ini (should be /var/mysql/mysql.sock)
  3. Create the folder and link the socket file to the expected location.
sudo mkdir /var/mysql
sudo ln -s /private/tmp/mysql.sock /var/mysql/mysql.sock
  1. Add MySQL to command line by editing /Users/username/.bash_profile and adding this line and then either restarting terminal or source-ing the file:
export PATH=$PATH:/usr/local/mysql/bin

PHP

PHP comes with Mac OS, so it’s not necessary to download and install it, however, there are a couple of necessary steps to configure it:

  1. Copy the default php.ini file:
sudo cp /etc/php.ini.default to /etc/php.ini
  1. Edit /etc/php.ini and uncomment this line to enable xdebug (not essential, but recommended):
zend_extension="/usr/lib/php/extensions/no-debug-non-zts-20090626/xdebug.so"

Apache

Apache too comes with Mac OS, so again, no need to download and install it. Its configuration, however, is a little more complex, but nothing scary. The described configuration will provide a special Apache “sandbox” environment for your projects. It uses the existing “Sites” directory in your Mac OS home directory.

  1. Create a subdirectory in this directory for each of your projects, ensuring that the directory name does not contain any characters that would be illegal in a URL. Within each of these subdirectories create another subdirectory called “web”; this will be become the web root of each project. The extra subdirectory is in case you wish to use a framework in your projects which may keep some of its files outside of the web server root (Symfony is a good example of this).
  2. Create a subdirectory called “logs” in your “Sites” directory; Apache will maintain two log files, access and error, for all the sandbox sites.
  3. Enable PHP5 with Apache by editing /etc/apache2/httpd.conf and uncomment the following line:
LoadModule php5_module libexec/apache2/libphp5.so
  1. Change the user and group to your username and “staff” respectively, also in /etc/apache2/httpd.conf:
User sbf
Group staff
  1. While still in /etc/apache2/httpd.conf, find the following configuration and change “Deny from all” to “Allow from all”:
<Directory />
    Options FollowSymLinks
    AllowOverride None
    Order deny,allow
    Deny from all
</Directory>
  1. Create and edit /etc/apache/users/user.conf with the following, changing “sbf” to the username:
<VirtualHost *:80>

    ServerName dev.local
    DocumentRoot /Users/sbf/Sites/

    RewriteEngine on
    RewriteLogLevel 1
    RewriteLog /var/log/apache2/rewrite.log

    # sites in the format http://[site].dev.local
    RewriteCond %{HTTP_HOST} ^[^.]+\.dev\.local
    RewriteCond %{REQUEST_URI} !^/error/.*
    RewriteCond %{REQUEST_URI} !^/icons/.*
    RewriteRule ^(.+) %{HTTP_HOST}$1 [C]
    RewriteRule ^([^.]+)\.dev\.local/(.*) /Users/sbf/Sites/$1/web/$2

    # Logging
    CustomLog /Users/sbf/Sites/logs/sandbox.access.log combined
    ErrorLog /Users/sbf/Sites/logs/sandbox.error.log

</VirtualHost>
  1. Restart Apache:
sudo apachectl restart

Then, for each of your sites, add an entry in /etc/hosts for with the format “name.dev.local” pointing to 127.0.0.1, where name corresponds to a subdirectory in your “Sites” directory. Don’t forget that the public subdirectory of each site is assumed to be “web”, so make a symlink to this if the framework you use has a different convention.

You should then be able to access each of your sites from URLs using the convention http://name.dev.local/ – where “name” again is a subdirectory within your “Sites” directory.

I’ve tested this setup procedure and It Works For Me [tm]. If, however, it doesn’t quite work for you as described, please let me know where you’re going wrong and how, if you were able, to resolve it, and I will update these instructions accordingly.

Uncategorized

Asterisk CDR Statistics

I’ve been a beneficiary of the open source software community for quite some time now. Ever since downloading Slackware Linux onto upteen floppy disks in 1995, I have used and profited from the use of open source software, whether it it be an operating system, programming language, server technology or desktop application. However, up until this point I’ve never given anything back to the open source community (I really don’t count my Twitter CLI script), chiefly because every software system I have created or worked on has been proprietary and subject to non-disclosure agreements. I’m not grumbling about that, not all software is meant to be or should be open source and working on such systems has paid the bills (just about).

So, what have I written? Unhappy about the lack of a decent (and free of charge) system for analysing caller detail records (CDRs) generated by Asterisk PBX telephone systems, I decided that I would combine a number of techniques that I have learnt and developed over the past year or so to put my own package together, and it’s now at the stage where I think it could be considered a beta. This means that it’s not perfect but it’s more or less there. I’ve started hosting it over at Github.

Principal features

  • Clean, modern interface.
  • Supports multiple Asterisk servers which record their CDRs to a MySQL database.
  • Uses Google Chart API to generate dynamic charts.
  • Quick and advanced search facilities.
  • Rolling monthly and annual reports.
  • MVC framework*.

Screenshots

Further development

Where does it go from here? I’m open to suggestion, which is why I’ve published it and I would welcome comments from anyone who’s interested and/or finds it useful, whether you are a developer or just an end user. Is it useful? Does it work out of the box on your system? Is it easy to install for someone who isn’t a developer? What other features would be useful, bearing in mind that the data produced by the Asterisk CDR MySQL add-on is relatively limited?

I know that the documentation is a little rough around the edges and so I shall be paying attention to that, certainly. I also want to do some really thorough and structured testing in order to ensure it’s as robust as possible. I’ve tested it, obviously, but I’ve not seriously tried to break it yet.

So please feel free to download it, either as a tarball for installation or from the Subversion repository if you would like a good look under the hood. Please submit any comments, suggestions or indeed any code you would like to contribute via the Google Code page in order that all information pertaining to it is kept in the same place. I won’t publish any comments made directly on this blog post for this reason.