Introduction: Send Notifications to Your Phone From an ESP8266
In this instructable I'm going to show you how to send notifications to your phone from your ESP8266 when programing with Arduino IDE.
This can be very useful if you want the device to notify when a sensor is triggered (PIR motion sensor) or certain criteria for a sensor is met ( e.g. dropped below a certain temperature).
I'm going to show you two ways to do this, using Telegram messenger and IFTTT. Both of these methods are completely free to use.
Check out the video to see it in action and for a quick run through of what I'll go through in this instructable. The code and circuitry from the demo is on my github.
Step 1: Setting Up Telegram
Telegram is an instant messenger very like whatsapp.
One advantage it has over whatsapp is it allows you to create bots, which are programs that you can interact with in the chat application.
We'll be using the Universal Arduino Telegram Library which is available on the Arduino Library manager to send us a Telegram message. This library supports ESP8266 and Wifi-101 boards. (Telegram requires SSL so ethernet shields and older wifi shields will not work.)
To use the library the first thing you need to get is a Bot Token, to get this inside telegram search for "botfather" and type the "/newbot" command. Then follow the onscreen instructions for naming the bot. Botfather will return you a bot token that you will use with the library.
Bots can only message you if you've first started a conversation with the bot first, so click on the link to your bot in the message that botfather sent and click the "Start" button
So the bot knows where to send the message you are going to need to add your chat id to the sketch, this is your unique identifier on Telegram. The easiest way to get this is search for a bot called "myIdBot", press the start button and send the "/getid" command.
You should now have everything you need to use Telegram for notifications.
Step 2: Setting Up IFTTT
IFTTT (If This Then That) is a service that lets you perform actions based on triggers, for example send a tweet if you get an email with a certain title.
Luckily for us fans of the ESP8266, it's pretty simple to trigger an event directly from the ESP8266. We'll be using the Arduino IFTTT Maker Library which is also available on the Arduino Library manager. It supports the same boards as the Telegram library (ESP8266 and Wifi-101) and also requires SSL (so no ethernet shield).
To use this library, the first thing we will need to do is create a "recipe" on IFTTT.
The "this" part, or the trigger, should be configured to be the "Maker" service. Give the trigger a name (I used "button_pressed" in the video), you will need this when using the library.
You then need to configure the "that" part of the IFTTT. In the video I use the "Notification" event (which requires the IFTTT app on your phone), but you can choose anything you want (email, twitter, even your Phillips Hue lightbulb!). You'll see in library that you can pass up 3 parameters, these can be used when creating the message that recipe sends you.
Finally you need to get for the library is the Maker key from your account. Click on your account up the top right of the IFTTT website and click on "Services". Click on "Maker" and then "Settings". The Maker Key is the characters at the end of the URL (In the red box in the photo).
Step 3: Testing It Out
You should now be able run the example from this github page. The circuitry and parts list are in the ReadMe.
In the sketch, just fill in the:
- Telegram Bot Token
- Telegram Chat ID
- IFTTT Maker Key
- IFTTT Event Name
Both of these libraries require the ArduinoJson library to be installed, so make sure you grab that from the library manager too.
Hopefully you find this useful! If you have any questions please let me know.