Geo-fence Garage Door Using Raspberry Pi, Azure, C#, and Windows Phone
Part One

You’ve experienced the joy of making LEDs blink and change colors. What is next, what will you do with all this power? The power that is making you feel like a superhero without a villain, empty and useless.

Meet your evil garage door. Think of it as a self-absorbed celebrity who will never try to remember names or acknowledge your existence. It expects you to know everything about it, yet it won’t even notify you when you forget to close it, or give you confirmation when you are not sure whether you closed it or not.

Before you get started with part one, here is what you will need.
Hardware:
  • Raspberry Pi (I am using Raspberry Pi 2 Model B).
  • Power cord for the Raspberry Pi
  • SD Card
  • Internet connection (I will use wired connection)
Software:
Go to RaspberryPi.org locate Raspian Debian Wheezy, download it, save it to your computer, and unzip it. Next you will a need a tool that will let you write the OS image you downloaded to your SD Card, I am using Win32 Disk Imager, you can download it from here Win32DiskImager, after download and installation, run Win32DiskImager.
For image file select the OS image you downloaded, select your SD Card’s drive letter from the Device dropdown, and click Write.
Win32DiskImager

After your SD Card is ready, eject it from your machine and insert it into your Raspberry Pi. We are going to use PuTTY SSH client to remote into the Pi, you can download it from this link PuTTY

Connect the Raspberry Pi to your internet connection (I am using wired connection) and hookup the power. Wait for the Pi to power up (it may take 1 -2 minutes). Try to locate the IP address of the Pi, you may use whatever tool you like to locate the IP address, for me all I have to do is navigate to my router admin page, enter my credentials, and view all connected device.

Start PuTTY SSH client, enter the IP address in the Host Name field, enter 22 for Port, and click Open.
PuTTY

Enter the default user name pi and the default password raspberry. You will now change the default password, start the configuration tool
sudo raspi-config

This will load the configuration tool. Select Change User Password and enter twice. You will now be asked to provide new password, provide it and confirm it, you will now be taken back to the main configuration page. You may also want to expand the file system, select Expand Filesystem and then enter, to confirm enter again. Select finish (using the left/right arrows) and enter. Select Yes for reboot and give a minute or two for the Pi to restart.

Restart PuTTY, enter the Pi’s IP address, and login. You will now get and install updates for your Pi. Run
sudo apt-get -y update && sudo apt-get -y upgrade

This can take 30 or more minutes, go find some entertainment while your Pi is getting and installing the updates.
After the update completes, reboot the Pi by running the reboot command
sudo reboot

Restart PuTTY again, enter your IP address if you didn’t save your session. Provide username pi and the new password you created earlier.

You are now ready to get Mono. Add the Mono Project signing key
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF

Add package one repository to your system, enter after typing the command
echo "deb http://download.mono-project.com/repo/debian wheezy main" | sudo tee /etc/apt/sources.list.d/mono-xamarin.list

You will need to add a second repository to your system, in addition to the generic Debian/Ubuntu repository above. Add the second repository. enter after the command
echo "deb http://download.mono-project.com/repo/debian wheezy-apache24-compat main" | sudo tee -a /etc/apt/sources.list.d/mono-xamarin.list

Before installing get and install updates by running
sudo apt-get -y update && sudo apt-get -y upgrade

This time things will go much faster. You can now install Mono, run
sudo apt-get install mono-complete 

Enter Y to confirm the installation. This can take 5 or more minutes.

While Mono is getting installed, go get a tool that will help you transfer files between your PC and the Pi. I am using WinSCP here is a link WinSCP download it, install, and run. Enter your IP address and password, then click Login.
WinSCP

You can now move files and folders between the Pi and your machine.
WinSCP

We are ready to build C# applications that will run on Raspberry Pi. Start Visual Studio, click File | New | Project. Select Console Application, enter HelloRaspberryPi for name, and click OK.
Visual Studio

In the main method add the code below
Console.WriteLine("Hello Raspberry Pi, I am C# Application");
Console.WriteLine("Press enter to exit");
Console.ReadKey();

and build the project.
C# Code


Go to WinSCP, locate the Debug folder of your project, and drag the HelloRaspberryPi.exe file to the pi folder of the Raspberry Pi.
Move File


Go to the Pi and run your application
sudo mono HelloRaspberryPi.exe 

Run Program

Your hello program will run. enter to end the program.
C# program running on Raspberry Pi

Go to Part Two
;