Temboo-less tweeting from the shellLinkIt 7688 Duo is a cheaper ($15.9 vs $74.95) and breadboardable version of Arduino Yun. Arduino Yun comes preloaded with Temboo whereas LinkIt does not have that preloaded. Temboo is a great go between service that allows your IoT project to talk to existing services like google drive, twitter or dropbox - but to do anything long term and meaningful with it, you have to upgrade from a free temboo plan to a paid plan - Arduino Yun is already expensive and this makes it even moire expensive. I used Arduino Yun and Temboo to make a shimmering lamp that reacts to tweets from your sweetheart - But now it was time to move on to better yet cheaper builds.
A Raspberry Pi running Node Red can achieve a lot but here I want to focus on LinkIt because I am using it as a part of a larger "art" project. Since LinkIt has an AVR microcontroller (Arduino programmable over WiFi and Arduino Bridge), it allows for greater flexibility in interfacing to sensors and modules via the microcontroller. Also, until someone (or me) ports Node Red to OpenWrt platforms, I would prefer to use bash scripts and Arduino code to get my bidding done.
So one of the first things on my agenda was to figure out a Temboo less way of fetching tweets. What is outlined below is how I got https://github.com/piroor/tweet.sh (which is a bash script to fetch tweets)to work on OpenWrt - more specifically LinkIt 7688 Duo. For this, we wont be writing any Arduino code since the Microcontroller does not come into play (yet). But what we will be doing is playing around with bash scripts and cross compiling 2 packages for OpenWrt.
|My LinkIt 7688 Duo as a part of a larger project.|
The LinkIt is the one in the middle. The one on a bottom is a 5V powersupply.
And the one on top is a dimmer circuit - similar to the one I used in my twitter lamp project.
Step 1 - Cross compiling packages required by tweet.shSince tweet.sh is just a bash script, it requires certain packages to exist on your system. They are curl, jq, nkf, openssl. Of these openssl and curl can be installed on your LinkIt since they are a part of the OpenWrt repositories. But jq and nkf - these you will have to cross compile on a Linux PC and transfer them to LinkIt.
Here are the steps to make sure you have all the packages required by tweet.sh on your LinkIt:
- Connect your LinkIt to your home's WiFi network - check this
- Figure out your LinkIt's IP address - there are many ways to do this:
- You may need to log on to your WiFi Router's page from your PC and look at the list of devices and IP addresses.
- You can install Arduino on your PC, add support for LinkIt 7688 Duo and then wait for a few moments till Arduino automatically discovers the LinkIt. Then you can look under Tools>Ports
- Use PuTTY to login to your LinkIt 7688 Duo. Login will be "root" and password would be whatever you set during the getting started stage.
- Lets install the basic packages that are required and available - execute the following commands on LinkIt over PuTTY:
opkg install ip curl openssl bash nano grep getopt bc ca-certificates
- We still need to install nkf and jq. For that, we will need to use a Linux computer - preferable one running Ubuntu and perform the following steps (on your Linux PC not LinkIt):
- Download OpenWRT SDK for Linux from here onto your x64 Ubuntu Laptop. (I used Ubuntu 15.10 x64 on a VirtualBox Virtual Machine - I used a virtualbox image from http://www.osboxes.org/)
- Extract the folder to your home folder:
tar -xvf OpenWrt-SDK-ramips-mt7688_gcc-4.8-linaro_uClibc-0.9.33.2.Linux-x86_64.tar
- Install some required build tools on your Ubuntu PC:
sudo apt-get install autoconf build-essential
- Set the environment variables:
- Change to ~/OpenWrt-SDK-ramips-mt7688_gcc-4.8-linaro_uClibc-0.9.33.2.Linux-x86_64.tar/package :
- Create two folders here:
- Create the makefile for jq and place it in the jq directory that you just created. (Appended Below):
- Create the makefile for nkf and place it in the nkf directory that you just created (Appended Below)
- Go back to ~/OpenWrt-SDK-ramips-mt7688_gcc-4.8-linaro_uClibc-0.9.33.2.Linux-x86_64:
- And issue the make command:
- cd to the ourput directory:
- You will find the two .ipk files:
- Copy these two ipk files to your LinkIt 7688 duo. you can do this in many ways but the best way is to use scp protocol. In my case I simply copied the files from my Ubuntu Virtual Machine to my Windows machine and used WinSCP (Make sure file protocol is set to SCP) to login into my LinkIt and copied the .ipk files to the /root folder there.
- Issue the following commands to install jq and nkf on your LinkIt (Issue commands over PuTTY while in /root directory):
opkg install jq_1.5_ramips_24kec.ipk
opkg install nkf_2.1.4-1_ramips_24kec.ipk
- And you are done with installing the required packages
|Using my router's page to figure out the IP addresses of my 2 LinkIts connected to my home network.|
The MAC addresses of LinkIt begin with 9e:65:f9
(Yes I have OpenWrt installed on my home router as well)
|Using Arduino IDE to figure out the IP addresses of LinkIt|
Here are the Makefiles for cross compiling jq and nkf
Makefile for nkf:
Makefile for jq:
Step 2 - Cross compiling packages required by tweet.sh
Next we need to get tweet.sh onto LinkIt and configure it.
- Visit https://github.com/lithiumhead/tweet.sh download tweet.sh and tweet.client.key to your PC and transfer it to your LinkIt using WinSCP. You can also download the two files directly to your LinkIt by issuing 2 commands over PuTTY:
curl -O https://raw.githubusercontent.com/lithiumhead/tweet.sh/master/tweet.sh
curl -O https://raw.githubusercontent.com/lithiumhead/tweet.sh/master/tweet.client.key
- Mark tweet.sh as executable:
chmod +x tweet.sh
- Now we need to configure the keys and add them to tweet.client.key on LinkIt. Visit twitter.com and login to your twitter account.
- Next open a new tab in the same browser and visit https://apps.twitter.com/
- Click on "Create New Apps"
- Enter something in Name, Description and Website
- Accept the Developer Agreement and click "Create your Twitter Application"
- Now click on your newly created application and click on "Keys and Access Token"
- Open tweet.client.key over WinSCP and copy and past key from the webpage to tweet.client.key
- Enter your twitter handle next to MY_SCREEN_NAME=
- Enter "en" next to MY_LANGUAGE=
- Copy the string mentioned next to Consumer Key (API Key) to CONSUMER_KEY=
- Copy the string next to Consumer Secret (API Secret) to CONSUMER_SECRET=
- Copy Access Token to ACCESS_TOKEN=
- Copy Access Token Secret to ACCESS_TOKEN_SECRET=
- Click save
The original tweet.sh is published at https://github.com/piroor/tweet.sh but I had to fork it and make some modification to it so that it would run on OpenWrt. I have forked it at https://github.com/lithiumhead/tweet.sh and that's what we have used. (Modifications involved creating symbolic links to stdin and stdout in proc file system - these are lacking by default in OpenWrt)
Finally everything is set and we can test our tweet.sh setup by fetching the latest tweet from - say - elonmusk, piping it through jq and printing only the unique tweet id and the text of the tweet itself:
./tweet.sh search -q "from:elonmusk" -c 1 | jq '.statuses.id, .statuses.text'
|tweet.sh running in a PuTTY window with Twitter open in Google Chrome|