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:
- Click on this:
- Choose Webhooks as the service to be used:
- Click on Receive a web request:
- Enter an Event name:
- Click on that:
- Choose Google Sheets:
- Click on Add row to a spreadsheet.
- Customize the spreadsheet name, row format and folder path in Google Drive and Create action:
- 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.
- Get SSH access to your router.
- Create a new shell script in folder /usr/sbin:
- The shell script should look like this:
#!/bin/sh # 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 ip="$cell_ip"_"$public_ip" url="http://maker.ifttt.com/trigger/router_status/with/key/<your_ifttt_maker_key>?value1=$imei&value2=$rssi&value3=$ip" curl $url
- Make your script executable:
chmod 777 /usr/sbin/ifttt.sh
- 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:
This script can be automated via cron to make it run periodically.
- Add a new entry to the crontab:
- This file should look like this:
# Run the script /usr/sbin/ifttt.sh every 1 minute * * * * * /usr/sbin/ifttt.sh
- Restart the cron service:
After a while, your spreadsheet will look like this: