Building a DIY Home Alarm Part 2 (Netduino Plus WebServer)

For this second part in the series I wanted to prototype the network connectivity of the Netduino. Why? Because I want the alarm to message me some how if some one breaks in AND I want to be able to interact with it from my phone.

Prototype Features

  • Run a threaded web server, capable of returning 200 OK with the HTTP body of “Hello World”
  • Flash the onboard LED whenever the webserver services an inbound request
  • Trigger a sound (I’ll cover this sound in more detail later in my posts). I was using a transistor switch to trigger a 555 timer which makes a 3khz sound to the speaker


I started off using any old network cable to connect to the Netduino. After some thought and discussion on the NetDuino chat I realized I should be using a Crossover cable. Luckily I had one to hand. (Good thing I hoard my electronics stuff :P). I made sure the network cable was connected before I turned the NetDuino on. I think I read somewhere that with certain versions of the flashed software, it can be troublesome connecting the network cable afterwards.

I discovered that the Netduino’s network configuration can be configured programatically or through the tool that comes with the microframework MFDeploy.exe (I found it in C:\Program Files (x86)\Microsoft .NET Micro Framework\v4.1\Tools). Through a lot of experimentation I figured the easiest way of me connecting the pc and the netduino would be to manually assign ip addresses on the same subnet mask. My laptop was initially setup for DHCP assigned ip on the physical network connection and the netduino was pre-wired with an ip. I set the pc to be a manually assigned IP of and the netduino to and both on a subnet mask of

Using Fiddler I sent HTTP Get Requests to the web server and received 200 OK messages back with the content “Hello World”.


Source Code

Note: I used the .Net Micro Framework Networking Toolkit to run the web server.
PS: Make sure you use the assembles found in the folders prefixed with “Micro” as they are compiled for the micro framework.
PPS: I used port 8080 as my machine is running IIS on port 80.

using System;
using System.Net;
using System.Net.Sockets;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using SecretLabs.NETMF.Hardware;
using SecretLabs.NETMF.Hardware.NetduinoPlus;
using MFToolkit.Net.Web;
using Microsoft.SPOT.Net.NetworkInformation;

namespace WebServer
    public class Program
        public static void Main()
            HttpServer httpServer = new HttpServer(8080, new MyHttpHandler());

    public class MyHttpHandler : IHttpHandler
        private OutputPort led = new OutputPort(Pins.ONBOARD_LED, false);
        private OutputPort sound = new OutputPort(Pins.GPIO_PIN_D5, false);
        private bool playSound = false;

        public void ProcessRequest(HttpContext context)

            if (playSound == false)
                playSound = true;
                playSound = false;


        public void BuildHttpResponse(HttpResponse httpResponse)
            httpResponse.HttpStatus = HttpStatusCode.OK;
            httpResponse.WriteLine("Hello World");

Leave a Reply

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

You are commenting using your 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