Greg Klein's Blog

Archive for December 2009

Prepaid Phones, Sensor.Network, and Java

with one comment

So school is out for the year, and I’ve got some three odd weeks off — plenty of time for side projects.

Anyway, I picked up a really cheap prepaid cell phone a while back for $50, with $5 prepaid credit on it. Neat thing is that it runs JavaME and has a cheap GPS unit built in. Overall, the thing feels pretty flimsy and cheap, but I still can’t believe it was $50.

i290

The phone in question.

Anyway, Tim and I wrote a small bit of code to read the latitude, longitude, and altitude coordinates from the GPS unit on the device and upload it to sensor.network via a $0.35/day internet connection on the phone.

The code to post the sensor data was just a slightly modified bit from yggdrasil (actual source file is here).

HttpConnection conn=(HttpConnection)Connector.open(datastreamURI+"/data");
conn.setRequestMethod("POST");
conn.setRequestProperty("X-SensorNetworkAPIKey", APIKey);
conn.setRequestProperty("Content-Type", "application/xml");
conn.setRequestProperty("Content-Length", sampleDataXML.getBytes().length + "");
OutputStream os = conn.openOutputStream();
os.write(sampleDataXML.getBytes());

If you do take a look at the original source, you’ll notice that I had to change only a very small bit around; Java ME doesn’t have the URL class, so I had to open things up with a Connector; other than that, it was pretty straightforward.

So with a bit more code to sample the GPS, I’ve got a $50 GPS tracker that uploads data to the internet.

With Sensor.Network, I can graph where the phone is.

GPS Trace

A trace of the phone's location; you can tell that the GPS isn't very good.

Fun stuff.

Written by gregklein

December 15, 2009 at 1:47 am

Posted in sensor.network, java

Follow

Get every new post delivered to your Inbox.