Rss 2.0 via FEED

About...

cc128-large_01 I recently bought a device to monitor our household energy consumption. After looking at a few I lumped for a CurrentCost Envi. this is a great little device that comes in two parts – a transmitter with jaws that wrap around the main power cable coming into your home and a desktop display unit. The communication is all wireless and I have found that it works okay through two thick brick walls.

the reason for going with this particular unit was that it has a data port that can connect to a USB port and feed it’s readings to a PC – I wanted to be able to monitor the readings on my PC and chart/analyse them at will.

imageThe communication to the PC is basically via USB, but emulating a serial port COM connection – the CurrentCost website has links to the drivers you’ll need for this.

I wanted to, not only, record the readings but to chart them (on my website), get regular updates via various notification methods and a few other bits. Unfortunately, none of the software applications listed on their website covered all the items that I wanted – so I set about writing something myself…

My initial thoughts were around just sending the data to Google PowerMeter, but at that stage the API was not public and their forums/groups were not very active (6 posts in about 18 months), so I abandoned that and decided a ‘DIY’ approach was needed. 
UPDATE: It looks like there may be some substance to it now, so that is another area to look at (another plugin)…

imageThe requirements were pretty simple – I wanted a service that grabbed the readings as they came in, decoded them into something intelligible and then pushed them out to a number of ‘modules’ that would do something with the reading. the ‘modules’ would be self contained and new modules could be added at any time. The initial modules would be :-

  • Tweet the reading at a regular interval
  • Record the reading (in a database, Xml file or the like)
  • Send the reading to a website / webservice

It seemed a simple Windows Service with a COM port would be enough to grab the reading, the readings are all in Xml so another class to parse the Xml would be needed and then for the ‘modules’ a ‘plugin’ type architecture was called for. I came up with an interface that all plugins would implement and a method of loading them in dynamically.

Each plugin would inherit from the IPowerMonitorPlugin interface and to load the plugins, each one would be specified in the app.config file with a filename and classname. The service would look at each plugin entry, load the DLL and create an instance of the plugin class :-

    private void LoadPlugins()
    {
        plugins = new ArrayList();

        NameValueCollection appSettings = ConfigurationManager.AppSettings;
        foreach (string key in appSettings.AllKeys)
        {
            if(key.ToLower().StartsWith("plugin"))
            {
                string path = AppDomain.CurrentDomain.BaseDirectory;
                string[] config = appSettings.Get(key).Split(':');
                Assembly ass = Assembly.LoadFile(path + config[0]);
                IPowerMonitorPlugin plugin = (IPowerMonitorPlugin)ass.CreateInstance(config[1]);
                if (null == plugins)
                {
                    plugins = new ArrayList();
                }
                if (!plugins.Contains(plugin))
                {
                    plugin.Init();
                    plugins.Add(plugin);
                }

            }
        }
    }

When the service was working and decoding the readings correctly, I started adding plugins – first was a simple ‘RawXmlWriterPlugin’ – this simple wrote the raw Xml reading data (Reading.RawXml) out to a text file – just to make sure it was working and we were decoding the Xml correctly.

imageThe next service was posting the data to a website – I found this great website (pachube.com) which allows you to track environmental data measurements, have multiple feeds, multiple measurements and has a lot of options for getting data in and out. The API that they provide is pretty simple to push data into and their website allows plenty of ways to visualize the data – for example here is a link to my last 24 hours energy consumption in a chart format, here is my latest temperature reading and here is an archive of all the energy data I have ever posted. there are also mash up to things like iGoogle widgets, Google’s Visualization API, Google Sketchup, iPhone Apps, Android Apps and this rather neat gauge.

From there I started the Twitter service….

 imagePachubePosterPlugin

The plugin for posting to Pachube requires that you have already create a feed with two datastreams (datastream 0 is energy and datastream 1 is temperature). You will need an API Key and the feed id. Both these items are configured in the app.config file also.

 TwitterPlugin

The plugin for ‘tweeting’ to twitter is also pretty simple – all you need is an account (username and password) and the ‘handle’ of the person/account you want to send the message to (if you want to send a direct message). You also specify the message text you wish to send (with placeholders for the energy and temperature values) an the interval (in minutes) of how frequently you wish to send the tweets.

SQL / Xml Storage Plugin

Watch this space … ;-)

Source and Package

For the time being either send me an email or post in the comments if you’d like access to the source code.

If you want to run this software yourself then here is a link to a zip file containing the full package. To get it installed, do the following :

  • imageUnzip the package contents into a folder (“C:\Program Files\PowerMonitorService\” would be good)
  • Open a command prompt and change to the folder above
  • Run the following command line…

“C:\Windows\Microsoft.NET\Framework64\v2.0.50727\InstallUtil.exe” PowerMonitorService.exe     (if you are running a 64 bit machine… or)
“C:\Windows\Microsoft.NET\Framework\v2.0.50727\InstallUtil.exe” PowerMonitorService.exe     (if you are running a 32 bit machine… or)

  • Open the PowerMonitorService.exe.config file (in Notepad) and edit your configuration as needed – save when done.
  • Now start the service (Windows..Run..services.msc, find the one named PowerMonitorService, right click and choose “Start”)

Enjoy…

GEO 51.4043388366699:-1.2875679731369

Share/Bookmark

Posted: Tuesday, May 11, 2010 5:13:16 PM (GMT Daylight Time, UTC+01:00)  #   Comments [0]
TAGS: .NET | C Sharp | Development | Software | Technical | Twitter

USBdriveThis post is for my own benefit more than anything. I frequently have to ‘google’ for the instructions to make a bootable USB drive to install some version of Windows from. So, to save time in the future, here are the instructions :

Open a command prompt As Administrator. Run diskpart. Enter list disk – this will list all the attached disks, make note of the USB drive disk number (2 in my case, so substitute 2 in the commands below for whatever number it shows on your system :- image

  • select disk 2
  • clean
  • create partition primary
  • select partition 1
  • active
  • format fs=fat32
  • assign
  • exit

GEO 51.4043388366699:-1.2875679731369

Share/Bookmark

Posted: Saturday, April 03, 2010 1:31:03 AM (GMT Daylight Time, UTC+01:00)  #   Comments [0]
TAGS: Software | Technical

After a brief hiatus (i.e. hectic work schedule for a few months), I am back to reading. The list is currently :-

Actually, that is wrong. I picked up ‘ReWork’ by the 37 Signals guys and read it cover to cover, so that’s no longer on the list ;-)   – what a great book. Full of down to earth pragmatic advice and common sense (as you’d expect from these guys), a ton of snippets to take away and really inspiring. I must read this again to make sure I got everything.

GEO 51.4043388366699:-1.2875679731369

Share/Bookmark

Posted: Thursday, March 25, 2010 10:35:50 PM (GMT Standard Time, UTC+00:00)  #   Comments [0]
TAGS: Books

Edge subscription file import and export process

This is a pretty obscure gotcha..

I was trying to export an Edge Subscription XML file from my Edge Transport server (a demo Exchange 2010 environment)
There is no GUI for this in Exchange Management Console, so you have to use the Exchange Management Shell.

Opened up EMS and entered the command :

New-EdgeSubscription –Filename “c:\Edge.xml”

image

image
I kept getting an error saying that “When running this task inside the organization, the Filename parameter must NOT be set.” Also, Google told me that a bunch of other people had experienced similar issues but had not found a solution.
A little investigation into why it thought I was ‘inside the organization’ uncovered that I had set the primary DNS suffix the same as the domain name. Changing this to something else, rebooting the server and trying it all again worked a treat.

Now… back to that Edge Subscription…

 

GEO 51.4043388366699:-1.2875679731369

Share/Bookmark

Posted: Tuesday, February 23, 2010 11:59:23 AM (GMT Standard Time, UTC+00:00)  #   Comments [0]
TAGS: Exchange

It seems that ‘Document Access’ from Outlook Web Access (OWA) is no longer supported in Exchange/OWA 2010.

image

http://technet.microsoft.com/en-us/library/aa998911.aspx#Disc2007to2010

imageHowever, the way this element of ‘Discontinued Features and De-Emphasized Functionality’ is worded (“Can’t use…”) makes me think it is more of a known issue than a conscious decision they have made – where is the reasoning and/or alternative solution ? no mention…

Also, all of the configuration functionality for this feature still exists in Exchange 2010 Management Console.

Smells like they just didn’t get the Outlook Web App finished in time. I wonder if this will be in SP1 – it was a pretty neat feature after all – or will SP1 remove the configuration elements in the Management Console ?

GEO51.4043502807617:-1.28752994537354

Share/Bookmark

Posted: Monday, February 22, 2010 6:36:14 PM (GMT Standard Time, UTC+00:00)  #   Comments [0]
TAGS: Exchange

I was discussing ‘googlability’  - a new word I made up meaning ‘the ability to find via Google’ – of our knowledgebase with one of the technical guys at work.
It seems that we seldom get matches in Google searches (and the built in search is somewhat lame) – I was quite surprised with the fact that Google wasn’t matching anything.

Looking into it a bit further, I found that although our knowledgebase is public, the Urls are pretty undiscoverable, all having a ‘articleid’ parameter – obviously, the GoogleBot couldn’t just guess at the values and so was skipping the majority of our article, apart from the few listed on the main page.

We needed to give it some hints by adding a sitemap. I (ever so) briefly toyed with adding a sitemap page to the knowledgebase website using the standard XML based sitemap protocol etc, but our site is written in PHP and I didn’t want to get bogged down in all that again…
In a rare burst of being pragmatic and keeping things simple (as opposed to _way_ over engineering a solution) I recalled that Google’s webmaster tools allow you to submit a text file as a sitemap with one Url per line.

I knew the format of the Url for our articles so it just required a bit of PowerShell to generate a bunch of lines containing Urls with sequential numbers and write them to a file. version 1 looked like this :

set-content "c:\sitemap.txt" (1..1000 | %{ "http://support.c2c.com/index.php?_m=knowledgebase&_a=viewarticle&kbarticleid=$_&nav=0`n" })

However, uploading this sitemap caused the Google machine to choke and spew out a bunch of errors about invalid Urls… A little more digging uncovered that the text file uploaded must be encoded in UTF8. So version 2 looked like this :

set-content "c:\sitemap.txt" (1..1000 | %{ "http://support.c2c.com/index.php?_m=knowledgebase&_a=viewarticle&kbarticleid=$_&nav=0`n" }) -encoding UTF8

Out popped a text file with 1000 Urls, in the correct format, with the correct encoding and accepted by the Google machine with no problems.
Probably 10 minute work all in – I wouldn’t have even got the PHP coding tools fired up in that time – reminder to self “KISS works !!

GEO51.4043502807617:-1.28752994537354

Share/Bookmark

Posted: Friday, January 15, 2010 2:40:54 AM (GMT Standard Time, UTC+00:00)  #   Comments [1]
TAGS: PowerShell | Web

I was working on an old (classic) ASP page the other day. It was pulling data from an Access database file and using an ODBC driver to get the connection.

It was working fine on a Windows 2003 server, but when I pulled the file into a local website on my Windows 7 machine (with Office 2010 beta) it kept failing at the ODBC layer. The reported error message was :

Microsoft OLE DB Provider for ODBC Drivers error ‘80004005’
[Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified

Looks like the driver specified in my connection string couldn’t be found. I was using the following :

    objConn.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=c:\inetpub\wwwroot\pstdiscovery.mdb;"

This all looked correct and checking the excellent “ConnectionStrings.com” website they were saying the same thing – strange. It then struck me that I’m using Win 7 and Office 2010, either of which could have changed the ODBC driver or installed a new driver, so checking the “Data Sources (ODBC)” tool I see that the driver also works with .accdb files, so I’m guessing this is an updated driver.

Changing the connection string (adding the *.accdb) was the next step.

objConn.Open "DRIVER={Microsoft Access Driver (*.mdb, *.accdb)}; DBQ=c:\inetpub\wwwroot\pstdiscovery.mdb;"

Testing with this new connection string worked fine - problem solved….

image

GEO51.4043502807617:-1.28752994537354

Share/Bookmark

Posted: Wednesday, January 13, 2010 10:23:22 PM (GMT Standard Time, UTC+00:00)  #   Comments [0]
TAGS: Development | Scripting | Web

imageI ran into some trouble with Hyper V the other day – I had booted from a VHD into Windows Server 2008 R2 and was trying to start a VM – I got the usual  ‘The virtual machine could not be started because the hypervisor is not running” error.
I had just had a BIOS failure on the machine so I figured it may have switched hardware virtualization support off in the BIOS when it reloaded the defaults.

Checking the BIOS, I found it was switched on – strange. I Googled a bit but everything seemed to be around flipping the setting in BIOS, when I knew to be correct.
Some further investigation around the boot environment and BCDEDIT settings I found the parameter “HypervisorLaunchType”, thinking this could well be connected, I set the parameter to “auto” in the BCD configuration:

BCDEDIT /set {big-long-guid} hypervisorlaunchtype auto 

This fixed it !!
So now all my BCD configurations go like this:

BCDEDIT /copy {current-or-guid} /d "New Boot Option"
BCDEDIT /set {new-guid} device vhd=[V:]\vmimage.vhd
BCDEDIT /set {new-guid} osdevice vhd=[V:]\vmimage.vhd
BCDEDIT /set {new-guid} detecthal on
BCDEDIT /set {new-guid} hypervisorlaunchtype auto

GEO51.4043502807617:-1.28752994537354

Share/Bookmark

Posted: Monday, November 23, 2009 9:51:31 AM (GMT Standard Time, UTC+00:00)  #   Comments [0]
TAGS: Productivity | Software | Support | Technical | Windows 7
Copyright © 2010 Ken Hughes. All rights reserved.

Creative Commons License
This work is licensed under a Creative Commons Attribution 2.0 UK: England & Wales License.