research weblog of william carter @
division of interactive media
University of Southern California

January 30, 2009

New Location Example using home values

Hey,

Here's a new file showing how to use a home values web service to build a little price thermometer. Basically, in the new sketch, we set a switch that makes the app react to either the temperature service, or a home values service, and then decides what to do with the returned values.


//set up the service type, either temperature or homevalues
String serviceType;
serviceType = "homevalues";

//use this new url to get either temp or home values
request = client.GET("/clients/405/services.php?service="+serviceType+"&lat=34.052187&lon=-118.243425");

in the libraryEvent method, we'll check to see which type of service we are using. If it's the homevalues service, we'll turn on the draw() animation loop using loop(); Otherwise, we'll just call redraw() to call the draw() function only once.


if(serviceType == "temperature") {
redraw(); //call the draw() function once
} else if(serviceType == "homevalues") {
//start animating again
loop();
}

Download file

com.mpp.player.PowerPlayerAppScreenSnapz001.jpg

Posted by will at 3:45 PM | Comments (0)

January 26, 2009

Location Tutorial | Mobile Processing

As we went through in class today, it's pretty easy to get your phone's location using Mobile Processing and the GPS on the N95.

First, you'll want to grab the mlocation library from Mary Jane Soft HERE.

Once the zip file is downloaded, expand it so you have an mlocation folder. Drag that mlocation folder into your mobile processing application folder:

YOUR_MOBILE_PROCESSING_DIRECTORY/libraries/

You should see some other libraries already there. Once you do that, restart mobile processing if it's already open. Otherwise, just open it and you're good to go.

You can download the .pde (mobile processing sketch) here:

Download file

The main parts of code you should be interested in are...

This bit connects to the server nodesnoop.com:


client = new PClient(this, "www.nodesnoop.com");

After that connection has been made, we're going to query the mlocation library for the latitude and longitude.


MLocation.location(coords);

This sticks the latitude and longitude in the coods array, which we will use when we send the request to the server we just connected to:


request = client.GET("/clients/405/weather.php?lat=" + coords[0] + "&lon=" + coords[1]);

Here we're sending an http get request to the server we connected to above. We're requesting the file weather.php, and we're sending that file the parameters lat and lon, which are assigned values based on the coords variable we get from MLocation.

in the libraryEvent callback function we'll look for the file to be completed


} else if (event == PRequest.EVENT_DONE) {
//done reading
msg = new String((byte[]) data);
println(msg); //print out in the mobile processing debug window for testing purposes
request.close(); //close the request
redraw(); //call the draw() function once
}

Basically, this just says: "When the file is loaded completely, set the msg variable to the output of the file we requested." In this case, the file returns the current temperature of the latitude and longitude it was given.

After we do this, we'll call redraw() which calls the draw() method once.

First, we'll check if the msg variable got set correctly. If there was some issue, it will not be set, and therefore be null.


if(msg == null) {
background(255);
}

Otherwise, we'll do something based on that temperature value. In this instance, we're just changing the background color of the app based on the temp., but I'd imagine you can come up with something better than that.


} else {
//if we do, do something with that information.
//in this example, we compare the integer value of msg (the integer temperature)
//with a range of values to change the background color

//YOU CAN EDIT THIS CODE TO MAYBE DO SOMETHING MORE INTERESTING

if(int(msg) > 60 && int(msg) <= 70) {
background(255,255,0);
} else if(int(msg) > 70 && int(msg) <= 100) {
background(255,0,0);
} else {
background(0,0,255);
}
}

Posted by will at 8:34 PM | Comments (0)

January 12, 2009

Building a j2me app with Mobile Processing

One of the technologies the class will be looking at is mobile processing.

Mobile Processing is an open source programming environment for people who want to design and prototype software for mobile phones. It is based on and shares the same design goals as the open source Processing project. Sketches programmed using Mobile Processing run on Java Powered mobile devices.

Building an app with mobile processing is pretty simple.

1) Download mobile processing from here.

2) Follow the instructions there to download a WTK (wireless toolkit) to your machine. The WTK is basically just allows mobile processing to compile your apps and also a way to simulate them on the desktop. More on that later. Note: he WTK link has changed from what is on the mobile processing site. You can download it for mac here.

3) Install mobile processing and go to the mobile preferences tab (shown) to enter the path of the WTK you just installed.

Mobile%20ProcessingScreenSnapz001.png

4) Enter some code in your sketch window. You can choose something to quickly get started, copying and pasting from the examples. This one will do.

5) Run your app by pressing the little play icon in the upper left corner of the sketch window.

OR

6) Build your application for use on a mobile device. Choose Export MIDIet from the File Window

Mobile%20ProcessingScreenSnapz002.png

This is the basic procedure for building an application very quickly using mobile processing.

The class will provide 6 nokia N95 devices, which will be good to use if you are building a sketch in Mobile Processing. However, mobile processing is also designed to be able to be used with a wide array of devices. You can see if your phone is supported by checking the list here.


Posted by will at 9:55 AM | Comments (0)