Alright, I was looking through the referrers to my blog, and saw this search term that came from google.com “openwrt twitter client”.

I have no idea why you would want a twitter client on your router, but still, I was inspired to write a simple script that would allow you to tweet from the commandline of your OpenWrt router.

First I thought you should just use wget, but the wget that is part of busybox does not include the option to POST data, so a real script was needed.

First of, you need to generate a base64 string of your username and password, on a computer that have the base64 program installed, like this:

bredsaal@apex:~$ echo -n "bredsaal:mypassword" | base64
YnJlZHNhYWw6bXlwYXNzd29yZA==

Copy the resulting string into the AUTHENTICATION variable in the script.

#!/bin/sh

# every parameter after $0 is going to be in the tweet.
TWEET="status=$*"

# Generate the authentication string on your commandline
# echo -n "username:password" | base64
# and insert below.
AUTHENTICATION=""

CONTENT_LENGTH=`echo -n $TWEET | wc -c`

MESSAGE="
POST /statuses/update.xml HTTP/1.1
Host: twitter.com
User-Agent: OpenWRTweet
Accept-Language: en-us,en;q=0.5
Accept: application/json, text/javascript, */*
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
Content-Length: $CONTENT_LENGTH
Authorization: Basic $AUTHENTICATION

$TWEET"

echo "$MESSAGE" | telnet twitter.com 80 2>&1 > /dev/null

Save the script in a place that is in the path on the router, i.e /usr/bin/ or /bin/ and remember to make it executable by running chmod +x /path/to/tweet.

Run it like this: root@OpenWrt:~# tweet I am twetting from my OpenWrt router – beat that suckers!

Related posts:

Tags: , ,

6 Comments to “Building an OpenWrt twitter client”

  1. twitter client could be useful if the script is used in a way to send twitter updates of whats happening on the network.

  2. Indeed it would, and I don’t think it would be to hard to do. :-)

  3. Hey Jannich :) long time no see.
    Fun to surf around google and find your site number 5, when searching for “browser plugin java”, and then cross the path of bredsaal ;)

    Good blog, and especially this post.

    A network twitter client, for posting on shared company profiles could be very nice, is it easypeasy Jannich ? –

    I hope you hit back ;)

    / Nego

  4. Hi Nicolai, indeed long time no see. :-D

    Do you mean like a twitter post aggregator? I think something like that is already made, but I guess it wouldn’t be that much of a problem to make one yourself. :-)

  5. lostman says:

    hello. thought some me too.
    but twiter will end basic authorization in jun.
    so i created this it can update timeline with oauth.
    this was created based on sh.
    require openssl-util and curl.

  6. Hi Lostman.

    I didn’t know that basic authorization would end so soon, but your solution looks pretty cool. :-)

Leave a Reply

You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

This site uses KeywordLuv. Enter YourName@YourKeywords in the Name field to take advantage.