Log router status to a Google Sheet using IFTTT

You are here:
Estimated reading time: 1 min

IF This Then That, also known as IFTTT is a web-based service to create chains of simple conditional statements, called applets. It allows to create custom webhooks and connect it to services such as Gmail, Google Drive, Twitter and many more. To follow this tutorial is needed to sign up for an account at ifttt.com.

Set up a new IFTTT webhook

Once you have an IFTTT account, you can check your personal key to receive web requests at https://ifttt.com/maker_webhooks.

Create a new applet from https://ifttt.com/create:

  1. Click on this:
  2. Choose Webhooks as the service to be used:
  3. Click on Receive a web request:
  4. Enter an Event name:
  5. Click on that:
  6. Choose Google Sheets:
  7. Click on Add row to a spreadsheet.
  8. Customize the spreadsheet name, row format and folder path in Google Drive and Create action:
  9. Click on Finish.

Create a shell script to make a web request to IFTTT

We will create a shell script to report the router’s IMEI, cellular signal strength and cellular IP address to IFTTT. Once IFTTT receives this request, a new row will be added to the Google spreadsheet allowing us to have a log of all this data.

  1. Get SSH access to your router.
  2. Create a new shell script in folder /usr/sbin:
    vim /usr/sbin/ifttt.sh
  3. The shell script should look like this:
    # Read router's IMEI
    imei=$(cat /tmp/sysinfo/imei)
    # Read cellular signal strength
    rssi=$(cat /tmp/sysinfo/sigstat)
    # Read IP address assigned by the cellular operator
    cell_ip=$(cat /tmp/sysinfo/gprsip)
    # Read true public IP address (via https://askubuntu.com/questions/95910/command-for-determining-my-public-ip)
    public_ip=$(curl -s checkip.dyndns.org | sed -e 's/.*Current IP Address: //' -e 's/<.*$//')
    # Combine $cell_ip and $public_ip in one field as only 3 values can be posted
    curl $url
  4. Make your script executable:
    chmod 777 /usr/sbin/ifttt.sh
  5. Run it!

If everything runs ok, you should see on the command line the following message “Congratulations! You’ve fired the router_status event”.

Also, in Google Drive you should have a new spreadsheet with filename IFTTT_Maker_Webhooks_Events and following content:

Automate it

This script can be automated via cron to make it run periodically.

  1. Add a new entry to the crontab:
    vim /etc/crontabs/root
  2. This file should look like this:
    # Run the script /usr/sbin/ifttt.sh every 1 minute
    * * * * * /usr/sbin/ifttt.sh
  3. Restart the cron service:
    /etc/init.d/cron restart

After a while, your spreadsheet will look like this:

Was this article helpful?
Dislike 0 1 of 1 found this article helpful.
Views: 238
Back to Top