Greg Klein's Blog

Twitter, Ubiquiti, and Spots

leave a comment »

Okay, so if you haven’t yet, please read my last blog post.

Twitter has this great API that makes it super easy to “tweet” (I can’t believe I just used the word tweet). The coolest thing is, you hardly need any extra software, which is a huge plus, especially on the Ubiquiti Nanostation which only has 16 MB of RAM and 4 MB of flash. I read this great guide that uses cURL. Unfortunately, when I tried to install cURL on my Ubiquiti, opkg tried to install a couple MB to my flash; way too much. Curl was not feasible given my limited hardware.

Fortunately, there’s a smaller program that can accomplish the same thing: wget. OpenWRT already has wget installed, but it’s a smaller version of wget that doesn’t have everything we need (it’s actually part of BusyBox).

Now, one of the reasons that cURL is so large is because it wants SSL. We don’t need that, so we can install the package wget-nossl.

root@OpenWrt:~# opkg install wget-nossl -force-overwrite

The -force-overwrite is required or it’ll complain that wget is already installed:

* Package wget-nossl wants to install file /usr/bin/wget
But that file is already provided by package * busybox

Anyway, once we’ve got wget installed, we can post a message to Twitter like this:

wget --http-user=wifispaught --http-password=password --post-data=status="test!" http://twitter.com/statuses/update.xml

Now let’s see if we can’t add a Spot to the mix.

StreamConnection serialStream = (StreamConnection) Connector.open("edemoserial://usart?baudrate=9600&databits=8&stopbits=1&parity=none");
OutputStream out = serialStream.openOutputStream();
out.write(("wget --http-user=wifispaught --http-password=mypassword --post-data=status=\"Hello, world!\" http://twitter.com/statuses/update.xml\n").getBytes());

Okay, we need some code to run on the Ubiquiti side of things:

root@OpenWrt:~# head -n 1 /dev/ttyS0 | ash

This will read a line off of the serial connection (ttyS0), and then pipe the output into ash (a simple shell included with BusyBox). Since the SunSPOT is sending the wget command, there’s no need to do any parsing or logic.

Now I’ve got a SunSPOT posting to Twitter via wifi.

If you’re interested, here’s the twitter feed of the spot.

Written by gregklein

July 31, 2009 at 4:39 pm

Posted in java, sun

Tagged with , , , ,

Ubiquiti and Spots

leave a comment »

A significant part of sensor networks, is, well, the network. The radio on the SunSPOT is designed for low power consumption, and works well in relatively short ranges, something like 50-100 meters at the very most. When a stronger radio is required, you’ve got to do something else.

Spot_and_ubnt

The black PCB in the picture is an Ubiquiti NanoStation2, with a range of several miles over Wifi. Below, of course, is a SunSpot. They’re talking to each other over serial, which is provided on the Ubiquiti (actually, as it would turn out, most routers seem to have serial on the board). To make it a bit easier to use, I put OpenWRT on it so that I could take advantage of their package management (I can run Perl!), and other niceties.

Anyhow, the whole thing was remarkably easy to do once I disabled the existing output on the serial. Apparently OpenWRT, by default, has a console running on the included serial.

I had to edit /etc/inittab and remove the line:

ttyS0::askfirst:/bin/ash –login

Once the serial was free, I just set the parameters using stty, and can now write to the serial using the command

cat > /dev/ttyS0

And read from it with

cat /dev/ttyS0

Writing to serial is easy with a Spot:

StreamConnection serialStream = (StreamConnection) Connector.open("edemoserial://usart?baudrate=9600&databits=8&stopbits=1&parity=none");
InputStream in = serialStream.openInputStream();
OutputStream out = serialStream.openOutputStream();

Pins D0 and D1 are Rx and Tx, respectively.

I think I’ll tie it up with some Perl to report values back to sensor.network.

Written by gregklein

July 30, 2009 at 5:18 pm

Posted in java, spaughts, sun

Tagged with , , , ,

Eye-Fi and CHDK

with 3 comments

So we’ve got these really cool SD cards made by a company called eye-fi. The eye-fi automatically upload pictures to Flickr via wifi.

I’ve also been playing with a CHDK, a hacked version of Canon’s firmware for their point and shoot cameras. CHDK has worked beautifully, allowing me to take pictures in intervals and turn the camera off when it’s not needed (excellent for long deployment on a bridge).

I have, however, had one issue. To get the camera to boot CHDK, the SD card has to be placed in the “lock” position by flipping a switch on the of the card. However, the eye-fi has no such lock. So I’ve had to be a bit creative.

eye-fi

With some help, I cut a slot in the side of the card with a dremel, permanently locking it. No damage to the card was done; it’s still able to save images, etc.

A little piece of tape, placed over the new slot, will unlock the card.

Written by gregklein

July 15, 2009 at 2:30 pm

Posted in Uncategorized

Hello, World! (USGS, SunSpots, sensor.network and more fun)

leave a comment »

Hello, all!

I’m not entirely sure how to start out, so I figure I’ll describe the work I’m doing.

I’m currently (until the end of Summer 2009), an intern at Sun Labs. I decided to host the blog here instead of on Sun’s website because I’ll hopefully continue using the blog after I’m gone. I’m working on the SunSPOT project; more specifically, sensor.network.com. All of this has been described in great detail by another member of the spot team, Vipul Gupta.

Anyway, here’s where I come in.

In the lower left corner of that map is Sun’s Menlo Park office, where I’m located. Look a bit toward the center right of the image and you’ll see a white spot, just below the Bayshore Expressway; we’ll call that area SF2.

SF2 is an old salt evaporation pond, and before that it was a marsh. The USGS is trying to restore this area back to the wetlands they once were. More on that here.

As part of the restoration, the USGS is trying to monitor the area. That’s where we come in. They’ve got a few sensors that they’re going to be putting in the area, which will hopefully be reporting data back to sensor.network with the help of a SunSPOT, so that a researcher doesn’t need to physically access the sensor. Additionally, the USGS is interested in knowing what birds and how many are in the area; a process usually done by going to the site and counting birds for an afternoon a few times a year.

We’ve been playing with cameras, CHDK, eye-fi cards, and Ubiquiti wifi access points in the lab for a while now, and we think there’s a better way to monitor the area.

Our plan at this point is to place several Canon cameras running the CHDK custom firmware in boxes on the Dumbarton Bridge, pointed towards SF2. Each camera will have an eye-fi module that uploads the pictures it takes via wifi to an Ubiquiti access point located at the Sun campus a kilometer or so away. The cameras will take several hundred pictures a day, and the researchers will be able to get a more accurate ‘picture’ of the bird situation at SF2, without needing to spend a day on-site.

Stay tuned: I’ll be posting more information along with pictures and maybe some code soon.

Written by gregklein

July 15, 2009 at 11:04 am