7.7 Testing Out the Android Client

Time to test out the application on a real X10 light switch. Assuming the Rails-based X10 web application is working as expected, start up your Rails development server on the same network/subnet as the emulator in Figure 28, Running the Light Switch application.

/epubstore/R/M-Riley/Programming-your-home//images/x10androidscreen.png

Figure 28. Running the Light Switch application

Use the same port number as the one we assigned in the my_server_ip_address_and_port_number string from our Android application. For example, in the case of 192.168.1.100:3344, the IP address is 192.168.1.100 and the port number is 3344. Pass this as a command-line parameter when launching the Rails server instance, like this:

  ​> rails s -p3344​

With the rails development server now running on port 3344 and waiting for inbound requests on the same local area network as your Android emulator or device, click the On/Off toggle button.

Um, nothing happened. Why?

There is one more important setting we have to make in the Light Switch application configuration. We have to respect the Android application security model and tell the Android OS that we want to allow our application to Use the Internet so that we can have our outbound HTTP requests reach the outside world. To do so, double-click the AndroidManifest.xml file and add the following line just above the closing manifest tag, like this:

  <uses-permission android:name="android.permission.INTERNET" >
  </uses-permission>

The entire AndroidManifest.xml file should now look like this:

  ​<?xml version="1.0" encoding="utf-8"?>​
  <manifest xmlns:android="http://schemas.android.com/apk/res/android"
  ​ package="com.mysampleapp.lightswitch"
  ​ android:versionCode="1"
  ​ android:versionName="1.0" >
  <application android:icon="@drawable/icon"
  ​ android:label="@string/app_name" >
  <activity android:name=".LightSwitch"
  ​ android:label="@string/app_name" >
  <intent-filter>
  <action android:name="android.intent.action.MAIN" />
  <category android:name="android.intent.category.LAUNCHER" />
  </intent-filter>
  </activity>
  </application>
  <uses-permission android:name="android.permission.INTERNET" >
  </uses-permission>
  </manifest>

Recompile and run the Light Switch application with the new permission setting and click the toggle button. If everything worked as planned, you should see the Rails server report something similar to the following successfully received request:

  ​Started GET "/command/on" for 192.168.1.101 at Sat Mar 21 19:48:10 -0500 2011​
  ​ Processing by CommandController#cmd as HTML​
  ​ Parameters: {"cmd"=>"on"}​
  ​Rendered command/cmd.html.erb within layouts/application (11.7ms)​
  ​Completed 200 OK in 53ms (Views: 34.7ms | ActiveRecord: 0.0ms)​

You should also see the light turn on! Click the toggle button again. It should generate a similar report for the off command:

  ​Started GET "/command/off" for 192.168.1.101 at Sat Mar 26 19:52:30 -0500 2011​
  ​ Processing by CommandController#cmd as HTML​
  ​ Parameters: {"cmd"=>"off"}​
  ​Rendered command/cmd.html.erb within layouts/application (13.2ms)​
  ​Completed 200 OK in 1623ms (Views: 40.0ms | ActiveRecord: 0.0ms)​

Consequently, the light should now switch off.

On rare occasions, one other issue you may encounter when you attempt to install the Light Switch application on your Android phone is an expired debug key. Android’s security model requires a signed key to execute code on an Android device. The signed key should have been automatically generated and configured when you installed the Android SDK, but in the event that an expiration message occurs, follow the signing procedure in the Android SDK documentation to generate a new key.[75]

For more details on installing Android programs onto an Android device from the Eclipse environment, review the Android SDK documentation on running Android applications on an emulator and on a device.[76]

Programming Your Home
cover.xhtml
f_0000.html
f_0001.html
f_0002.html
f_0003.html
f_0004.html
f_0005.html
f_0006.html
f_0007.html
f_0008.html
f_0009.html
f_0010.html
f_0011.html
f_0012.html
f_0013.html
f_0014.html
f_0015.html
f_0016.html
f_0017.html
f_0018.html
f_0019.html
f_0020.html
f_0021.html
f_0022.html
f_0023.html
f_0024.html
f_0025.html
f_0026.html
f_0027.html
f_0028.html
f_0029.html
f_0030.html
f_0031.html
f_0032.html
f_0033.html
f_0034.html
f_0035.html
f_0036.html
f_0037.html
f_0038.html
f_0039.html
f_0040.html
f_0041.html
f_0042.html
f_0043.html
f_0044.html
f_0045.html
f_0046.html
f_0047.html
f_0048.html
f_0049.html
f_0050.html
f_0051.html
f_0052.html
f_0053.html
f_0054.html
f_0055.html
f_0056.html
f_0057.html
f_0058.html
f_0059.html
f_0060.html
f_0061.html
f_0062.html
f_0063.html
f_0064.html
f_0065.html
f_0066.html
f_0067.html
f_0068.html
f_0069.html
f_0070.html
f_0071.html
f_0072.html
f_0073.html
f_0074.html
f_0075.html
f_0076.html
f_0077.html
f_0078.html
f_0079.html
f_0080.html
f_0081.html
f_0082.html
f_0083.html
f_0084.html
f_0085.html
f_0086.html
f_0087.html
f_0088.html
f_0089.html
f_0090.html
f_0091.html
f_0092.html
f_0093.html
f_0094.html
f_0095.html
f_0096.html
f_0097.html
f_0098.html
f_0099.html
f_0100.html
f_0101.html
f_0102.html
f_0103.html
f_0104.html
f_0105.html
f_0106.html
f_0107.html
f_0108.html
f_0109.html
f_0110.html
f_0111.html
f_0112.html
f_0113.html
f_0114.html
f_0115.html
f_0116.html
f_0117.html
f_0118.html
f_0119.html
f_0120.html
f_0121.html
f_0122.html
f_0123.html
f_0124.html
f_0125.html