Successful testing

After weeks of development, the “Life of Trash” app has undergone preliminary testing with great success, and a few bumps. App development began on the android platform primarily because of its open source nature, access to a large community and ability to be deployed on less expensive phones. The first iteration of the app focused mainly on the essential elements to make the app useful, location updates and sending automatic SMS’s.

After the app was built in a basic form, I first began to set the automatic SMS messages every five minutes while I went for a brief walk around the neighborhood. Upon returning and access the Life of Trash website to verify coordinate accuracy and proper automation.

The results seemed positive with successful coordinates and regular SMS messages being sent over the course of the walk. I then moved the testing into a second phase to check the duration of the phones life while only running the app. This required charging the phone fully and launching the app until the phone’s battery died.

Initial Failures

The second phase of testing began on a Thursday evening as went upon my normal routine. The following morning I decided to verify the app was still performing by again checking into my twilio account. To my surprise, the account had been suspended due to lack of funds which was surprising given the low cost of SMS messages and the amount of fund that were previously in the account.

As I began to investigate, I realized that the app had fired over 2,000 messages through the night using all of the funds in the account. Though the phone was supposed to send and SMS every 15minuets, it began firing messages every 30 seconds.

Looking into what caused this in the code, I realized that the function to send an SMS was mistakenly placed inside the function that checks for new locations. Therefor, each time the phone looked for a new location, it sent an SMS with that new location. Lesson learned.

Looking at the code

Android programing has many interesting aspects of which I was able to take advantage . One of the more important aspects to the app is the ability to send and automated SMS. This requires the use of an alarm in combination with a broadcast receiver.

The broadcast receiver is function that gets called when a core function of the phone is setup. One core function which is available to android programming is an alarm. With a few lines of code, one can set an alarm to send a message which the broadcast receiver is setup to listen. When the broadcast receiver receives this message, it can perform other tasks available to it.

The below code takes the current time, adds 15minutes and then sets the AlarmManager to send a message after the 15 minutes has expired thus triggering the SMS.

public void setTimer(){
	// Setup the broadcast receiver to listen for an alarm
	Intent intent = new Intent(this, BroadCastReceiver.class);
	intent.putExtra("alarm_message", "O'Doyle Rules!");
	PendingIntent sender = PendingIntent.getBroadcast(this.
	getApplicationContext(), 192837, intent, PendingIntent.FLAG_UPDATE_CURRENT);

        // add 15 minutes to the current time
        Calendar cal = Calendar.getInstance();
        cal.add(Calendar.MINUTE, 15);	

        // Get the AlarmManager service
        AlarmManager am = (AlarmManager) getSystemService(ALARM_SERVICE);
        am.set(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), sender);	


Future Iterrations

As of right now the basic functionality of the app is working. An alarm is set to fire every 15 minutes which then causes the phone to get its current coordinates and send them to a specific phone number via SMS.

In the next iteration, I plan on accessing the core services of the phone and suspend automate a suspension of those functions. This will cause the phone to shut down as much as possible until the moment when it needs to gather its location and send those coordinates back to the central server. This will be an important element because it will increase the battery life by a few days allow the tracking of trash to extend further.