Sunday, October 24, 2010

HomeAutomation Client beta is close to release

I have the majority of the Android client app built and functioning within the emulator. There are a few finishing touches needed, but those are just minor details at this point. The initial hard work has been done and the remaining code is tedious but only requires time. At this rate, I am estimating the client's completion by next weekend. There are many more features that I want to add, but I will hold off for now so I can get back to the Arduino side of the development again. I will finally buy the X10 Serial device and make the project begin to function as a whole.

Todays update will include links to the code as well as some screenshots. As I have stated, the code isn't entirely complete, but is close enough. The code is also mostly commented.

Below are some screen shots of the updated UI. This UI is a huge improvement on my previous one where there was only one text field and one button with everything hard coded. This version doesn't have any of the hard coded components of the prototype, but also doesn't have the configuration to assign the settings by the user yet.

 I have linked the java and xml files below to the screen shots they are associated with. Here is the link to my box.net Folder with the whole project including the apk file.

Main Activity(home.xml/JsonParser)


Configuration Menu
UnitConfigurator.java / createunit.xml
Device Configuration Activity

Device Type Selections

Hopefully this week, I will complete the  initial client beta release. Once that is done, I will be back to the Arduino to tie all the pieces together. I am feeling pretty close to having part of my house fully controlled by my phone. I must admit I am excited and will probably  be burning the midnight oil to get it done quicker. To see the Arduino code/project information you can check out my Arduino Blog or the code folder I have on box.net.

Saturday, October 23, 2010

Got It!

I guess I just needed some time away from the code and some different search keywords. I identified the cause this morning, but was suspect of it last night. Since my initial round with Google didn't provide any results that were usable, I was left with two options. First was to just give up, but this is not really my style. The second option, hack and hack until it works was what I went with.


I thought my code was already stripped down to the bare essentials so I just started chopping. There were only a few lines that I knew were 100% required to implement but everything else just got cut. I was stuck with a non-functional app again. I put the few lines back one by one until it worked. As great as it was to get it functioning the way I expected, I still didn't understand what the difference was. 


I went to Google to figure out what the line did that I removed. In the top few results, I found a post with somebody having the exact same problem as well as the explanation of the issue. The basic answer is that the line, myIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK)caused my sub-activity to not really be a sub-activity. So as soon as the new activity was launched, it was becoming it's own application so my main activity would immediately receive the "RESULT_CANCELED" result. 


We have a bit of a busy weekend so I am not sure when I will get back to my Arduino Client, but I am hoping it will be this weekend still. Either way, the kids are getting up. I just wanted to take advantage of this extra morning time before my normal day kicks in.

Thursday, October 21, 2010

Stuck on Sub-Activities

So I have hit a wall that I can't seem to get around. I am launching a sub-activity and attempting to get a result. I have a couple weird things happening, but everything I find online tells me I am doing this correctly.

I even created a simple little test project called SubActivityTest (you can download the zip file with all the source/xml files). It simply launches a sub-activity and waits for the response and writes to a Text View. I have simplified the code to the bare minimum and not only is it NOT working, but it is also returning before the activity even launches.

My code for launching the sub-activity:
Intent myIntent = new Intent(SubActivityTest.this, SubActivity.class);
myIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivityForResult(myIntent, 1);

My Code for setting the result from my sub-activity:
setResult(RESULT_OK);
finish();

My Code for catching the return:
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == 1) {
if (resultCode == RESULT_OK) {
TxtView.setText("OK Pressed");
}
else {
TxtView.setText("resultCode = " + Integer.toString(resultCode));
}
}
}

As I said before, it returns immediately and my text view updates to "resultCode = 0" and then the sub-activity opens. I set the result and finish() from the subactivity and the text view text doesn't change. It remains "resultCode = 0". I guess I am not even sure the routine is running when control returns from the sub-activity. I need this to work and will be scouring the forums to find a fix.

If anybody comes across this and can identify my mistake I would greatly appreciate it.

Tuesday, October 19, 2010

HomeAutomation Client update

I have been working on my client but have not had the time I was hoping to dedicate. Work has been busy and we have been doing extra fall activities as a family since the weather has been so nice.

At this point, I have updated the main activity look/feel. I added Spinners (Combo Box) for selecting "Rooms" and "Units", components for displaying/setting digital and analog settings as well as  a button to send the command. I also created a Room Configuration Activity. The main Activity doesn't recognize the change without restarting the app, but that will hopefully be fixed tonight. See screenshots below for the two Activities. "Rooms"/"Room Code" are synonymous for "House Code" in X10 speak. However Room/House Codes will be selected by User Defined Names for the Room instead of the bland X10 codes of A-P. Unit is modeled directly after the X10 "Unit Code" with the simple twist of a User Defined Name in place of the X10 codes of 1-16. Opening the configuration as well as saving/canceling configuration changes is done through menus(not pictured below).

Mostly this is merely a shell for the minimal functionality. The UI management code has not been started and will probably be saved for last. User error proofing is always a last priority when developing apps for myself.

My Updated UI Activities:
Main Activity
Room Configuration Activity


Monday, October 11, 2010

HomeAutomation Client v0.0.0.1

I have developed my app to the point that satisfies my needs as a proof of concept. Now that I am there, I have started outlining my plans for the 1.0 version. I will have to brush up on some more of my java, but it will be good information anyways.

I have to re-learn my options for collections of objects. In Delphi, I would use a TObjectList, TStringList or a child class that inherits from TObjectClass. However, for java, it has been long enough that I don't remember the built in constructs that are at my disposal. I could attempt to write my own version of the TObjectList class, and will if there are no other options, but have to believe I can find something first. At least, I will start with Google and go from there.

Once I am done investigating collections and a couple other minor questions, I will be flushing out my next generation of a UI. It will be an actual UI that somebody might use. Currently, the app I have linked to here is only an EditText, TextView and a button. The app simply sends an HTTP Request with the exact text in the EditText and displays the result in the TextView. This happens when the application loads as well as when the button is clicked. The server is an Arduino Micro controller on my home LAN. I currently have my router set up to forward port 80 to Arduino so I can also access it over my 3G. I have posted about it here on my blog. I also have the code for my version of the Webduino server on box.net. Any web server capable of receiving/responding to this app's requests would also work.

Sunday, October 3, 2010

A New Project (My Home Automation Client)

I have begun a new project for my Android phone. I have gotten far enough with my Arduino webserver development to need a client. I am mostly using my desktop web browser for testing/debugging, but at my last minor milestone, I needed a client to verify I could read data, from the Arduino, over my home wifi. I have taken it a step further, enabled port-forwarding on my router and now have access to my Arduino's webserver over the WAN.

The arduino ins't connected to anything yet (well anymore), it is only really echos some minor information back. It was at one point, but my learning-to-solder ruined that quickly. I fried the microchip I connected the Arduino to and that was the end of my physical X10 control. It is back to outputting text to confirm. Initially, before I had both the Arduino and Android projects to their respective milestones, I did have it controlling a circuit within my home. I used X10 sockets so I didn't have to do anything more than replace sockets. That ended when I fried the chip. The actual milestone was capable of sending the status/values of the digital and analog pins on the Arduino. I created my Android client to make a basic HTTP request, parse the results and display them as I desired within the user controls on the Activity.

The Activity was an extremely simple file. It consisted of two controls. The first was a TextView and the second was a button. The button initiated the HTTP Request and the TextView was used to display the parsed data. I used this application to test a couple techniques. Initially, I needed to confirm I could send/receive the HTTP request. This turned out to be much simpler than I expected. I found an example online quickly, tried the code, modified it to fit my needs and was done. The other technique was JSON parsing. I stumbled onto json through the Webduino demo sketch. I found it was essentially just an alternative to XML. It appears to be a lighter alternative in terms of necessary bandwidth and program memory. Fortunately, java already had a parser so I didn't have to write it myself. This also turned out to be relatively simple. I, again, found some code online, modified it to fit my needs and was done. I parsed the result of the HTTP response and selected the Analog values for display in the TextView.

I am still working on the Arduino infrastructure. I need to finish the command processor. My next milestone at the very least is to implement all the command processing options. It will still most likely echo back the request, but having each option stubbed out will be nice. It will also make it easy to go back and finish one piece at a time.

My next Android step though is to make a more functional and feature-rich client. I want to make some more settings user-definable. I also want to provide a better UI to issue some-what custom requests and display the response's results.

Hopefully the next post will be sooner rather than later. I have been busy with life in general, and it has been hard enough getting to the point I have. However, I keep pushing and will update again.