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.

No comments:

Post a Comment