Developing apps for Android OS: Develop an app for interfacing Arduino with Android OS for home automation



Similar documents
Tutorial #1. Android Application Development Advanced Hello World App

How to build your first Android Application in Windows

Android Environment SDK

Mobile Application Development

Android Environment SDK

directory to "d:\myproject\android". Hereafter, I shall denote the android installed directory as

Android Development. 吳 俊 興 國 立 高 雄 大 學 資 訊 工 程 學 系

Hello World. by Elliot Khazon

Arduino & Android. A How to on interfacing these two devices. Bryant Tram

Developing Android Apps: Part 1

Getting Started: Creating a Simple App

Advantages. manage port forwarding, set breakpoints, and view thread and process information directly

MMI 2: Mobile Human- Computer Interaction Android

IOIO for Android Beginners Guide Introduction

Android Introduction. Hello Mihail L. Sichitiu 1

How to develop your own app

ECWM511 MOBILE APPLICATION DEVELOPMENT Lecture 1: Introduction to Android

Introduction to Android SDK Jordi Linares

Android Application Development: Hands- On. Dr. Jogesh K. Muppala

Now that we have the Android SDK, Eclipse and Phones all ready to go we can jump into actual Android development.

Android Java Live and In Action

Getting Started With Android

Android Development Tutorial. Nikhil Yadav CSE40816/ Pervasive Health Fall 2011

Yun Shield Quick Start Guide VERSION: 1.0 Version Description Date 1.0 Release 2014-Jul-08 Yun Shield Quick Start Guide 1 / 14

Android Development. Marc Mc Loughlin

Chapter 2 Getting Started

Tutorial: Android Object API Application Development. SAP Mobile Platform 2.3

Developing NFC Applications on the Android Platform. The Definitive Resource

Android For Java Developers. Marko Gargenta Marakana

Getting Started with Android Development

Android Basics. Xin Yang

4. The Android System

Basics. Bruce Crawford Global Solutions Manager

Board also Supports MicroBridge

Installing the Android SDK

ANDROID BASED FARM AUTOMATION USING GR-SAKURA

OpenCV on Android Platforms

Advertiser Campaign SDK Your How-to Guide

Presenting Android Development in the CS Curriculum

Login with Amazon Getting Started Guide for Android. Version 2.0

2. Click the download button for your operating system (Windows, Mac, or Linux).

Tutorial: Android Object API Application Development. Sybase Unwired Platform 2.2 SP02

SDK Quick Start Guide

Android 多 核 心 嵌 入 式 多 媒 體 系 統 設 計 與 實 作

How To Develop An Android App On An Android Device

ID TECH UniMag Android SDK User Manual

Fahim Uddin 1. Java SDK

Lab 0 (Setting up your Development Environment) Week 1

ANDROID APPS DEVELOPMENT FOR MOBILE AND TABLET DEVICE (LEVEL I)

How to Create an Android Application using Eclipse on Windows 7

App Development for Smart Devices. Lec #2: Android Tools, Building Applications, and Activities

Hacking your Droid ADITYA GUPTA

Example Connection between USB Host and Android

The "Eclipse Classic" version is recommended. Otherwise, a Java or RCP version of Eclipse is recommended.

Tutorial on Basic Android Setup

Android Programming. Android App. Høgskolen i Telemark Telemark University College. Cuong Nguyen,

How To Run A Hello World On Android (Jdk) On A Microsoft Ds.Io (Windows) Or Android Or Android On A Pc Or Android 4 (

Android Programming. Høgskolen i Telemark Telemark University College. Cuong Nguyen,

Getting Started with Android

ADT Plugin for Eclipse

Oracle FLEXCUBE Direct Banking Android Tab Client Installation Guide Release

Admin. Mobile Software Development Framework: Android Activity, View/ViewGroup, External Resources. Recap: TinyOS. Recap: J2ME Framework

Developing In Eclipse, with ADT

Developing Android Applications Introduction to Software Engineering Fall Updated 7 October 2015

CSE476 Mobile Application Development. Yard. Doç. Dr. Tacha Serif Department of Computer Engineering Yeditepe University

Programming with Android: SDK install and initial setup. Dipartimento di Informatica: Scienza e Ingegneria Università di Bologna

Building Your First App

Basic Android Setup Windows Version

Android, Bluetooth and MIAC

Jordan Jozwiak November 13, 2011

Download and Installation Instructions. Android SDK and Android Development Tools (ADT)

Download and Installation Instructions. Android SDK and Android Development Tools (ADT) Microsoft Windows

Android Tutorial. Larry Walters OOSE Fall 2011

Programming with Android: SDK install and initial setup. Dipartimento di Informatica: Scienza e Ingegneria Università di Bologna

TUTORIAL 3 :: ETHERNET SHIELD AND TWITTER.COM

Running a Program on an AVD

Developing an Android App. CSC207 Fall 2014

Mocean Android SDK Developer Guide

Università Degli Studi di Parma. Distributed Systems Group. Android Development. Lecture 2 Android Platform. Marco Picone

SIM900 Eclipse environment install Application Note_V1.00

Lecture 1 Introduction to Android

TUTORIALS AND QUIZ ANDROID APPLICATION SANDEEP REDDY PAKKER. B. Tech in Aurora's Engineering College, 2013 A REPORT

Android ( ) Frank Ducrest

Android Setup Phase 2

Android Services. Services

Arduino Internet Connectivity: Maintenance Manual Julian Ryan Draft No. 7 April 24, 2015

J A D E T U TO R I A L

Android: How To. Thanks. Aman Nijhawan

IRF2000 IWL3000 SRC1000 Application Note - Develop your own Apps with OSGi - getting started

Introduction to Android Programming (CS5248 Fall 2015)

Islamic University of Gaza. Faculty of Engineering. Computer Engineering Department. Mobile Computing ECOM Eng. Wafaa Audah.

Android Programming Basics

How To Write A File Station In Android.Com (For Free) On A Microsoft Macbook Or Ipad (For A Limited Time) On An Ubuntu 8.1 (For Ubuntu) On Your Computer Or Ipa (For

Transcription:

Developing apps for Android OS: Develop an app for interfacing Arduino with Android OS for home automation Author: Aron NEAGU Professor: Martin TIMMERMAN

Table of contents 1. Introduction.2 2. Android project file structure 2 3. Android development environment.2 4. Cosm (Pachube).8 5. Arduino.9 6. Software 10 7. Conclusions.19 7. References..19 8. Appendix 19

1. Introduction The purpose of this document is to present briefly the structure of the Android OS, how to set up the IDE for developing apps, and develop a small application for that runs on an Android capable device. The application is a proof of concept how Android and Arduino can be interfaced together to monitor a wireless sensor network inside a house. The Arduino board acts as a node where multiple sensors can be connected to it, and its role is to send these measurements to an online platform for monitoring sensors, called Pachube. The app on the Android connects to Pachube, and through its API connects to the corresponding data stream to get the sensor readings. Android project file structure An Android project contains multiple files, much more than in the case of a simple Java project. Although Android apps are developed in Java, the interface of an app is created using a set of elements which are defined in XML files. The structure of an Android project is the following: /src all the source files go here /bin output directory of the build. This is where the final *.apk file will reside /gen contains the Java files generated by the ADT, such as the R.java /res contains application resources, such as draw able files, layout files and string values /libs contains private libraries AndroidManifest.xml this control file describes the nature of the application and each of its components. For instance, it can describe: certain qualities about the activities, services, intent receivers and content providers; what permissions are requested, what external libraries are needed; what device features are required; what API levels are supported of requested. Android development environment To start programming and developing applications for the Android OS, one must set up the IDE. In our case, the development environment is Eclipse which runs a plugin for Android called ADT, or Android Development Tools. Also, the Android SDK must be installed. The correct steps are the following: Download and install the Android SDK Download and install the latest SDK tools and platforms using the SDK Manager Download and install the ADT plugin for Eclipse After the IDE is set-up and the app was developed, it needs to be downloaded to a phone. This is done in the following steps:

Download and install HTC Sync Connect the Android phone through USB to the PC Download and install the Android SDK 1. Go to http://developer.android.com/sdk/index.html and click on the Download the SDK for Windows 2. Run the executable which starts the installer. The installer checks your machine for required tools, such as the proper Java SE Development Kit (JDK) and install if necessary. The installer then saves the Android SDK Tools into a default location. 3. Select Start SDK Manager, and click Finish Download and install the latest SDK tools 1. After the Android SDK is installed the SDK Manager is started 2. The SDK Tools were previously installed, but to develop Android apps, you must install also the SDK Platform Tools, and at least one Android platform 3. After you have selected the Platform Tools and one Android platform, click Install

Figure x: The SDK Manager Download and install the ADT plugin 1. Start Eclipse, then select Help -> Install New Software 2. Click Add, in the top right corner 3. In the Add Repository dialog that appear, enter ADT Plugin for the Name and the URL https://dl-ssl.google.com/android/eclipse for the Location 4. Click OK 5. In the available Software dialog, select the checkbox next to Developer Tools and click Next 6. In the next window, you ll see a list of the tools to be downloaded. Click Next 7. Read and accept the license agreements, then click Finish 8. When the installation completes, restart Eclipse

Figure x: The Install New Software screen for downloading the ADT plugin Configure the ADT plugin: 1. Select Windows -> Preferences to open the Preferences panel 2. Select Android from the left panel 3. For the SDK Location in the main panel, click Browse and locate your downloaded Android SDK directory (such as android-sdk-windows) 4. Click Apply, then OK

Figure x: The preferences dialog for configuring the ADT plugin Download and install HTC Sync 1. Go to http://www.htc.com/www/software/htc-sync/ and press Download 2. Run the executable, which is an installer. Choose the Language and press OK. 3. It might need to install additional software, like MSXML, Adobe AIR and HTC Driver. Press Install 4. Accept the license agreement and press Next 5. For simplicity, choose Complete Setup and press Next, and then Install Connect the Android phone to the PC 1. Using an USB cable connect the phone to the PC

2. When the phone prompts you to choose a type of USB connection, tap HTC Sync, and then tap Done 3. Wait for the HTC Sync to recognize your phone. On the Device Setup screen, enter a name for your phone 4. In HTC Sync, click Application Installer 5. Browse for the *.apk file and click OK. Now the app will be copied to the phone Figure x: HTC Sync Cosm Coms, which was formerly known as Pachube, is an online database service allowing developers to connect sensor derived data to the web and build their own applications based on that data. Cosm has become, from its launch in 2008 as Pachube, the main platform for the Internet of Things, and it provides most of its functionality via its Application Programming Interface (API). The API makes it quick and easy to create devices which connect to the Internet of Things. The API defines a couple of concepts:

Feed: represents a group of data streams Data stream: represents an individual sensor/device stream within an environment Data point: represents the value at a point in time of a data stream and is simply a key value pair of the timestamp and the value at that time API key: are keys defined for each individual user and allows that user to send feeds to cosm.com site. Arduino The hardware platform that acts as the main node to which all of the sensors connect is an Arduino platform. The advantage of Arduino over other boards is the simplicity of the syntax of the programming language, which is a combination of Wire and Processing. Moreover, the Arduino is open-source and its community is highly active which ensures an ongoing development. Figure x shows the Processing-based development environment (IDE) of Arduino. Figure x: Arduino development environment The Arduino, as stated before, is only a platform that comes in many shapes and size and from different manufacturers. I have used the iboard, an Arduino board from ITeadStudio. The iboard contains an Atmel ATMEGA328P microcontroller, has a slot for SD card storage, an Ethernet port, a socket for XBee

module which can optionally add wireless functionality to the board. The iboard also has 8 ports for connecting electronic bricks, like sensors or actuators. Figure x shows the iboard. Figure x: The iboard For the sensor, we used the DHT11 Temperature and Humidity sensor. This sensor features a calibrated digital signal output with the temperature and humidity sensor complex. Humidity calibration coefficients are stored in the devices OTP memory. The sensor s fast response time, use of one wire interface, digital signal output, small size and low power, make this sensor perfect for our implementation. Figure x: DHT11 Temperature and Humidity sensor Software The software that runs on the iboard has the following structure: it reads the data from the sensor, creates a String with these values, connects to Pachube and sends the readings.

The first step is to read the sensor and put the values in a String called datastring: // read the sensor temperature: int chk = DHT11.read(DHT11PIN); int sensorreading=dht11.temperature; // convert the data to a String to send it: String datastring = String(sensorReading); // we can append multiple readings to this String if the // pachube feed is set up to handle multiple values: int othersensorreading = DHT11.humidity; datastring += ","; datastring += String(otherSensorReading); The next step is to connect to Pachube and send the data. This is done in the senddata() method. It connects to pchube.com on port 80, with the command client.connect("www.pachube.com", 80). Then the number of the feed, as well as the API key is sent to Pachube. In the end the datastring is sent to Pachube.com. // this method makes a HTTP connection to the server: void senddata(string thisdata) { // if there's a successful connection: if (client.connect("www.pachube.com", 80)) { Serial.println("connecting..."); // send the HTTP PUT request. // fill in your feed address here: client.print("put /api/44662.csv HTTP/1.1\n"); //44662 is the ID of the pachube feed which can be visualised online client.print("host: www.pachube.com\n"); // fill in your Pachube API key here: client.print("x-pachubeapikey: nb7598ndoqwhw72mhtlkaql05ur6_svrkznicv7ccxm\n");//api key is the special key, unique to every user client.print("content-length: "); client.println(thisdata.length(), DEC); // last pieces of the HTTP PUT request: client.print("content-type: text/csv\n"); client.println("connection: close\n"); // here's the actual content of the PUT request: client.println(thisdata); // note the time that the connection was made: lastconnectiontime = millis(); else { // if you couldn't make a connection:

Serial.println("connection failed"); The code for the Android OS is composed of several activities, or screens. Figure x: The architecture of the software

Figure x: The Startup Activity public class StartupActivity extends Activity { /** Called when the activity is first created. */ @Override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.startup); public void callmainactivity(view view){ startactivity(new Intent(this, MainActivity.class)); finish();

Figure x: The Main Activity public class MainActivity extends ListActivity { public void oncreate(bundle savedinstances){ super.oncreate(savedinstances); setcontentview(r.layout.main); @Override protected void onlistitemclick(listview l, View v, int position, long id){ super.onlistitemclick(l, v, position, id); switch(position){ case 0: startactivity(new Intent(this, LightsActivity.class)); break; case 1: startactivity(new Intent(this, TemperatureActivity.class)); break; case 2: startactivity(new Intent(this, HumidityActivity.class)); break; case 3: startactivity(new Intent(this, AdvancedActivity.class)); break; case 4: startactivity(new Intent(this, HelpActivity.class)); break;

Figure x: The Lights Activity public class LightsActivity extends Activity{ public void oncreate(bundle savedinstances){ super.oncreate(savedinstances); setcontentview(r.layout.lights); ToggleButton toggle_setalllights=new ToggleButton(this); ToggleButton toggle_livingroom=new ToggleButton(this); ToggleButton toggle_bedroom=new ToggleButton(this); ToggleButton toggle_kitchen=new ToggleButton(this); ToggleButton toggle_bathroom=new ToggleButton(this); toggle_livingroom=(togglebutton)findviewbyid(r.id.toggle_livingroom); toggle_bedroom=(togglebutton)findviewbyid(r.id.toggle_bedroom); toggle_kitchen=(togglebutton)findviewbyid(r.id.toggle_kitchen); toggle_bathroom=(togglebutton)findviewbyid(r.id.toggle_bathroom); toggle_setalllights=(togglebutton)findviewbyid(r.id.toggle_setalllights);

Figure x: The Temperature Activity public class TemperatureActivity extends Activity{ public void oncreate(bundle savedinstances){ super.oncreate(savedinstances); setcontentview(r.layout.temperature); TextView temp_name=new TextView(this); TextView temp_value=new TextView(this); temp_name=(textview)findviewbyid(r.id.textview_temperature1_name); temp_value=(textview)findviewbyid(r.id.textview_temperature1_value); try{ Pachube pachube=new Pachube("xfxR_Mu4Npk79Vj0NRv2HwIknt0yJhDb5ausJECZkGY"); Feed feed=new Feed(pachube); feed=pachube.getfeed(44642); ArrayList<Data> array=feed.getdata(); temp_name.settext(array.get(0).gettag()); temp_value.settext(double.tostring(array.get(0).getvalue())); catch(pachubeexception e){system.out.println(e.errormessage);

Figure x: The Humidity Activity public class HumidityActivity extends Activity{ public void oncreate(bundle savedinstances){ super.oncreate(savedinstances); setcontentview(r.layout.humidity); TextView hum_name=new TextView(this); TextView hum_value=new TextView(this); hum_name=(textview)findviewbyid(r.id.textview_humidity1_name); hum_value=(textview)findviewbyid(r.id.textview_humidity1_value); try{ Pachube pachube=new Pachube("xfxR_Mu4Npk79Vj0NRv2HwIknt0yJhDb5ausJECZkGY"); Feed feed=new Feed(pachube); feed=pachube.getfeed(44642); ArrayList<Data> array=feed.getdata(); hum_name.settext(array.get(0).gettag()); hum_value.settext(double.tostring(array.get(1).getvalue())); catch(pachubeexception e){system.out.println(e.errormessage);

Figure x: The Advanced Activity public class AdvancedActivity extends Activity{ public void oncreate(bundle savedinstances){ super.oncreate(savedinstances); setcontentview(r.layout.advanced); SharedPreferences settings=getsharedpreferences("settings",0); SharedPreferences.Editor prefeditor=settings.edit(); //*************** EditText APIkey=new EditText(this); EditText feed=new EditText(this); APIkey=(EditText)findViewById(R.id.edittext_APIkey); feed=(edittext)findviewbyid(r.id.edittext_feed); prefeditor.putstring("apikey_pref", APIkey.getText().toString()); prefeditor.putstring("feed_pref", feed.gettext().tostring()); prefeditor.commit(); public void callsettriggersactivity(view view){ startactivity(new Intent(this, SetTriggersActivity.class));

Conclusions Developing for Android has several downsides. First of all, the lack of a dedicated IDE and thus the requirement to develop in Eclipse means two things: developers who are familiar with Eclipse will have no problem transitioning to developing for Android; on the other hand Eclipse requires some (extensive) configuration so one can develop for Android. This implies not just installing the plugin, but also the Android SDK and platform tools. I have found that setting up was not that straightforward as it seems. Another issue is that Android is a combination of Java development and XML files. The tree structure of an Android project can be overwhelming for a beginner. The XML files contain static elements, like strings, images, animations, so it can be quite hard to figure out what resource goes where. On the other hand, downloading the app to the phone is very easy. The HTC has an app for Windows, called HTC Sync that allows for syncing data between the phone and the PC. The process is as easy as specifying the executable code and click on the Upload button. Pachube had a Java library which supported their platform. However, after being bought by Cosm, they changed the API and the old Java library is unsupported. Now it is impossible to use the current API to communicate from an Android phone with the Cosm platform. References Installing the Eclipse ADT plugin: http://developer.android.com/sdk/installing/installing-adt.html Installing apps to an Android device: http://www.htc.com/help/www/howto_iframe.aspx?id=192&type=1&p_id=313 Appendix A Code for Arduino /* This sketch connects a temperature/humidity sensor to Pin A2 on the Iboard 1.0. The board is connected to the internet through the Ethernet port. Equivalent with pin 16 on the datasheet */ #include <dht11.h> //use the special library which comes with the temperature/humidity sensor #include <SPI.h> #include <Ethernet.h> // assign a MAC address for the ethernet controller.

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED; #define DHT11PIN 16 //pin on which the sensor is connected dht11 DHT11; // available IP address on the network // for manual configuration: IPAddress ip(192, 168, 1, 144); // initialize the library instance: EthernetClient client; long lastconnectiontime = 0; // last time you connected to the server, in milliseconds boolean lastconnected = false; // state of the connection last time through the main loop const int postinginterval = 10000; //delay between updates to Pachube.com void setup() { // start serial port: Serial.begin(9600); // give the ethernet module time to boot up: delay(1000); // start the Ethernet connection: if (Ethernet.begin(mac) == 0) { Serial.println("Failed to configure Ethernet using DHCP"); // Configure manually: Ethernet.begin(mac, ip); void loop() { // read the sensor temperature: int chk = DHT11.read(DHT11PIN); int sensorreading=dht11.temperature; // convert the data to a String to send it: String datastring = String(sensorReading); // we can append multiple readings to this String if the // pachube feed is set up to handle multiple values: int othersensorreading = DHT11.humidity; datastring += ","; datastring += String(otherSensorReading); // if there's incoming data from the net connection.

// send it out the serial port. This is for debugging // purposes only: if (client.available()) { char c = client.read(); Serial.print(c); // if there's no net connection, but there was one last time // through the loop, then stop the client: if (!client.connected() && lastconnected) { Serial.println(); Serial.println("disconnecting."); client.stop(); // if you're not connected, and ten seconds have passed since // your last connection, then connect again and send data: if(!client.connected() && (millis() - lastconnectiontime > postinginterval)) { senddata(datastring); // store the state of the connection for next time through // the loop: lastconnected = client.connected(); // this method makes a HTTP connection to the server: void senddata(string thisdata) { // if there's a successful connection: if (client.connect("www.pachube.com", 80)) { Serial.println("connecting..."); // send the HTTP PUT request. // fill in your feed address here: client.print("put /api/44662.csv HTTP/1.1\n"); //44662 is the ID of the pachube feed which can be visualised online client.print("host: www.pachube.com\n"); // fill in your Pachube API key here: client.print("x-pachubeapikey: nb7598ndoqwhw72mhtlkaql05ur6_svrkznicv7ccxm\n");//api key is the special key, unique to every user client.print("content-length: "); client.println(thisdata.length(), DEC); // last pieces of the HTTP PUT request: client.print("content-type: text/csv\n"); client.println("connection: close\n"); // here's the actual content of the PUT request: client.println(thisdata);

// note the time that the connection was made: lastconnectiontime = millis(); else { // if you couldn't make a connection: Serial.println("connection failed"); Appendix B Code for Android StartupActivity.java package com.domotics; import android.app.activity; import android.content.intent; import android.os.bundle; import android.view.view; public class StartupActivity extends Activity { /** Called when the activity is first created. */ @Override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.startup); public void callmainactivity(view view){ startactivity(new Intent(this, MainActivity.class)); finish(); MainActivity.java package com.domotics; /*import java.io.ioexception; import java.net.malformedurlexception; import java.net.url; import org.xmlpull.v1.xmlpullparser; import org.xmlpull.v1.xmlpullparserexception;

import org.xmlpull.v1.xmlpullparserfactory;*/ import android.app.listactivity; import android.content.intent; import android.os.bundle; import android.view.view; import android.widget.listview; public class MainActivity extends ListActivity { public void oncreate(bundle savedinstances){ super.oncreate(savedinstances); setcontentview(r.layout.main); @Override protected void onlistitemclick(listview l, View v, int position, long id){ super.onlistitemclick(l, v, position, id); switch(position){ case 0: startactivity(new Intent(this, LightsActivity.class)); break; case 1: startactivity(new Intent(this, TemperatureActivity.class)); break; case 2: startactivity(new Intent(this, HumidityActivity.class)); break; case 3: startactivity(new Intent(this, AdvancedActivity.class)); break; case 4: startactivity(new Intent(this, HelpActivity.class)); break; Temperature.java package com.domotics; import java.util.arraylist; import Pachube.Data; import Pachube.Feed; import Pachube.Pachube; import Pachube.PachubeException; import android.app.activity; import android.os.bundle; import android.widget.textview; public class TemperatureActivity extends Activity{

public void oncreate(bundle savedinstances){ super.oncreate(savedinstances); setcontentview(r.layout.temperature); TextView temp_name=new TextView(this); TextView temp_value=new TextView(this); temp_name=(textview)findviewbyid(r.id.textview_temperature1_name); temp_value=(textview)findviewbyid(r.id.textview_temperature1_value); try{ Pachube pachube=new Pachube("xfxR_Mu4Npk79Vj0NRv2HwIknt0yJhDb5ausJECZkGY"); Feed feed=new Feed(pachube); feed=pachube.getfeed(44642); ArrayList<Data> array=feed.getdata(); temp_name.settext(array.get(0).gettag()); temp_value.settext(double.tostring(array.get(0).getvalue())); catch(pachubeexception e){system.out.println(e.errormessage); LightsActivity.java package com.domotics; import android.app.activity; import android.os.bundle; import android.view.view; import android.view.view.onclicklistener; import android.widget.togglebutton; public class LightsActivity extends Activity{ public void oncreate(bundle savedinstances){ super.oncreate(savedinstances); setcontentview(r.layout.lights); ToggleButton toggle_setalllights=new ToggleButton(this); ToggleButton toggle_livingroom=new ToggleButton(this); ToggleButton toggle_bedroom=new ToggleButton(this); ToggleButton toggle_kitchen=new ToggleButton(this); ToggleButton toggle_bathroom=new ToggleButton(this); toggle_livingroom=(togglebutton)findviewbyid(r.id.toggle_livingroom); toggle_bedroom=(togglebutton)findviewbyid(r.id.toggle_bedroom); toggle_kitchen=(togglebutton)findviewbyid(r.id.toggle_kitchen); toggle_bathroom=(togglebutton)findviewbyid(r.id.toggle_bathroom); toggle_setalllights=(togglebutton)findviewbyid(r.id.toggle_setalllights); //toggle_setalllights.setonclicklistener(togglelistener); /*private OnClickListener togglelistener=new OnClickListener(){

public void onclick(view v){ if(toggle_setalllights.ischecked()){ toggle_livingroom.setchecked(true); toggle_bedroom.setchecked(true); toggle_kitchen.setchecked(true); toggle_bathroom.setchecked(true); ; ; */ HumidityActivity.java package com.domotics; import java.util.arraylist; import Pachube.Data; import Pachube.Feed; import Pachube.Pachube; import Pachube.PachubeException; import android.app.activity; import android.os.bundle; import android.widget.textview; public class HumidityActivity extends Activity{ public void oncreate(bundle savedinstances){ super.oncreate(savedinstances); setcontentview(r.layout.humidity); TextView hum_name=new TextView(this); TextView hum_value=new TextView(this); hum_name=(textview)findviewbyid(r.id.textview_humidity1_name); hum_value=(textview)findviewbyid(r.id.textview_humidity1_value); try{ Pachube pachube=new Pachube("xfxR_Mu4Npk79Vj0NRv2HwIknt0yJhDb5ausJECZkGY"); Feed feed=new Feed(pachube); feed=pachube.getfeed(44642); ArrayList<Data> array=feed.getdata(); hum_name.settext(array.get(0).gettag()); hum_value.settext(double.tostring(array.get(1).getvalue())); catch(pachubeexception e){system.out.println(e.errormessage); AdvancedActivity.java

package com.domotics; import android.app.activity; import android.content.intent; import android.content.sharedpreferences; import android.os.bundle; import android.view.view; import android.widget.edittext; import android.widget.textview; public class AdvancedActivity extends Activity{ public void oncreate(bundle savedinstances){ super.oncreate(savedinstances); setcontentview(r.layout.advanced); SharedPreferences settings=getsharedpreferences("settings",0); SharedPreferences.Editor prefeditor=settings.edit(); //*************** EditText APIkey=new EditText(this); EditText feed=new EditText(this); APIkey=(EditText)findViewById(R.id.edittext_APIkey); feed=(edittext)findviewbyid(r.id.edittext_feed); prefeditor.putstring("apikey_pref", APIkey.getText().toString()); prefeditor.putstring("feed_pref", feed.gettext().tostring()); prefeditor.commit(); public void callsettriggersactivity(view view){ startactivity(new Intent(this, SetTriggersActivity.class)); HelpActivity.java package com.domotics; import android.app.activity; import android.os.bundle; public class HelpActivity extends Activity{ public void oncreate(bundle savedinstances){ super.oncreate(savedinstances); setcontentview(r.layout.help);

AndroidManifest.xml <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.domotics" android:versioncode="1" android:versionname="1.0" > <uses-sdk android:minsdkversion="8" /> <uses-permission android:name="android.permission.internet"/> <application android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:debuggable="true"> <activity android:label="@string/app_name" android:name=".startupactivity" > <intent-filter > <action android:name="android.intent.action.main" /> <category android:name="android.intent.category.launcher" /> </intent-filter> </activity> <activity android:name=".mainactivity"></activity> <activity android:name=".lightsactivity"></activity> <activity android:name=".temperatureactivity"></activity> <activity android:name=".humidityactivity"></activity> <activity android:name=".advancedactivity"></activity> <activity android:name=".helpactivity"></activity> <activity android:name=".settriggersactivity"></activity> </application> </manifest>