I’ve moved!

After almost 12 years, and 15 posts, I’m leaving WordPress.com and closing this blog. Well, basically I will not post any more content here…

Anyway, I guess if you are one of the two persons who accidently happended to follow me at some point in time, you won’t cry yourself you sleep.

But if you do, you can start follow on www.lekegrind.no. “Lekegrind” is Norwegian for “playground” and will be where I will post different stuff about technology, home automation, IoT and everything fun.

So long and see you at lekegrind.no!


Magic Mirror – version 1


A while back I discovered the exiting world of “magic mirrors”. I don’t remember how or where it caught my attention, but I knew at that time I had to make one! The idea of having key information for planning the day readily available on a mirror, where me and my family looked every morning, seemed fantastic!

And very high-tech… Me like!

This was just before I would have my 10 weeks parental leave for my second son, so I imagined this was a nice side-project to baby feeding and diaper changing.


At first I considered using Windows 10 IoT since I’m mostly a Microsoft dude with knowledge of C#. But I learned the hard way that it didn’t support neither build-in WiFi or the Raspberry Pi camera. Then I discovered Michael Teeuw’s Magic Mirror project on GitHub. I installed it on a Raspberry Pi 3 I had lying around and was up and running in a couple of hours – including setting up Raspian.

Magic Mirror allows third-party developers to create custom modules and it has a growing community of people who builds them.

But in the beginning there wasn’t many third-party modules. So I decided I had to learn the software things around it before I started to build the mirror itself.

Learning by doing is the way I learn and I needed an idea for a module! My bathroom FM-radio will be rendered useless sometime in 2017 when digital DAB replaces analog FM in Norway. I want to be able to listen to music somehow. I accidentally found a Spotify Connect implementation for Raspberry Pi with an HTTP interface. That made it rather easy to make my first real module for Magic Mirror: Spotify Connect UI (GitHub).

My general rule for what should be shown on the mirror is very simple: I don’t want to display “everything” on the mirror, just the important stuff that helps plan the day! If I want to see soccer scores or cartoons I can do that on my laptop or mobile. OK, my Spotify-module didn’t exactly fit this rule, but since I made it (cough) …

Fundamentally I think an input interface has to work every time and for everyone. I did some testing of different user interaction techniques:

  • Camera for facial recognition was too unreliable to be usable. I had hoped to show some modules, like my personal calendar, only to me
  • Camera for motion detection. The idea was to turn on the TV-service on the Raspberry only when someone was in front of it. Unfortunately my monitor turns blue with a message when the display is off and used too long time to turn on again. I saw that someone suggested to put a relay on the power to the LCD lights only, but I didn’t want to risk destroying my monitor
  • PIR-sensor for turning on/off the monitor. Don’t work through glass, but I would have had the same problem as camera with blue screen anyway
  • Voice control is too unstable too, especially since my native language is Norwegian. Maybe it works good with English, but that is not the language I want to force my family to use.
  • Gestures was something I really wanted to implement to be able to hide/show things I didn’t want “everyone” to see, like my calendar or technical information like system temperature. Unfortunately I had no luck getting this sensor to work. I later found that the “gesture” sensor that DealXtreme sold me wasn’t a gesture sensor at all. I have now ordered the correct model with gesture control for next version of the mirror…



One of the first things I had to decide was how big this thing was going to be. The existing mirror on the bathroom was 80 cm wide including frame. Using a screen size calculator I worked out that this was comparable to a 36″ screen, excluding the frame. Removing space for the mirror frame, and then the frame of the monitor itself, I ended up deciding upon a 32″ screen. Probably would 34″ be better, but there aren’t many of those.

I wanted the mirror to be as narrow as possible so I had to find a monitor that 1) wasn’t too deep and 2) had at least one HDMI on the side. Very few product photos are photographed from the side or behind, so it wasn’t always easy to find a monitor that matched.

I bought a used 32″ Grundig LCD for NOK 1.000,- at Finn.no.

The next step was to strip it for the outer plastic and redundant parts on the inside. A bonus was that the speakers could easily be dismantled and moved around in the frame.


Reading a few magic blog posts of other people’s experience with building a magic mirror I realized that one of the biggest challenges was how to fasten the mirror itself to the frame and the frame to the wall.

I spent quite some time in 3D Builder to figure how I should build the frame and hang it on the wall. It was very useful to “simulate” different sizes to find the correct measurements.


Parts from left to right: 1) french cleat, 2) dummy box for everything inside (monitor, power, Raspberry etc),  3) frame and 4) mirror

I figured out that a slot on the inside of the frame would probably be best for securing the mirror in place. I also invested NOK 1.800,- in a handheld router I hopefully will get to use later.

For hanging the frame on the wall I found after a lot of searching a method that seemed to be perfect: a French Cleat. It let’s you securely hang the mirror close to the wall. You basically cut a board 45 degrees the length way. But you need good tools – which I didn’t have. I ended up using a hand saw and the result was not perfect. Good enough, but I wish I had a professional saw for a cleaner result!

Having already calculated the screen size I went down to the local hardware store and bought a long 15 x 100 mm wood board and cut it for the frame.


When the frame was finished I knew how big mirror I needed. I saw many recommendations to use real glass. Using foil on top of normal glass is very prone to scratches when cleaning or general handling during the build process, so a real mirror made the most sense to me.

The first shop I went to wanted NOK 2400. Luckily I checked a couple of others. Glassmester1 at Alnabru (Oslo) wanted NOK 900 when I visited them, but changed the price on email to NOK 1300 after “checking more”. It was still cheaper than the others…

The build process

Here I’m testing the placement of the different components inside the frame (that is held together using Gaffa tape).


Testing placement of the different components.

Ventilation/power cord holes were drilled. I made sure I could stick the power cord through one of them. I also checked that the holes weren’t so big that they might weakening the frame.


Frame ready to assemble

The Outer frame was painted white using a special paint for kitchen/bathroom furniture. I had to spend NOK 386 for 3 liters of paint, when I only needed 2-3 deciliters. I possible could have used normal, white paint to save some money.


Frame painted


Closeup of slot for mirror, ventilation hole and french cleat

Since the monitors weight would hang on the left and right boards, the weak spot would be the upper corners. I therefore attached two carpenter’s squares to make the structure stronger.


Reinforced the uppers corners where all weight of the monitor will be

Now I was ready to put the mirror inside the frame.


The mirror is in place.

I was very happy with my decision to use slots in the board!


Mirror fits perfectly!

I then screwed the bottom board in place, but didn’t use glue because I wanted the option to slide out the mirror on a later stage.

To make sure light from the components wasn’t visible through the mirror, I had to find something black to cover everything but the LCD screen itself. Since the size is quite big, it was difficult to find black cardboard in correct size. I found a black rubber carpet at Biltema that is normally used to make custom carpets for cars. At NOK 299 it isn’t cheap…


Black rubber mat with a hole cut for the monitor.

When I tested to assemble the Magic Mirror I noticed that the monitor would make it impossible to get the power cord through the holes. So I therefore did this before putting the monitor in place.


Power cord

Next I screwed the speakers in place on top of each ventilation holes.



To make sure the mat was held in place I screwed a ledge I had available to the upper board.


Ledge keeping the rubber mat in place.

Now it was time to fasten the monitor. I made two custom boards that would keep the monitor in place. I used just two screws on each since I believe that would be enough and it makes it easier to take the monitor out later.


Board holding the monitor in place angle 1


Board holding the mirror in place angle 2


I then had to solder the wires to the speaker because they fell off.


No IoT project is complete without a bit of soldering!

I didn’t want the bright light of the IR receiver (for remote controlling the Magic Mirror) to be visible through the mirror, so I made sure the IR light is available through one of the lower ventilation holes. Not the best solution, but I don’t use the remote to other things than to tune brightness once.


IR light seen through one of the lower ventilation holes.


The IR light seen from behind.

The Raspberry Pi and a temperature sensor is fastened using Gaffa tape.  I will replace it with a 3D printed side mount later.


Low tech mounting of Raspberry Pi and temperature sensor

Finally, everything is ready for mounting on the wall!


Everything in place!

I put the mirror on the bathroom wall where it should be, without fastening it. At this time I got my first really big disappointment. The mirror was noticeably darker compared to the old one! I had suspected it earlier when I tried the mirror with the black mat behind it, but hoped it was because of different lighting conditions.

Damn, my wife would never accept this!

This was a real setback since the whole point of this project was to make it possible to quickly see what would happen that day during the morning cleanup.

Plan B was to put it in the outer corridor. It was not ideal because we normally not spend more than the time it takes to put on shoes and a jacket. But out of other choices I went with that.

I removed the old mirror and screwed on the second part of the French cleat. Notice I don’t put the screw’s on a straight line since I guess that would weaken the board if it starts to crack.


Ready to mount!

Finally I used a power outlet for the lamp in the roof and guided the wire as nice as I could to it.

I made three mistakes at this stage that I later have to fix:

  1. The outlet for the lamp will of course turn off the mirror as well. Duh!
  2. Since I need to lift the frame up to release it from the French cleat I will have to remove the cable organizer since it’s too close to the frame.
  3. Ideally I should have put the frame 30-40 cm up to align better with the eyes when standing.

Anyway this is how it looks now:


Magic Mirror ready for use!


  • I’m using the monitors own feature to turn off the monitor at midnight and on at 05:00 in the morning.
  • I’m using snippets on Juice SSH-client on my mobile to quickly run script for making backup and updating the RPi itself and MM and it’s modules

Future improvements

In addition to the obvious fixes mentioned before I want to do the following:

  • Add a module for public transport information (only visible in the morning when we need it) DONE: https://github.com/CatoAntonsen/MMM-Ruter
  • Add a gesture sensor to be able to turn on some modules
  • Get facial recognition to work better

Have you built a Magic Mirror or something similar? Share your experiences in the comments section below!

Upgrade gotcha – Microsoft don’t follow it’s own recommendations for web template ID’s!

During a recent upgrade of a SharePoint 2010 solution to 2013 I discovered something I first thought must be a bug in the upgrade process.

It was actually just “luck” that made us aware of the problem. Under each region site we had a landing page where users could add sub webs using a custom web part for provisioning. Visually you couldn’t tell something was wrong, but the provisioning failed because the custom code in the web part required the landing page to be of a specific site definition.

Sure enough, the WebTemplate property of the web revealed that the template is DOCMARKETPLACESITE. At first I thought I had made an error in the XML file that you place in 15\CONFIG\UPGRADE before upgrade. But no, it looked OK. And there was no signs of what had happened in the upgrade logs – except for a successfully web upgrade.

Then it hit me, what site definition id do DOCMARKETPLACESITE use? Oh, “10000” – the same as ours!

But hey, isn’t that a “reserved” ID for custom site definitions according to the documentation:

Specifies the ID of the site definition. To avoid conflict with IDs that are natively used in Microsoft SharePoint Foundation, use IDs with values greater than 10,000 when you create custom site definitions.

You can argue that they say greater than 10.000, but I bet most people don’t expect Microsoft to use 10.000…

To solve this we had to do the following:

  1. Change the web template ID in the SP2013-version of the site definition to a new number (15/TEMPLATE/<lcid>/XML/webtemp*.xml)
  2. Create a web on the same level as the old one, but using the new template
  3. Move all subwebs to the new web (Export-SPWeb / Import-SPWeb)
  4. Delete the old web
  5. Rename the new web

A basic check that could have revealed this earlier is to run the following PowerShell script in old and new environment and do a text compare to spot changes:

$wa = Get-SPWebApplication <URL> 
$wa | Get-SPSite -Limit All | Get-SPWeb -Limit All | Select-Object Url, WebTemplate | Export-Csv ".\[NAME].csv"

Using KDiff3 with Visual Studio 2010

For a long time I’ve hated the built in compare/merge tool in Visual Studio. If the changes are just somewhat complex, the compared result is really confusing and I have to spend alot of time trying to see what has changed.

I’m an big fan of the Windows Explorer (+ much more) replacement Total Commander and love it’s compare tool. But since it doesn’t work within Visual Studio I had to export the files from TFS and to the compare using Total Commander.

I started to investigate for a better solution…

The result was the free tool KDiff3 and some Visual Studio configuration:

  1. Download and install KDiff3
  2. In Visual Studio:
  • Tools > Options
  • Source Control > Visual Studio Team Foundation Server
  • Click button Configure User Tools
  • Click button Add, and fill in:
  • Extension: .*
  • Operation:Compare
  • Command: [browse to kdiff3.exe]
  • Arguments: %1 %2 -L1 %6 -L2 %7 -o %2

I have found similar posts about configuring KDiff3 in VS, but they’ve used different arguments. But I didn’t like those. If you want to try yourself, you can read this blogpost.

Thank God for Windows Home Server!

This week was the first in my new job in Bouvet ASA in Oslo. On the first day I was handed a Lenovo ThinkPad W500 with Windows 7. I installed SharePoint 2007, Visual Studio 2008 and all the dozens of applications and utilities I can’t develop without. After a couple of days I was told it was very likely I would start on a SharePoint 2010 project. Cool! Since the machine only had 4 GB of RAM it was out of the question to run SharePoint 2010 in a virtual machine. I decided to make a VHD with Windows Server 2008 R2, SharePoint 2010 and Visual Studio 2010 and boot from it. At the end of the week I had two complete and separate development environments for both SharePoint versions on my machine. I had even started to prepare for the potential 2010 project by making a test project to investigate some ideas I had.

On Saturday I booted into Windows 7 and read news as usual while eating breakfast. After that I rebooted into Windows 2008 R2 and wanted to work some on my test-project. After the boot load screen I got an bluescreen. Booted into Safe Mode, but again got an bluescreen. Tried to boot into Windows 7 but that bluescreened as well! WTF happened?!?

I would normally boot with a bootable utility CD to be able to fix problem or rescue files, but I thought this was an excellent opportunity to test a restore from my Windows Home Server backup.Luckily I had installed the WHS client on the Windows 7 machine and a full backup, including the VHD, was done Friday night. After 30 minutes downloading and burning the Restore CD and put network drivers on a USB stick – and then 1,5 hour restore time my machine was in perfect state.

Thank God for Windows Home Server!

“Failed to retrieve the list schema for feature” caused by missing BaseView in List element

I needed a very basic custom list template with one custom content type and a few custom fields. I first started by copying schema.xml from a feature I recently used and started to modify it. To make a long story short: I got some errors in the views I couldn’t figure out, so I decided to start fresh by copying the schema.xml from the OOB CustList feature and copy’n’paste needed customization from the “old” schema.xml.

When I tried to create a list I got the famous: 

Cannot complete this action.
Please try again.   at Microsoft.SharePoint.Library.SPRequestInternalClass.CreateListFromFormPost(String bstrUrl, String& pbstrGuid, String& pbstrNextUrl)
   at Microsoft.SharePoint.Library.SPRequest.CreateListFromFormPost(String bstrUrl, String& pbstrGuid, String& pbstrNextUrl)

In the Sharepoint logs I found this:

Failed to retrieve the list schema for feature [FEATURE GUID], list template [TEMPLATE]; expected to find it at: "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\Template\Features\[FEATURENAME]\[LIST]".    
Failed to find the list schema for FeatureId ‘[FEATURE GUID]’, list template ID [TEMPLATE].  Cannot create list in web "[WEBURL]" at URL "(null)".    

This error is often caused by having more than one directory level in the feature folder. But in my case none of the suggestions Google gave me was valid.

I therefore tried to start with a fresh schema.xml but this time without modification. Deployed and added a list. No problem. I thereby modified the List attributes. Deploy. No problem. Added the content types. Again no problem. Added the fields. No problem! Added ViewFields. No problem!!! At this stage the schema.xml was practically identically to the one that caused the error – with one exception: The BaseView=”0” attribute of the List element was included in the working version. Hmmm, the documentation states that this attribute is optional. But as soon as I remove it, the error occurs.

Conclusion: The BaseView attribute is not optional. At least in this case…

AutoCompleteExtender only returnes ‘undefined’

I was making a simple Ajax solution for an application running in Sharepoint context in the 12 layout hive (aka application page). I needed a textbox where the user could start typing a job title and the system would suggest previous titles stored in a database. A perfect task for the AutoCompleteExtender.

The problem was that after writing the necessary 3 letters in the textbox I only got a looong list of ‘undefined’ entries. I tried to debug the webservice, but my code seemed never to run. I Googled and found others having the same problem, but their problem was caused by the fact that they returned only integers and not text.

I needed to find out what was happening in the background, so I started Fiddler and ran my solution, typed in a few characters and found this result from the server:

<span id="ctl00_PlaceHolderMain_LabelMessage">Could not create type 'Itera.IDM.Web._12.TEMPLATE.Layouts.IteraIDM.TitleService'.&nbsp;&nbsp; at System.Web.UI.SimpleWebHandlerParser.GetType(String typeName) <br>&nbsp;&nbsp;&nbsp;at System.Web.UI.SimpleWebHandlerParser.GetTypeToCache(Assembly builtAssembly) <br>&nbsp;&nbsp;&nbsp;at System.Web.Compilation.SimpleHandlerBuildProvider.GetGeneratedType(CompilerResults results) <br>&nbsp;&nbsp;&nbsp;at System.Web.Compilation.BuildProvider.CreateBuildResult(CompilerResults results) <br>&nbsp;&nbsp;&nbsp;at System.Web.Compilation.BuildProvider.GetBuildResult(CompilerResults results) <br>&nbsp;&nbsp;&nbsp;at System.Web.Compilation.BuildManager.CompileWebFile(VirtualPath virtualPath) <br>&nbsp;&nbsp;&nbsp;at System.Web.Compilation.BuildManager.GetVPathBuildResultInternal(VirtualPath virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean allowBuildInPrecompile) <br>&nbsp;&nbsp;&nbsp;at System.Web.Compilation.BuildManager.GetVPathBuildResultWithNoAssert(HttpContext context, VirtualPath virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean allowBuildInPrecompile) <br>&nbsp;&nbsp;&nbsp;at System.Web.Compilation.BuildManager.GetVirtualPathObjectFactory(VirtualPath virtualPath, HttpContext context, Boolean allowCrossApp, Boolean noAssert) <br>&nbsp;&nbsp;&nbsp;at System.Web.Compilation.BuildManager.GetCompiledType(VirtualPath virtualPath) <br>&nbsp;&nbsp;&nbsp;at System.Web.Compilation.BuildManager.GetCompiledType(String virtualPath) <br>&nbsp;&nbsp;&nbsp;at System.Web.Script.Services.WebServiceData.GetWebServiceData(HttpContext context, String virtualPath, Boolean failIfNoData, Boolean pageMethods, Boolean inlineScript) <br>&nbsp;&nbsp;&nbsp;at System.Web.Script.Services.RestHandler.CreateHandler(HttpContext context) <br>&nbsp;&nbsp;&nbsp;at System.Web.Script.Services.RestHandlerFactory.GetHandler(HttpContext context, String requestType, String url, String pathTranslated) <br>&nbsp;&nbsp;&nbsp;at System.Web.Script.Services.ScriptHandlerFactory.GetHandler(HttpContext context, String requestType, String url, String pathTranslated) <br>&nbsp;&nbsp;&nbsp;at System.Web.HttpApplication.MapHttpHandler(HttpContext context, String requestType, VirtualPath path, String pathTranslated, Boolean useAppConfig) <br>&nbsp;&nbsp;&nbsp;at System.Web.HttpApplication.MapHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() <br>&nbsp;&nbsp;&nbsp;at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean&amp; completedSynchronously)</span>

Aha! That namespace didn’t look right!

Since I created the source .aspx and .asmx files in the 12/TEMPLATE/Layouts/[SOLUTION]-folder, both files got an default namespace according this folder, like this: Itera.IDM._12.TEMPLATE.Layouts.IteraIDM. I had refactored it to Itera.IDM.Web and Itera.IDM.Ajax but forgot to update the .asmx file itself. Bummer!