Introduction: Send Notifications to Your Phone From an ESP8266

Hello Everyone!

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.

Brian

Comments

author
dfiddle made it! (author)2017-05-14

This is great work. I've used this as the core for multiple projects. Thank you!!

author
robomaniac made it! (author)2017-02-16

dude so sweet!!! I had this running within minutes!! Darn easy!

Using IFTTT, I send emails, notification and send data to google spreadsheet!

I am in the process to add this to machine in my workshop so I can send usage data to spreadsheet and I will do some graphs and understand when I need to do maintenance!

thanks a lot!!

author
witnessmenow made it! (author)witnessmenow2017-02-16

Hey, that sounds great!

Really good idea logging it to Google sheets, I was thinking before about seeing could I use the Google api to do it before but I haven't looked into yet.

Thanks a lot for your comment, really appreciate it. It's a Great feeling to see people using stuff that I've made!

author
robomaniac made it! (author)robomaniac2017-02-16

You could look into pushsafer.
https://www.pushsafer.com/

It's a service that let you customize notification, you can tell how many motor virbration you want, what sound to play, what icon, etc. It has lot of potential. It's free for a X amount of push per month.

it's basically PHP request, I tried and tried to make it work for the ESP8266 but no luck. It had to do with HTTPS no possible on arduino but Kevin (the guy behind pushsafer) change his side to do both HTTP and HTTPS.

my thread is here
http://www.appzer.de/forum/viewtopic.php?f=24&t=2729&sid=69465c80f2d333f8882a162d7b77483c

I you make it work, I will check your instructable :P

author
witnessmenow made it! (author)witnessmenow2017-02-17

Hey

I took a look at this last night. I didn't look through your link too much, but just went direct to pushsafers website

ESP8266 can do https, both of the libraries in this instructable talk https to their endpoints.

I spent some time making a library to talk with pushsafer, but I haven't got it working yet, but it should be close! (It was late and I needed to go to bed!)

https://github.com/witnessmenow/pushsafer-arduino-...

I'll spend a few minutes on it tonight and see can I get it working. It needs to be tidied up a bit, but the example attempts to make a request to pushsafer with the configured inputs

They have examples for arduino on their website, but it doesn't even compile (trying to call length() on an int for example) so I didn't think there was much value in basing the code on their example.

author
robomaniac made it! (author)robomaniac2017-02-17

hey!

I tried your code did not work. I made an issue on github.

Regarding the code not compiling (trying to call length()) is what I posted in the forum. I will keep checking github.

author
witnessmenow made it! (author)witnessmenow2017-02-17

Hey, I took a look into this for you.

Esp8266 can do https, both these libraries use it.

Here is a library I created to work with pushsafer

https://github.com/witnessmenow/pushsafer-arduino-...

It does work, It can send notifications ok, but for some reason the response is not received back on the ESP8266, not too sure what is wrong (maybe I'm not waiting long enough for it, pushsafer doesn't seem as fast to respond as Telegram when I was testing with curl).

Pushsafers Arduino example on their website is trying to use length() methods on ints so I dont think they tested it very well :)

author
ElioM2 made it! (author)2017-05-03

Very ineresting, but I had this error in compilation. Can you help me?

Thank you.

Quote:

Arduino:1.8.1 (Windows 7), Scheda:"WeMos D1 R2 & mini, 80 MHz, 921600, 4M (3M SPIFFS)"

C:\Users\Elio\Desktop\push-notifications-arduino-esp8266-master\push-notifications-arduino-esp8266-master\PushNotificaitonDemo\PushNotificaitonDemo.ino: In function 'void sendTelegramMessage()':

PushNotificaitonDemo:116: error: invalid operands of types 'const char [7]' and 'char [9]' to binary 'operator+'

String message = "SSID: " + ssid + "\n"

^

PushNotificaitonDemo:121: error: expected ',' or ';' before 'telegramButtonPressedFlag'

telegramButtonPressedFlag = false;

^

exit status 1

invalid operands of types 'const char [7]' and 'char [9]' to binary 'operator+'

Questo report potrebbe essere più ricco di informazioni abilitando l'opzione

"Mostra un output dettagliato durante la compilazione"

in "File -> Impostazioni"

Immagine.png
author
hemanth kumar reddy made it! (author)2017-03-14

Can you plz look at this

https://www.instructables.com/community/security-s...

small help thanks

author
CarterKoopa made it! (author)2017-02-17

I'm getting an error whenever I try to compile the code. The error is: invalid operands of types const char to binary 'operator+'. Any ideas? I have only eidited the SSID, Password, and keys.

author
witnessmenow made it! (author)witnessmenow2017-02-18

Hey, which board are you using?

The error seems to relate to trying to add (+) on different types of strings.

Have yo added a new serial print that prints the tokens?

author
CarterKoopa made it! (author)CarterKoopa2017-02-18

I'm using a generic ESP8266 with an Arduino Uno? Do I need a specific board?

author
CarterKoopa made it! (author)CarterKoopa2017-02-18

I haven't changed anything else in the project either. The line with the error is:

String message = "SSID: " + ssid + "\n"

Thanks!

author
macsito07 made it! (author)macsito072017-02-21

i'm having the same problem. please help!!!

2017-02-22_12h28_44.jpg
author
witnessmenow made it! (author)witnessmenow2017-02-21

I'd say we must be using different versions of the arduino ide. Try changing it to

"ssid: " + String(ssid) + "\n"

I've a feeling you'll need to do the same on the next line with ipAdress

author
macsito07 made it! (author)macsito072017-02-22

now the error is on the next line

message = message + "IP: " + String(ipAddress) + "\n"

i also tried using other version of IDE but it shows the same error.

2017-02-22_16h49_36.jpg
author
witnessmenow made it! (author)witnessmenow2017-02-25

A commenter on youtube made this change when they were having the same issue and it works for them

39843202b22e4bb49ef7115c3cf02cd1.png
author
witnessmenow made it! (author)witnessmenow2017-02-21

You will need to program the esp8266 rather than using at codes with.

This video should hopefully explain how to program the esp8266 with an uno

https://youtu.be/P_ecAFpUADU

author
DanielC752 made it! (author)2017-02-21

Worked like a charm! Do you have any code for this application with a PIR? Tried myself, but it just keeps sending notifications constantly... :)

author
witnessmenow made it! (author)witnessmenow2017-02-21

Hey Daniel,

Glad it worked for you!

I've ordered some PIR sensors, but they are on the slow boat from China so I haven't played around with any yet. As far as i know most PIR sensors have a couple of adjustments you can make to them to the change how often they trigger, it might be worth looking into that, here is a pretty good link describing it

You could also cool down timer in your code, that it wouldn't set the flag unless a certain amount of time had past.

author
Daddys_Stare made it! (author)2017-02-19

I dont know about using Telrgram. First thing it wants to do is take over and manage calls and SMS duties of my phone. Bit of a security risk there.

author
witnessmenow made it! (author)witnessmenow2017-02-20

Hey, I've it installed for the last couple of years or so don't really remember the setup process. If your talking about the permission to read SMS, I think that's used at verification. I'd imagine what's app has the same permissions.

The IFTTT method should allow you to raise notifications without installing anything new (if you use email for example) so hopefully that works out for you.

author
Pavan. made it! (author)2017-02-13

Can anyone help me to fix range of esp8266 since I am new to this I dono how to do it

author
Pavan. made it! (author)Pavan.2017-02-14

I am doing small project by using ESP8266 , project is all about displaying the messages to LCD by using android app. Project is successful completed But the Wi-Fi connectivity range is very less about 10feet , I tried by connecting attena but of no use so kindly give me an idea to fix this problem . I had seen so many videos in YouTube but I am not getting proper solution, And also by using IOT they controlled esp8266 can you pls help me to understand the concept of IOT(internet of things ) to configure of esp8266.

author
witnessmenow made it! (author)witnessmenow2017-02-14

oh, that's not good! What board are you using?

Any esp8266 chips I've had and decent WiFi range, not sure how long but it has never been an issue (definitely more than 10 feet). Do you have it in a metal case or near something metal (like a battery)?

If you look at my video on telegram it talks about sending commands to your device, you could use that communicate both ways with your esp8266

https://www.youtube.com/watch?v=wP2J5BaQIWs

author
witnessmenow made it! (author)witnessmenow2017-02-13

Hi Pavan, I'm sorry I don't understand your question, what's the problem you are having?

author
JeromeC6 made it! (author)2017-02-13

can I use esp32 instead of esp8266?

author
witnessmenow made it! (author)witnessmenow2017-02-13

I've never tested as i don't have a board! The libraries work by passing in a HTTPS client in to them, just looking at the arduino core for esp32 it looks like there is some issues with WifiClientSecure.

There was a PR raised to fix it yesterday, so hopefully it's close!

https://github.com/espressif/arduino-esp32/pull/20...

If it works for you please do let me know

author
eermiyaev made it! (author)2017-02-13

Спасибо. Кстати, ты палишься с закладками спидов :)

author
DIY Hacks and How Tos made it! (author)2017-02-12

Good idea. This gives me a lot of ideas for projects that could use this.

author
witnessmenow made it! (author)witnessmenow2017-02-12

Hey, thanks for your message. Glad it was useful for you!

About This Instructable

20,659views

268favorites

License:

Bio: Hey everyone! My name is Brian and thanks for checking my Instructables. I'm a software developer by trade but I've recently gotten into ... More »
More by witnessmenow:Using Witnessmenow's ESP8266/Arduino LibrariesArduino Commute CheckerSocial Stats Counter
Add instructable to: