Using IFTTT’s Maker channel, I could setup a Web Request receiver or if you prefer a simpler method, you could use Pushbullet. Then I configured my OpenWRT router to post to the receiver on startup.
I wanted to know how often my router reboots. Using OpenWRT router, I could configure my router to do something on startup. i.e. calling a web endpoint. With that, I could post a message to IFTTT via its Maker channel or post a message to Pushbullet API. I will explain the setup for both but and the choice is yours.
If you have not heard of IFTTT before. IFTTT stands for If-This-Then-That. In a nutshell, it chains a condition to an action.
The IFTTT Maker channel enables the creation of a HTTPS Web Request receiver. This receiver is secured by an authentication key so that others cannot post to it. Multiple receivers can be created with each for capturing a specific event. Each event can optionally include up to 3 values.
I am assuming that you can figure out how to signup for an account IFTTT and activate the Maker channel. Then you may want to follow these simple steps:
My Recipes
.Create a Recipe
.Maker
.Receive a web request
.OpenWRT_started
. I recommend replacing spaces with underscore or else you will need to substitute space with %20
later.IF Notifications
.{{EventName}} {{Value1}}
.To make a web request from OpenWRT, you must have curl
and ca-certificates
installed.
opkg update
opkg install curl
opkg install ca-certificates
Once you have the above installed, try out the Maker Web Request endpoint:
curl -X POST -H "Content-Type: application/json" -d '{"value1":"openwrt","value2":"'"$(/sbin/ifconfig pppoe-wan | grep 'inet addr' | cut -d: -f2 | awk '{print $1}')"'"}' https://maker.ifttt.com/trigger/OpenWRT_started/with/key/<key>
This command sends 2 values to IFTTT. The first is a constant string, “openwrt”. The second is the current WAN IP address. My WAN interface is named pppoe-wan
. You will need to substitute the name. Also, be sure to replace <key>
with your Maker key.
The output from the command above is:
Congratulations! You've fired the OpenWRT_started event
Check the Recipe Log and you should see Personal Recipe triggered
. You should be receiving a notification pushed to your phone in a minute if you have IF by IFTTT
installed.
If you prefer Pushbullet, go to Settings > Account > Access Tokens
. Click on Create Access Token
. Copy that token.
To post a message to Pushbullet from OpenWRT, you will need curl
and ca-certificates
installed. Scroll up for the instructions.
Then post a message to Pushbullet using:
curl --header 'Access-Token: <Access_Token>' \
--header 'Content-Type: application/json' \
--data-binary '{"body":"'"$(/sbin/ifconfig pppoe-wan | grep 'inet addr' | cut -d: -f2 | awk '{print $1}')"'","title":"OpenWRT started","type":"note"}' \
--request POST \
https://api.pushbullet.com/v2/pushes
Be sure to replace <Access_Token>
with your access token created earlier.
You should be receiving a notification via Pushbullet almost immediately.
Via OpenWRT LuCI, navigate to System > Startup
. Scroll to the bottom and add the the full curl ...
line into Local Startup
placing it above exit 0
. You may want to include a delay until internet connection is available before calling this command. i.e.:
# Wait until Internet connection is available
for i in {1..60}; do ping -c1 -W1 8.8.8.8 &> /dev/null && break; done
# Replace this line with the full curl command to IFTTT/Pushbullet
curl ...
exit 0
Finally, reboot your router to test it out.