Twitter, Ubiquiti, and Spots
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.