Will be shown how to integrate a windows phone device and a micro framework board (to build a simple remote control).


How use a windows phone device as remote control of a Fez Panda II/MicroFramework board ? A windows phone device can be connected to a wifi network (for example a wifi router). If you have also a .Net Micro Framework board connected to the wifi network; you can send some http rest commands from the windows phone device to the .Net Micro Framework board. The netmf / microframework board, it must support the tcp/ip protocol through a connect shield; in this way you can implement a small http web server. There is also the possibility to send from micro framework board tile push notification to the windows phone. In this exaple it will be used the FEZ Ultimate Kit. In the download file there are two project. There are also two video on youtube that show the project in action. - Stefano Marchisio / My windows phone marketplace

windows-phone-microframework-rest.png

At this links you can find some little videos on YOUTUBE that show this project in action:
Windows Phone 7.1 + .Net Micro Framework (How use a windows phone device as remote control)
Windows Phone 7.1 + MicroFramework and Tiles allarm (by push notification)
YOUTUBE channel: (http://www.youtube.com/user/PhoneMicroFramework1)

First project
In this project is showed how use Windows Phone as remote control. Into the silverlight application (windows phone side) has been used the WebClient class to manage the http rest call (it is in asynchronous mode). Into the fez panda II (microframework board side) has been written some codes that process the incomming commands and manage the i/o port. The essential thing is to define a syntax for the commands; that must be known both client/server side. Alternatively you can also use PhoneGap for the cliet side; so you can create a cross platform apps.

www.board.it/turnOn?number=n (turn on the specified port)
www.board.it/turnOff?number=n (turn off the specified port)
www.board.it/status?number=n (read the status of the specified port)

In the download there is a version with silverlight and a version with phonegap. With phonegap it has been used jquery mobile and knockout.js. The server side is the same for both. Silverlight example - PhoneGap example

Second project
In this project is showed how create an Windows Phone app that uses tile push notificaton as temperature allarm. On the Micro Framework board there is a thread that check a temperature sensor. If the temperature change to/from a predefined range the code on the Micro Framework board send a tile push notification to the Windows Phone (this is a native silverlight application/is not a phonegap application).

private string CreateMessage(int type, double value)
{

    ...

   string message = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
     "<wp:Notification xmlns:wp=\"WPNotification\">" +
     "<wp:Tile>" +
     "<wp:BackgroundImage>" + backgroundimage + "</wp:BackgroundImage>" +
     "<wp:Count>" + count + "</wp:Count>" +
     "<wp:Title>" + title + "</wp:Title>" +
     "<wp:BackBackgroundImage>" + backbackgroundimage + "</wp:BackBackgroundImage>" +
     "<wp:BackTitle>" + backtitle + "</wp:BackTitle>" +
     "<wp:BackContent>" + backcontent + "</wp:BackContent>" +
     "</wp:Tile> " +
   "</wp:Notification>";

    ...

   return message;
 }

private void SendHttpRequest(string uri, string message)
{
   HttpWebResponse webres = null;
   HttpWebRequest webreq = null;
   try 
      {
        byte[] buffer = Encoding.UTF8.GetBytes(message);
        webreq = (HttpWebRequest)WebRequest.Create(uri);
        webreq.Method = "POST";
        webreq.ContentType = "text/xml";
        webreq.Headers.Add("X-WindowsPhone-Target", "token");
        webreq.Headers.Add("X-NotificationClass", "1");
        webreq.ContentLength = buffer.Length;
        webreq.Timeout = 10000;
        Stream stin = webreq.GetRequestStream();
        stin.Write(buffer, 0, buffer.Length);
        stin.Close();
        webres = (HttpWebResponse)webreq.GetResponse();
        if (webres.StatusCode == HttpStatusCode.OK)
        {
           ...
           string status1 = webres.Headers["X-NotificationStatus"];
           string status2 = webres.Headers["X-SubscriptionStatus"];
           ...
        }
        webres.Close();
        sensor.Beep(8000, 500);
      }
     catch (Exception ex) 
     {
        sensor.Beep(500, 4000);
      }
     finally
     {
        if (  webres != null  )
            webres.Dispose();
        if (  webreq != null  )
            webreq.Dispose();
    }           
 }


.Net Micro Framework board
In this project is used the FEZ Ultimate Kit. This kit provides internet connectivity to FEZ Panda II. It also include eblocks for simple plug-and-play capabilities, giving you access to input/output and sensor data.

microframework-fez-pandaII.png

Conclusion
In this way you can connect embedded devices to a windows phone 7; in the videos it was used a Windows Phone 7.1 / Nokia Lumia 800. Instead of a led you can connect some rele'; so you can create a simply domotic control (Windows Phone 7.1 + MicroFramework). Alternatively if you have not logic on the micro framework board; if you just want to control some relays; you can use a dedicated ethernet rele board like this. In this way; the ethernet rele board internally implement a small webserver so you only send the command to set on/off the rele. Follow-Me on facebook.

At this links you can find some articles on DotNetToscana (Italian article):
Polarizzazione di un led (Come connettere un led ad un pin di una scheda .Net Micro Framework)
FEZ Robot Kit (Costruire un robot con motor driver e distance sensor)


http://create.msdn.com
http://www.ghielectronics.com
http://www.tinyclr.com
http://www.torinotechnologiesgroup.it
http://www.dotnettoscana.org
My windows phone marketplace
Linkedin / Stefano Marchisio
Blog


Last edited Jul 31 at 8:21 AM by mastefano64, version 112