Tracking LAN Uptime on My ASUS/Merlin Router – Intro

In a previous post I talked about connecting my ASUS/Merlin router to AWS.  Well, now that I have done that it is time to really take advantage of that and track some router issues I am having.  I’ve never been a huge fan of wireless communications or even cell phones.  Both are unreliable.  Humans keep insisting on walls and building them out of material which screw up wireless communications.  And having a nice looking house is reversely proportional to the number of antennas you can see.  But I face reality and mostly get over it.  And I digress.

I’m having trouble with the wireless connection between my router and a couple of Roku boxes we use around the house.  So I would like to track outages over time so I can tell if my changes in settings and placement are making a difference.  When it is all set and done I want a text on my cell phone when a change is connection status occurs and a nice chart showing the outages over time.  Something like this (this is the finished product by the way).

To do this I want to use DynamoDB and Lambda.  Architecturally it will look like this.

Every 5 minutes a script will be executed on the ASUS/Merlin router.  That script will use ping to check and see if there is a wired connection, a wireless 2.4Ghz connection and a wireless 5Ghz connection.  It will then send the results to a Lambda function courtesy of API Gateway.  The Lambda function will store the received status in a DynamoDB table and compare the current status to the previous status.  If the status has changed the lambda function will publish the difference to the SNS topic which will forward the message to my cell phone.

Also, once a day, a scheduled CloudWatch event will launch another Lambda function which will read the data from DynamoDB, draw a plot using Python and Pyplot, and export the plot to S3.

I have talked about setting up an API Gateway in a previous post.  This API Gateway method used here is merely an extension of the API Gateway from that post.  In this case there are six parameters sent in the query string.

  • WiredHost – The host being checked to confirm the wired connection to the router is working.
  • WiredAlive – 1 if ping is successful, 0 if it is not.
  • Wireless24Host – The host being checked to confirm the wireless 2.4 Ghz connection to the router is working.
  • Wireless24Alive – 1 if ping is successful, 0 if it is not.
  • Wireless5Host – The host being checked to confirm the wireless 5Ghz connection to the router is working.
  • Wireless5Alive   – 1 if ping is successful, 0 if it is not.

The DynamoDB table is set up with the following columns

  • DayId – This is the primary partition key.  It stores year, month and day since I will be primarily accessing the table by date.  Normally I would use yyyymmdd because that is sortable, but it is wrong for a key value.  The value needs more change in it.  So ddmmyyyy is better.  Given the life of WiFi technology, the century value is wasted space, so the format is ddmmyy.
  • CreateTS – This is the sort key.  This is in the format yyyymmddhhmiss.
  • ExpirationEpochSecs – This is the time to live attribute.  This attribute has to be set as a value representing the number of seconds elapsed since 12:00:00 AM January 1st, 1970 UTC.  I set this value to 31 days in the future when creating a record.  When the 31 days elapses the value in this field will signal DynamoDB to automatically delete this record.  In other words, using this attribute, I can make sure I only store a month of data at any given time.
  • FromIP – Might be useful in the future, but stored mostly for security now.  I can use this value to see if my lambda function is being called by the wrong IP address.
  • WiredAliveInd – Received from the ASUS/Merlin router’s uptime script.  1 if ping is successful, 0 if it is not.
  • WiredHost – Received from the ASUS/Merlin router’s uptime script.  The host being checked to confirm the wired connection to the router is working.
  • Wireless24AliveInd – Received from the ASUS/Merlin router’s uptime script.  1 if ping is successful, 0 if it is not.
  • Wireless24Host – Received from the ASUS/Merlin router’s uptime script.  The host being checked to confirm the wireless 2.4 Ghz connection to the router is working.
  • Wireless5AliveInd – Received from the ASUS/Merlin router’s uptime script.  1 if ping is successful, 0 if it is not.
  • Wireless5Host – Received from the ASUS/Merlin router’s uptime script.  The host being checked to confirm the wireless 5 Ghz connection to the router is working.

The rest of the functionality is provided in separate posts about router script, a lambda function that collects data and a lambda function that creates the plots.