Rebooting The Modem

BSNL Broadband is a very unreliable one most of the times because of the ADSL signal on a copper line and weather (yes, believe me it is!) – it is always bouncing and the DSL protocol renegotiated. This invariably means I can’t access my Synology DS214Play NAS server from anywhere outside my home. This is because my public IP address changes. I haven’t paid for a static IP as it costs a bomb and it is not reliable either because of the reason mentioned in the opening line of this post.

The synology has a built-in mechanism of refreshing the NAS’s public IP address and usually it is pretty reliable. All the above assumes that the TP-link modem (shown in picture for illustration only) is quite a robust one when it comes to ADSL protocol negotiation and frequent re-establishment of the PPPoE connection and getting a public IP address. Many a times, I have seen that the TPLink Modem hangs and not able to either establish a DSL link or obtain and renew a public IP. In such situations, I am left with no access to my NAS as mentioned before.

TPLINK - 8817 ADSL Modem

TPLINK – 8817 ADSL Modem

After pouring over the web and analyzing many options available – from replacing the modem with a better one  to rebooting the modem every now and then. Those solutions were impractical – changing the modem – because of costs. rebooting the modem regularly – 5mins, 1hr or 1day??

I came up with the below solution.

Rebooting/Resetting the Modem whenever

– there is a connectivity loss to an external device/node and sending email if reboot triggered.

– whenever an internal connectivity loss to one of the LAN nodes and sending email when reboot triggered.

– if we are redirected to a different page from the ISP and asking us to reboot the modem. Yes, this is done by BSNL after you reach the FUP limit.

I have observed that while the Modem is in the hung state, it’s CLI is still accessible via telnet and I am able to run administrative commands.

Scripts running on the NAS:

1. logip_reboot.sh  – A Shell script having the logic to determine the IP and reboot modem in case of failure. This is run every five minutes as a cron job.

#!/bin/bash
export MYIP=`cat /volume2/Aashman/Dropbox/aashman/logs/ip.me`
### curl ifconfig.me > /home/aashman/ip.me
### export NEW_IP=`cat ip.me`
### export NEW_IP=`curl ifconfig.me`
export NEW_IP=`curl http://myip.xname.org`

#Strings present in the BSNL redirect page.
export REDIR_MSG_1="Please wait while you are redirected"
export REDIR_MSG_2="ssssportal.war"

#To flag redirect page or not.
export IS_REDIR_MSG=0

#---------------------------------------------------------------
### export NEW_IP="<html>
### <head>
### <meta http-equiv=\"Refresh\" content=\"1; URL=http://172.30.3.136:8080/ssssportal.war/fup_4m-8g-512k.jsp\">
### <meta http-equiv=\"pragma\" content=\"no-cache\">
### </head>
### <body>
### Please wait while you are redirected ...
### </body>
### </html>"
#---------------------------------------------------------------

if [ -z "$NEW_IP" ]
then
 echo "NULL Returned from curl"
 echo "IP:NULL | `date`" >> /volume2/Aashman/Dropbox/aashman/logs/ipAdd.log
 exit
fi


#Debug , enable to debug.
### echo "$NEW_IP"
### echo " "
### echo "IS_REDIR_MSG:$IS_REDIR_MSG"

#Check if it is the redirect message.
case "$NEW_IP" in
 *$REDIR_MSG_1*)
 printf "\nSet for Reboot now, Found: \"$REDIR_MSG_1\"\n";
 export IS_REDIR_MSG=1;
 ;;
esac
case "$NEW_IP" in
 *$REDIR_MSG_2*)
 printf "\nSet for Reboot now, Found: \"$REDIR_MSG_2\"\n";
 export IS_REDIR_MSG=1;
 ;;
esac

if [ "$IS_REDIR_MSG" == 1 ]
then
 printf "\nRebooting Now, IS_REDIR_MSG: TRUE\n\n";
 sh /volume2/Aashman/Dropbox/aashman/scripts/syno/rebootModem.sh
 printf "\n\n_____________________________________________________________________\n"
 printf "\n"
 printf "|*******************************************************************|\n"
 printf "|*** Done Rebooting ADSL Modem - Try connecting after sometime   ***|\n"
 printf "|*******************************************************************|\n"
 printf "_____________________________________________________________________\n\n"
 # Send email here and log.
 echo "ADSL Modem Rebooted | `date` " >> /volume2/Aashman/Dropbox/aashman/logs/adslModemReboot.log
 echo -e "Subject:ADSL Modem Rebooted\n\n" "ADSL Modem Rebooted @ `date`" | sendmail -F "Aashman" -f home.aashman@gmail.com pradeepprakash@gmail.com
 exit
else
 printf "\nChecking if IP Address has changed and Logging, IS_REDIR_MSG: FALSE\n\n";
 echo $NEW_IP > /volume2/Aashman/Dropbox/aashman/logs/ip.me
 if [ "$MYIP" == "$NEW_IP" ]
 then
 echo "IP Has not changed"
 #echo "IP:$MYIP | `date`" >> /volume2/Aashman/Dropbox/aashman/logs/ipAdd.log
 #cat /volume2/Aashman/Dropbox/aashman/logs/ip.me | mail -s "Public IP Address Changed" pradeepprakash@gmail.com
 #echo -e "Subject:IP Address Not Changed\n\n" `cat /volume2/Aashman/Dropbox/aashman/logs/ip.me` | sendmail -F "Aashman" -f home.aashman@gmail.com pradeepprakash@gmail.com
 else
 echo "New IP is $NEW_IP"
 #cat /home/aashman/Dropbox/aashman/logs/ip.me | mutt -s "Public IP Address Changed" pradeepprakash@gmail.com
 #cat /volume2/Aashman/Dropbox/aashman/logs/ip.me | mail -s "Public IP Address Changed" pradeepprakash@gmail.com
 echo "IP:$NEW_IP | `date` **" >> /volume2/Aashman/Dropbox/aashman/logs/ipAdd.log
 echo -e "Subject:Public IP Address Changed\n\n" `cat /volume2/Aashman/Dropbox/aashman/logs/ip.me` | sendmail -F "Aashman" -f home.aashman@gmail.com pradeepprakash@gmail.com
 fi
fi

2. rebootModem.py – A Python script to reboot the modem. This is called by the above script.

import getpass
import sys
import telnetlib

HOST = "192.168.1.1"
#user = raw_input("Enter your remote account: ")
#password = getpass.getpass()
password = "aashmanf2$"

tn = telnetlib.Telnet(HOST)

#tn.read_until("login: ")
#tn.write(user + "\n")
if password:
 tn.read_until("Password: ")
 tn.write(password + "\n")

print "rebootModem.py - All set for rebooting\n Done!!"
tn.write("set reboot\n")
tn.write("exit\n")

print tn.read_all()

3. Crontab entries:

#minute hour mday month wday who command
*/5 * * * * root sh /volume2/Aashman/Dropbox/aashman/scripts/syno/logip_reboot.sh

Home Automation: NFC And LED Lights

Why and What:

I  bought the LIFX LED Smart Light Bulb some time back. It is a really nice LED bulb which connects to your home WiFi network. Using an app on your smartphone ( Android or iOS ), you can control the light – switch ON/OFF, change the color and intensity, invoke some special effects like – equalizer, alarm, strobe, random etc. Totally liking the bulb. Thanks LIFX!

But, I still needed to open the app and trigger the above – Not exactly equivalent to just flicking the panel switch ON or OFF.  Then came the idea of automatically switching it ON/OFF when certain conditions are met. Also, I do not want any person to operate and be able to control the lights – security matters. I can authorize only a few NFC tags with unique ID to allow the LED bulb operation.

How:

NFC came to the rescue. NFC or Near Field Communication is a technology which is based on secure data exchange between two devices. It is hugely popular off late. NFC capable tags ( similar to RFID tags) are available easily and commonly. NFC Tags these days are not all that expensive. You get 5 re-writable NFC tags for about ₹250.00 and it can be easily sourced from ebay, flipkart etc. I used the Topaz 512, a 512 byte capacity NFC tag for my purpose.  This is compatible with many smartphones and specifically tested and found to be both writable/readable from my Android based Samsung Note 3 (SM-N9005) and my wife’s  Samsung Galaxy S5.

Google Play store has tons of NFC Apps which can read/write the tags with the information you want. I used NFC Writer by Tagstand, having found to be the simplest of them all.

LIFX community developers has developed a LIFX Plugin for Tasker which can control the lights from the Tasker App. Tasker is one of the best automation app available on android today. I regularly use Tasker to automate a lot of things on my smartphone. Now I just needed to tie the NFC Tag with certain information in it to control the LED Lights to Tasker App by creating a Tasker Task.  With that done pretty easily by the above app and the Tasker App Task to switch ON/OFF the LIFX LED Bulb, it was all ready.

One small glitch in this solution. Tasker ( as of writing this blog) doesn’t support the NFC reading for some reason. This made me hunt for the plugins for Tasker, but to no avail. After lot of searching and researching on the web, one android app called Trigger came to the rescue. Ideally I would have liked to eliminate the need for this “wrapper” app to get things done. But I had no choice. Trigger is an app in which you can create trigger tasks/jobs/apps if certain criteria is met. For example, if it is 3:00pm, turn on the radio, put the phone to silent etc. One of the trigger scenarios is the NFC Tag Read. When a pre-programmed NFC tag ( has a unique id)  is read and authenticated,   I can use this as a trigger to launch an app/task/job. This app also has the option of invoking the Tasker Task and I made use of this for my application. See diagram for more details.

Now I really need to just bring my Note3 near the NFC Tag that I have programmed earlier to switch ON/OFF the LED Bulb in my living room. I can stick the NFC Tag on my coffee table, near or on the main door, have it in my wallet or anywhere it is most comfortable to have. I have been using it for the past couple of months and working like a charm.

Block Diagram:

NFC + LIFX + TASKER

NFC + LIFX + TASKER

 

Pictures:

Tasker Setup [ Lifx ON / Lifx OFF]:

Tasker LIFX Setup

Tasker LIFX Setup

Trigger Setup:

Trigger NFC Task

Trigger NFC Task

Lifx Tasker Plugin:

LIFX Tasker Plugin

LIFX Tasker Plugin

 

Topaz 512 NFC tag:

Click on the image to enlarge. You will find a tiny black dot – the NFC Chip, and a coil  – used as antenna or induction coil to induce a current to power the IC Chip. Passive NFC tags work on the principle of induction to inject and power the tiny IC Chip and exchange data to and from the chip.

This particular NFC tag is a little bigger than usual. It’s sensitivity being higher due to the bigger and larger induction coil. But there are much smaller ones available as easily.

 

Topaz 512 NFC Tag

Topaz 512 NFC Tag

Topaz 512 NFCTag - Compared with a ₹2.0 coin.

Topaz 512 NFCTag – Compared with a ₹2.0 coin.

 

Apps / Tools used:

Click  below to open the App/Tool website.

Tasker App

Trigger App

Tagstand NFC Writer

LIFX Tasker Plugin

Hardware devices used:

Samsung Note 3 (SM-N9005) Android Smartphone ( NFC Enabled).

LIFX Smart LED Bulb

Topaz 512 NFC Tag

Mesh Network In The Air!

Connectivity of the commercial airlines has increased drastically over the past 50-60 years. They now cover pretty much the entire globe. The number of operators are more than ever in the airline industry. The air crafts themselves are highly advanced and now are able to provide sophisticated services and features to the passengers like never before.

Now, How can this be leveraged in telecommunications all over the world? The idea or the concept below might be a very far fetched, futuristic looking and impractical one at this moment. But not an impossible one. Hear it out.

Let’s look at the world map,at any given instant, with the overlay of the flight path data of all the airline operators in the world – both  cargo, as well as passenger airlines. Here is what it looks like for the passenger flights alone at the instant this post was being written. At any given point of time, the map looks more or less the same – the density of air crafts in the air.

This can be leveraged into providing a “Mesh Network In The Air”, the topic for today’s post.

Flight Positions overlay on world map. Courtesy:  http://www.flightradar24.com/

Flight Positions overlay on world map. Courtesy:  http://www.flightradar24.com/

Here is how the flight path of all the air crafts in the world look like.

Simplified Flight Paths

Simplified Flight Paths

How:

Let’s assume we are able to install commercially available routers (communication devices) with powerful radios which can beam data to and from the other air crafts. The air craft has all the power that the router and the radio component needs to go about doing its job. This way each of the aircraft can communicate with other air crafts in the range. The range can be made configurable based on certain criteria and costs.

Each of the routers and the radio module on-board the air craft must be able to advertise itself as operational and ready-to-serve. This way routers can indicate whether they can participate in the building of the Mesh Network.

The protocol-suite(s) itself running on-board these routers must cater to the following:

   (i) Route the path to a different advertised and available router-on-craft to maintain the continuity in communication.

  (ii) Discover (advertising capabilities on radio) and auto-configure themselves with the next router-on-craft that comes up “online” to serve.

 (iii) Handle a particular router’s entry/exit from participating in the formation of the Mesh Network.

 (iv) <More scenarios here – TBD>

Why:

 – An “in-between-solution”  to the very expensive satellite communication and the terrestrial wired/wireless networks.

– If any loss of all means of terrestrial communications (maybe due to natural calamity in a particular geography) , the Mesh-In-The-Air can be made available at short notice restoring critical communications.

– Possibility of more capable services on-board the air craft – both for passengers as well as features for operators – advertising, commercial benefits etc.

–  ATC communication now more efficient and in case of accidents – more relevant and up-to-date data available for post-mortem/analysis. Data might be synced with other air crafts in the vicinity and which is part of the mesh and can be relayed to the ATC.

– Aircraft-to-aircraft direct communication possibility opened –  detection and avoiding collision made more efficient and fool proof. This is a mutual and/or additional benefit.

A Rough Visualization:

It is to be noted that the below is for illustration purposes only. The  air crafts show here forming a mesh network, in the real world scenario, would not be separated in distance as much as shown below.

Mesh Network Of Aircrafts

Mesh Network Of Aircrafts

 

Update [18th March 2015]:

Brainstorming this idea with a couple of people led to a couple of points to note.

(i)  The aircraft(s) mentioned in the above idea can very well be

  • Hot air balloons which can be kept in flight for long periods of time or self sustaining ones.
  • Solar powered drones ( think Solar Impulse).

(ii)  Geographies covered by these networks need not be just in the flight paths as mentioned above.

       With point (i) in mind, the mesh-networks can be extended to

  • Arctic/Antarctic geographies.
  • Scandinavian geographies.
  • Deserts ( if needed).
  • Areas where either terrestrial network infrastructure is deficient or non-existent.

Motion for Home Security

Home security and monitoring are the buzz words today. Every home has some kind of security and monitoring tools installed nowadays. Be it for perimeter security, in-home security, baby monitoring  and many others.

In this age of the internet and open source world, a home brewed solution is not a tedious task to achieve.

This post concentrates on one such solution listing all the tools which are completely free and open source.  Subsequent posts will detail the installation/setting up and configuration of each of them in detail.

Requirements:

1. A Linux box:

Installing linux have never been so easy. Gone are the days when a linux installation from scratch would take hours – debug, find solutions for problem specific to the hardware being used. It used to be a big task to hunt for the device drivers for specific hardware. That is all a problem of the past now. Popular distributions like Ubuntu, SuSe etc have all that is needed to get you up and running in less than an hour’s time. There are numerous guides for how to install linux on a particular desktop/laptop etc.

In my case I am using my old laptop, fully functional. Being a old system, it is too slow for modern day requirements. A system with 1GB RAM, atleast 40GB of HDD, USB ports, RJ45 LAN ports and/or WiFi is sufficient.

2. Any USB camera and/or IP camera:

 Lots of USB webcams are available in the market for a very good price. Any USB camera will do. Just make sure you are satisfied with the image quality ofr your application. As to the IP cameras, lots of them are available in the market with several features – built in WiFi , Infrared, PTZ (Pan Tilt Zoom) functionalities. Pick up the one which suits you best. I ordered mine from Ali Express for 40$ USD. It is working beautifully for the past 1.5years. It is a Chinese make ( What is not these days :)).

3. Motion:

Setting up motion is a easy thing to do. Read the documentation to configure it for your usage. Detailed below is for  the configuration I have, but it should not be too different for different configurations.

4. Dropbox:

  Dropbox is a useful tool to have. If you haven’t signed up for it yet, you should. Here, it is optional that you have Dropbox. But if you are the types that you want the images from anywhere in the world, then Dropbox is the easiest way to go!

As mentioned earlier, I will shortly blog in detail on how to install and setup each and every one of the above .

Black Box In Aircrafts

We all know about the black box in aircrafts. Its been there for many years and little have changed about how it works. Whatever that has changed is only how you store the data, and what data is stored. Little has changed on how the black box is handled in times of crises – like a crash, emergency landing on water etc etc.

We all know that Navy aircrafts use the ejectable black boxes. The same should be implemented in commercial aircrafts too.

Most of the times, during emergency, accidents pilots look for a water body to land/crash land the aircraft. The blackbox should be implemented in such a way that when it comes in contact with water (for let’s say more than an hour), there should be mechanism built into the blackbox to non-destructively explode and cucoon itself inside a floatable, pressure proof, balloon, brightly colored and float on water as buoys. That way it is easier to retrieve the blackbox in a much quicker time than what is done today.
Just a thought…….

Crowd Searching

Crowd Searching:
We all know about the recent Malaysian Airlines #MH376 flight which has been missing.Even after 5 days, not much have surfaced – debris, floating remains, oil slicks etc. The area involved is huge. For comparison, it is like finding a pebble in a football field as someone pointed out.

In such situations, we should make use of all the technology we have at our disposal. One such thing is the “crowd searching” (may not be the right term) – deploy satellites with high resolution imaging capabilities and gather as many images as possible from the probable region and make it available in public domain server. Volunteers (general public) can then be asked to identify any unusual patterns which might be the crash site, debris etc. Internet can be used to reach out to huge number of people. Maximum number of clicks for a particular image might mean something (statistics rarely lie).

Then when we have the probable areas we can target a narrower region with as many vessels. The process might be quicker.

Just a thought.

This idea is not new, have been used from a long time to convert illegible texts and numbers into meaningful texts. Why can’t it be used for a search and rescue, might save some lives if we act quicker.