asp tutorials, asp.net tutorials, sample code, and Microsoft news from 15Seconds
Data Access  |   Troubleshooting  |   Security  |   Performance  |   ADSI  |   Upload  |   Email  |   Control Building  |   Component Building  |   Forms  |   XML  |   Web Services  |   ASP.NET  |   .NET Features  |   .NET 2.0  |   App Development  |   App Architecture  |   IIS  |   Wireless
 
Pioneering Active Server
 Power Search








Active News
15 Seconds Weekly Newsletter
• Complete Coverage
• Site Updates
• Upcoming Features

More Free Newsletters
Reference
News
Articles
Archive
Writers
Code Samples
Components
Tools
FAQ
Feedback
Books
Links
DL Archives
Community
Messageboard
List Servers
Mailing List
WebHosts
Consultants
Tech Jobs
15 Seconds
Home
Site Map
Press
Legal
Privacy Policy
internet.commerce














internet.com
IT
Developer
Internet News
Small Business
Personal Technology
International

Search internet.com
Advertise
Corporate Info
Newsletters
Tech Jobs
E-mail Offers

HardwareCentral
Compare products, prices, and stores at Hardware Central!

Wireless Home Automation Using .NET and X10 -- Cont'd
By Robert Chartier


  • email this article to a colleague
  • suggest an article

    Section II: Adding Mobility

    Getting the New Solution Ready

    In this section of the article we will start by creating a new ASP.NET mobile Web application. I created mine at the path http://localhost/X10Mobile. Once the solution connects to your local instance of IIS, make sure you add a reference to both libraries from the first section of this article. Both the "Communications.dll" and the "X10Unified.dll" will need to be referenced and both should be found in the bin\Debug folder of the X10Unified Project.

    Next we will want to store the actual port number for the Firecracker device in the Web.Config. This will prevent having to hard code the port, in case we need to change it at a future date. Open up Web.Config and add the following:

    <appSettings>

      <addkey="FirecrackerPort"value="1"/>

    </appSettings>

    This should be added directly under the <configuration> element. Of course make sure the "value" element is set to the actual port the Firecracker device is installed on.

    Designing the Mobile Form

    Next we switch over to the Design time view of our mobile control. We will need to add a few simple controls to our form.

    <body Xmlns:mobile="http://schemas.microsoft.com/Mobile/WebForm">

      <mobile:Form id="MainForm" runat="server" title="X10 Home Automation">

        <mobile:Label id="Label1" runat="server">House Code:</mobile:Label>

        <mobile:SelectionList id="HouseSelectionList" runat="server">

          <Item Value="A" Text="A"></Item>

          <Item Value="B" Text="B"></Item>

          <Item Value="C" Text="C"></Item>

          <Item Value="D" Text="D"></Item>

        </mobile:SelectionList>

        <mobile:Label id="Label3" runat="server">Device:</mobile:Label>

        <mobile:SelectionList id="DeviceSelectionList" runat="server">

          <Item Value="1" Text="1"></Item>

          <Item Value="2" Text="2"></Item>

          <Item Value="3" Text="3"></Item>

          <Item Value="4" Text="4"></Item>

          <Item Value="5" Text="5"></Item>

          <Item Value="6" Text="6"></Item>

          <Item Value="7" Text="7"></Item>

          <Item Value="8" Text="8"></Item>

          <Item Value="9" Text="9"></Item>

          <Item Value="10" Text="10"></Item>

        </mobile:SelectionList>

        <mobile:Label id="Label2" runat="server">Action:</mobile:Label>

        <mobile:SelectionList id="ActionSelectionList" runat="server">

          <Item Value="TurnOn" Text="TurnOn" Selected="True"></Item>

          <Item Value="TurnOff" Text="TurnOff"></Item>

          <Item Value="MakeBrighter" Text="MakeBrighter"></Item>

          <Item Value="MakeDimmer" Text="MakeDimmer"></Item>

        </mobile:SelectionList>

        <mobile:Command id="SendCommand" runat="server">Send Command</mobile:Command>

      </mobile:Form>

    </body>

    Notice that I used SelectionLists for all of the inputs. Since there is a very finite list of actions that the end user can take, this seemed the easiest approach. As an alternative one could argue that it would be better to have the house and device codes as input textboxes. This would allow the user to choose any house and device, not to mention it would shorten the amount of content that would need to be sent to the actual wireless device (something all of us need to think about). On the other hand, a finite list of items may be desirable in some instances. For example if one controls the coffee pot, you probably would not want that accessible via the wireless interface; it may prove hazardous to turn on the coffee pot while away from home.

    You may also want to change the entire form layout to something more logical for you. For example, you have a set of predefined codes mapping to your actual home devices. You could easily have a single selection list (instead of the house and device code lists), that indicates which device you wanted to change, "desk lamp", "front Christmas lights", "front security camera", etc...

    Calling the X10Unified Library

    If you doubleclick on the "SendCommand" button on the form, you are brought to the actual implementation of the button event on the server. In here we will use the following code. Work your way through this quick bit of code and make sure you understand what each piece does.

    privatevoid SendCommand_Click(object sender, System.EventArgs e) {

     

      //lets first get the actual House code, as a char.     

      char houseCode = Convert.ToChar(HouseSelectionList.Selection.Text);

     

      //now lets get the device code, as an int

      int deviceCode = Convert.ToInt32(DeviceSelectionList.Selection.Text);

     

      //now we need to convert the action to the enum

      string action = ActionSelectionList.Selection.Text;

      X10Unified.Senders.Firecracker.Commands cmd = (X10Unified.Senders.Firecracker.Commands)System.Enum.Parse(typeof(X10Unified.Senders.Firecracker.Commands), action);

     

      //lets get the serial port from the app.config

      string configValue = System.Configuration.ConfigurationSettings.AppSettings["FirecrackerPort"];

      int FirecrackerPort=(configValue==null || configValue=="")?1:Convert.ToInt32(configValue);

     

      //get our instance of the firecracker library

      X10Unified.Senders.Firecracker f = X10Unified.Senders.Firecracker.GetInstance(FirecrackerPort);

     

      //send the command

      f.SendCommand(houseCode, deviceCode, cmd);

     

    }

    Finally, we need to load the page and test it. First start with Internet Explorer or whatever browser you normally use. Load up the URL http://localhost/X10Mobile/ and make sure it loads and sends commands to the given house and device. You can also download the Openwave SDK 6.1 and test the page with that, just to get a different view of the page. Lastly, if you have a cell phone or other wireless browser, load the page (using your IP address instead of localhost) and test it out.

    Conclusion

    In this article you have seen how easy it is to automate your home on your PC using .NET and Serial Port IO Communication. Take time to investigate the complete library. I have included everything in this article, as well as a Windows Forms-based application that you can use on the desktop to control your devices. If you are going to take it to the next step and start investigating on how to receive commands through a X10 MR26A device, I have also included a desktop application for controlling such items as Winamp and a Text To Speech RSS reader.

    References

    ASP.NET Mobile Controls: http://www.asp.net/mobile
    Initial build of the C# Library: http://brian.vallelunga.com/code/x10/ X10's Firecracker Product Page: http://www.x10.com/automation/firecracker.htm Serial Communication with VB.NET: http://www.codeworks.it/net/VBNetRs232.htm Singleton Design Pattern: http://www.c-sharpcorner.com/Code/2003/Jan/SingletonPattern.asp MR26a Receiver: http://www.x10.com/products/x10_mr26a.htm

    About the Author

    Robert Chartier has developed IT solutions for more than nine years with a diverse background in both software and hardware development. He is internationally recognized as an innovative thinker and leading IT architect with frequent speaking engagements showcasing his expertise. He's been an integral part of many open forums on cutting-edge technology, including the .NET Framework and Web Services. His current position as vice president of technology for Santra Technology (http://www.santra.com) has allowed him to focus on innovation within the Web Services market space.

    He uses expertise with many Microsoft technologies, including .NET, and a strong background in Oracle, BEA Systems, Inc.'s BEA WebLogic, IBM, Java 2 Platform Enterprise Edition (J2EE), and similar technologies to support his award-winning writing. He frequently publishes to many of the leading developer and industry support Web sites and publications. He has a bachelor's degree in Computer Information Systems.

    Robert Chartier can be reached at rob@santra.com.

    << Section I: Creating the Reuseable X10 Library

    Rate This Article

  • Other Articles
    Apr 13, 2004 - Wireless Home Automation Using .NET and X10
    Learn how to use .NET to communicate with the X10 Firecracker Home Automation System through a PC's serial port. Then build a mobile Web form to access all X10-enabled appliances from a wireless device.
    [Read This Article]  [Top]
    Sep 3, 2003 - Programming for the Palm Part 3 - Creating a Windows Installer
    In the third and final installment of the Programming for the Palm series, Robert Chartier shows how to create a Windows Installer that will install and register the Palm application and Palm conduit on the target machine.
    [Read This Article]  [Top]
    Jul 22, 2003 - Programming for the Palm Part 2 - The Synchronization Process
    In the second part of this three-part series on programming for the Palm, Robert Chartier shows how to work with the Palm synchronization process and how to handle data transferring, importing, and uploading to various destinations using the Palm Conduit Developer Kit and VS .NET.
    [Read This Article]  [Top]
    Jun 24, 2003 - Programming for the Palm Part 1 - Creating the Palm Application
    The first part of this three part series walks through the process of creating a mobile blog application using a BASIC development environment for Palm OS devices called NS Basic. Subsequent articles will focus on synchronizing the data to the desktop using C# and creating an installer.
    [Read This Article]  [Top]
    Apr 22, 2003 - Creating a Mobile Portal
    In the past, developers typically relied on XML and XSLT to create sites that needed to target multiple client platforms. Today, with ASP.NET mobile controls, developers only need to focus on creating one application. In this article, Rob Chartier shows how easy it is to use the ASP.NET mobile controls to create a full-blown wireless portal.
    [Read This Article]  [Top]
    Mar 27, 2001 - Using ASP to Send a Wireless Text Message
    Even though SMS is now in high gear, developers remain slated with restrictive limits to carrier resources. Sending an SMS message via e-mail requires the acceptance of several hidden flaws. Joe Lauer shows how to avoid these complications by sending a wireless text-message through the use of ASP.
    [Read This Article]  [Top]
    Jun 22, 2000 - HDML and ASP Go Hand in Hand
    Learn how to create applications for wireless devices using the Handheld Device Markup Language (HDML) and ASP. Article covers everything from setting the MIME content type for HDML in ASP to passing data between languages to accessing environment variables from ASP.
    [Read This Article]  [Top]
    Mailing List
    Want to receive email when the next article is published? Just Click Here to sign up.

    Support the Active Server Industry



    JupiterOnlineMedia

    internet.comearthweb.comDevx.commediabistro.comGraphics.com

    Search:

    Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

    Jupitermedia Corporate Info


    Legal Notices, Licensing, Reprints, & Permissions, Privacy Policy.

    Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers

    Solutions
    Whitepapers and eBooks
    Microsoft Article: HyperV-The Killer Feature in WinServer ‘08
    Avaya Article: How to Feed Data into the Avaya Event Processor
    Microsoft Article: Install What You Need with Win Server ‘08
    HP eBook: Putting the Green into IT
    Whitepaper: HP Integrated Citrix XenServer for HP ProLiant Servers
    Intel Go Parallel Portal: Interview with C++ Guru Herb Sutter, Part 1
    Intel Go Parallel Portal: Interview with C++ Guru Herb Sutter, Part 2--The Future of Concurrency
    Avaya Article: Setting Up a SIP A/S Development Environment
    IBM Article: How Cool Is Your Data Center?
    Microsoft Article: Managing Virtual Machines with Microsoft System Center
    HP eBook: Storage Networking , Part 1
    Microsoft Article: Solving Data Center Complexity with Microsoft System Center Configuration Manager 2007
    MORE WHITEPAPERS, EBOOKS, AND ARTICLES
    Webcasts
    Intel Video: Are Multi-core Processors Here to Stay?
    On-Demand Webcast: Five Virtualization Trends to Watch
    HP Video: Page Cost Calculator
    Intel Video: APIs for Parallel Programming
    HP Webcast: Storage Is Changing Fast - Be Ready or Be Left Behind
    Microsoft Silverlight Video: Creating Fading Controls with Expression Design and Expression Blend 2
    MORE WEBCASTS, PODCASTS, AND VIDEOS
    Downloads and eKits
    Sun Download: Solaris 8 Migration Assistant
    Sybase Download: SQL Anywhere Developer Edition
    Red Gate Download: SQL Backup Pro and free DBA Best Practices eBook
    Red Gate Download: SQL Compare Pro 6
    Iron Speed Designer Application Generator
    MORE DOWNLOADS, EKITS, AND FREE TRIALS
    Tutorials and Demos
    How-to-Article: Preparing for Hyper-Threading Technology and Dual Core Technology
    eTouch PDF: Conquering the Tyranny of E-Mail and Word Processors
    IBM Article: Collaborating in the High-Performance Workplace
    HP Demo: StorageWorks EVA4400
    Intel Featured Algorhythm: Intel Threading Building Blocks--The Pipeline Class
    Microsoft How-to Article: Get Going with Silverlight and Windows Live
    MORE TUTORIALS, DEMOS AND STEP-BY-STEP GUIDES