The Goal
A self-reporting, ISP bandwidth checking router that is integrated to the IFTTT Maker Channel and requires NO ADDITIONAL HARDWARE!!!
The IdeaIt started when I saw a hackster post from Alasdair Allan, "Monitoring your Broadband Connection with Raspberry Pi". I immediately fell in love with his project as well as the idea in general. I respected it to mark it as a favorite, so I could implement it as soon as I got time.
Unfortunately, I had a couple problems that prevented me from knocking it out that same day, so it has taken a little while.
- First, I only have one Raspberry Pi 2, so I didn't want to devote it to the noble but somewhat lackluster cause of a desk job.
- Second but way more important, I have a crazy two-year old, who doesn't need a rope and handle to get a hold of my router!
Plain and simple, I can't tell why my internet sucks. I wanted to build Alasdair's project, but I actually have two problems to solve.
- My networking hardware is completely unreliable.My ISP seems to drop on occasion and is willing to offer rebates if I offer documentation
- Once I have a stable network, only then will I be able to tackle the project to keep up with my ISP.
I live in a condo building with no less than 20 wifi networks available at all times, and my network has been ridiculously unstable for so long I can't remember.
Usually my router was to blame, and a simple restart would put me back in business. Honestly, the router failing became so routine that when my ISP went down for two days, we were so busy we just thought the router had crashed again.
Eventually, my router became so ashamed of its poor performance, it decided to fall on its sword and burn out. After a brief period of mourning (a.k.a. the length of time required to enable a hot-spot from my phone), I purchased the latest, greatest, best-selling, deal of the millennium from Amazon, the TP-LINK Archer C7 AC1750 Dual Band Wireless AC Gigabit Router. Wow, what a mouthful!
On the datasheet it is phenomenal, it has dual antennae so it can broadcast a 5GHz and 2.4GHz at the same time and it is a GB switch. However, that is where the coolness ends. It has terrible firmware out of the factory and the 5GHz antenna drops every two days, and won't work again until it is restarted.
After all that, I was out 100 bucks, and I still had hardware trouble.
The SolutionI have known about OpenWrt for sometime now, but I had never had the time to mess with it and, frankly, I was afraid I would wreck my networking hardware. Thanks to the horrible firmware, I felt like I had nothing to lose, so I decided to convert my router over to OpenWrt.
Converting to OpenWrt was SO, SO EASY I couldn't believe I didn't do it earlier! Not to mention it is Linux and it runs like a champ; I'm on day two and I just can't stop gushing over it.
Next, by simply installing a few packages, tweaking a couple of settings, and adding a single script to the router, you have a self-reporting, ISP bandwidth checking router that requires NO ADDITIONAL HARDWARE!!!
The Steps1) Install the "Unlocked Firmware" attached to this project. This can be installed via the normal firmware upgrade interface hosted on the router.
2) Install "OpenWrt 15.05 (Chaos Calmer)" attached to this project. This can be installed via the normal firmware upgrade interface hosted on the router.
IMPORTANT: You must install 15.05, not 15.05.1. There is a bug in 15.05.1 that has been reported to brick devices!
3) Configure the router. Not only will you probably want to use the internet, but several features are enabled on OpenWrt after you have logged in and setup a password for the root
user and rebooted the device.
4) SSH into the device. After you have successfully setup the router, you will be able to ssh into the device using: ssh root@192.168.1.1
and supplying your password.
IMPORTANT: The device has very limited resources and installing the required packages will take approximately 9 of 11MB of flash on the device. Please take care to follow the directions exactly and do NOT install any other packages!
5) Install python pip. Doing this will also install all of it's dependencies (like python itself) and will give us everything we will eventually need to run the speed test.
opkg update
opkg install python-pip
6) Install curl. Not only is curl great, but it's required to interface with IFTTT.
opkg install curl
7) Add root certificates. Most browsers/distributions/etc ship with root certificates from the major Certificate Authorities, such as VeriSign and GeoTrust. Root certificates are used to validate the certificates presented by servers. OpenWRT does not include root certificates, so it is up to you to install them(1).
opkg install ca-certificates
8) Install the speedtest-net python package. This is the core software that will run and gather the bandwidth statistics from your ISP.
pip install speedtest-cli
9) Create IFTTT recipe using Alasdair's template. Take note of the "Recipe Event Name" and the "Channel Key". You will need them to update the speedtest-ifttt.sh script in the next step.
10) Update and copy speedtest-ifttt.sh into the /root directory (~) of the device. This file is supplied in full at the bottom of the page. I have modified it to use the Almquist shell `ash` syntax, as well as to respect the directory structure of OpenWrt. You will need to replace with the event name you chose, and with the key generated for you. Once you have finished updating the script, then copy it over using the following command (Linux).
scp speedtest-ifttt.sh root@192.168.1.1:~/speedtest-ifttt.sh
11) Schedule the task. First you must add the following syntax (below) to the "System>Scheduled Task" pane on the administration page hosted on the OpenWrt device and click "Submit".
# Report ISP statistics to IFTTT Maker Channel
*/15 * * * * ~/speedtest-ifttt.sh
12) Enable the cron daemon. You must do this step after you have completed step 11, or the cron daemon will NOT be enabled. The first command starts the job, and the second ensures that it will pick back up after reboot.
/etc/init.d/cron start
/etc/init.d/cron enable
13) Install `bash`. The script requires bash
, but Open-WRT only comes with ash
installed.
14) Test it. You can manually run the speed test by simply typing ~/speedtest-ifttt.sh
on the command line. If everything is wired up correctly you will see a response "Congratulations! You've fired the event"
15) Reboot. It's not necessary, but it always seems pertinent after you install a bunch of packages.
SummaryNow your router has much better firmware that gives you full control of the system. Not only that, but it will also help you keep your ISP honest, and give you the necessary talking points to have a frank conversation about any billing issues you may have.
Well, it looks like that $100 on Amazon was well worth the money, cheers!
Appendix A: Minimum required python componentsI tried to add this script to another router that I converted to OpenWRT (Linksys WRT320N/E2000). It ended up being too resource constrained, but I was able to distil the python installation down to the bare minimum requirements.
Required packages:
opkg install python-light
[1.5 MB]opkg install python-xml
[0.2 MB]opkg install python-openssl
[668kB]opkg install python-codecs
[0.8 MB]
After you have installed these packages (and perhaps during), you will want to start removing unnecessary files to free ~1MB in /rootfs
. The script will still execute as long as the following files are in place.
Required files:
/usr/lib/python2.7/encodings/__init__.py
/usr/lib/python2.7/encodings/aliases.py
/usr/lib/python2.7/encodings/ascii.py
/usr/lib/python2.7/encodings/string_escape.py
/usr/lib/python2.7/encodings/utf_8.py
/usr/lib/python2.7/lib-dynload/_collections.so
/usr/lib/python2.7/lib-dynload/_functools.so
/usr/lib/python2.7/lib-dynload/_hashlib.so
/usr/lib/python2.7/lib-dynload/_io.so
/usr/lib/python2.7/lib-dynload/_random.so
/usr/lib/python2.7/lib-dynload/_socket.so
/usr/lib/python2.7/lib-dynload/_ssl.so
/usr/lib/python2.7/lib-dynload/_struct.so
/usr/lib/python2.7/lib-dynload/array.so
/usr/lib/python2.7/lib-dynload/binascii.so
/usr/lib/python2.7/lib-dynload/cStringIO.so
/usr/lib/python2.7/lib-dynload/fcntl.so
/usr/lib/python2.7/lib-dynload/itertools.so
/usr/lib/python2.7/lib-dynload/math.so
/usr/lib/python2.7/lib-dynload/operator.so
/usr/lib/python2.7/lib-dynload/pyexpat.so
(python-xml)/usr/lib/python2.7/lib-dynload/select.so
/usr/lib/python2.7/lib-dynload/time.so
/usr/lib/python2.7/site-packages/speedtest_cli.py
/usr/lib/python2.7/xml/__init__.py
/usr/lib/python2.7/xml/etree/ElementTree.py
/usr/lib/python2.7/xml/etree/__init__.py
/usr/lib/python2.7/Queue.py
/usr/lib/python2.7/UserDict.py
/usr/lib/python2.7/__future__.py
/usr/lib/python2.7/_abcoll.py
/usr/lib/python2.7/_sysconfigdata.py
/usr/lib/python2.7/_weakrefset.py
/usr/lib/python2.7/abc.py
/usr/lib/python2.7/base64.py
/usr/lib/python2.7/bisect.py
/usr/lib/python2.7/codecs.py
/usr/lib/python2.7/collections.py
/usr/lib/python2.7/contextlib.py
/usr/lib/python2.7/copy_reg.py
/usr/lib/python2.7/functools.py
/usr/lib/python2.7/genericpath.py
/usr/lib/python2.7/hashlib.py
/usr/lib/python2.7/heapq.py
/usr/lib/python2.7/httplib.py
/usr/lib/python2.7/io.py
/usr/lib/python2.7/keyword.py
/usr/lib/python2.7/linecache.py
/usr/lib/python2.7/mimetools.py
/usr/lib/python2.7/optparse.py
/usr/lib/python2.7/os.py
/usr/lib/python2.7/pickle.py
/usr/lib/python2.7/platform.py
/usr/lib/python2.7/posixpath.py
/usr/lib/python2.7/random.py
/usr/lib/python2.7/re.py
/usr/lib/python2.7/rfc822.py
/usr/lib/python2.7/site.py
/usr/lib/python2.7/socket.py
/usr/lib/python2.7/sre_compile.py
/usr/lib/python2.7/sre_constants.py
/usr/lib/python2.7/sre_parse.py
/usr/lib/python2.7/ssl.py
/usr/lib/python2.7/stat.py
/usr/lib/python2.7/string.py
/usr/lib/python2.7/struct.py
/usr/lib/python2.7/subprocess.py
/usr/lib/python2.7/sysconfig.py
/usr/lib/python2.7/tempfile.py
/usr/lib/python2.7/textwrap.py
/usr/lib/python2.7/threading.py
/usr/lib/python2.7/timeit.py
/usr/lib/python2.7/traceback.py
/usr/lib/python2.7/types.py
/usr/lib/python2.7/urllib.py
/usr/lib/python2.7/urllib2.py
/usr/lib/python2.7/urlparse.py
/usr/lib/python2.7/warnings.py
To download the speedtest_cli.py
script directly (without having python-pip), use the following commands:
mkdir /usr/lib/python2.7/site-packages/
cd /usr/lib/python2.7/site-packages/
curl -Lo speedtest-cli.py
ln -s speedtest-cli.py /usr/bin/speedtest-cli
Comments
Please log in or sign up to comment.