Send Notifications to Your Phone From an ESP8266

64,106

305

46

About: 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 Arduino development after discovering the esp8266 chip, a WiFi enab...

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

Please note: since I wrote this guide IFTTT have updated the name of the Maker channel to "Webhook", it should work the exact same as before though!

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

Microcontroller Contest 2017

Participated in the
Microcontroller Contest 2017

4 People Made This Project!

Recommendations

  • Growing Beyond Earth Maker Contest

    Growing Beyond Earth Maker Contest
  • 1 Hour Challenge

    1 Hour Challenge
  • Classroom Science Contest

    Classroom Science Contest

46 Discussions

0
None
dfiddle

2 years ago

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

0
None
robomaniac

2 years ago

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!!

5 replies
0
None
witnessmenowrobomaniac

Reply 2 years ago

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!

0
None
robomaniacwitnessmenow

Reply 2 years ago

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

0
None
witnessmenowrobomaniac

Reply 2 years ago

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.

0
None
robomaniacwitnessmenow

Reply 2 years ago

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.

0
None
witnessmenowrobomaniac

Reply 2 years ago

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 :)

0
None
hasanetakiwa

Question 15 days ago

35/5000
I found a problem, why not connect with WiFi?
canot connect with WiFi.png
0
None
epiCS97

2 months ago

I've done it but sending the notifications doesn't work. Which versions of the libraries did you use?

2 replies
0
None
epiCS97epiCS97

Reply 2 months ago

Its working now. You need esp Libary in Version 2.4.2

0
None
SamikshaS3epiCS97

Reply 2 months ago

thank you so much for this!
Is there any way for it to work on version 2.5?

0
None
AnP29

Question 2 months ago on Step 3

How to i make many phone can get notifications from arduino

0
None
AntonioF36

Question 4 months ago

marks it sends, but in the bot it does not arrive
chatID has to be inserted with -? "-XXXXXXXXX"

not_send.jpg
0
None
AntonioF36

Question 4 months ago

who found the solution to these errors? Thanks for the attention:
Nel file incluso da C: \ Users \ Antonio \ Desktop \ Nuova cartella \ push-notifications-arduino-esp8266-master \ PushNotificaitonDemo \ PushNotificaitonDemo.ino: 16: 0:
C: \ Users \ Antonio \ Documents \ Arduino \ libraries \ arduino -ifttt-maker-master \ src / IFTTTMaker.h: 26: 0: avviso: "HOST" ridefinito [abilitato di default]
#define HOST "maker.ifttt.com"
^
Nel file incluso da C: \ Users \ Antonio \ Desktop \ Nuova cartella \ push-notifications-arduino-esp8266-master \ PushNotificaitonDemo \ PushNotificaitonDemo.ino: 15: 0:
C: \ Users \ Antonio \ Documents \ Arduino \ librerie \ Universal-Arduino-Telegram-Bot-master \ src / UniversalTelegramBot.h: 29: 0: nota: questa è la posizione della definizione precedente
#define HOST "api.telegram.org"
^
Nel file incluso da C: \ Users \ Antonio \ AppData \ Local \ Arduino15 \ packages \ esp8266 \ hardware \ esp8266 \ 2.0.0 \ libraries \ ESP8266WiFi \ src \ ESP8266WiFi.cpp: 30: 0:
C: \ Users \ Antonio \ AppData \ Local \ Arduino15 \ packages \ esp8266 \ hardware \ esp8266 \ 2.0.0 / tools / sdk / include / user_interface.h: 451: 43: errore: typedef 'freedom_outside_cb__t' è inizializzato (usa invece decltype)
typedef void (** freedom_outside_cb__t) (stato uint8);
^
C: \ Users \ Antonio \ AppData \ Local \ Arduino15 \ packages \ esp8266 \ hardware \ esp8266 \ 2.0.0 / tools / sdk / include / user_interface.h: 451: 43: errore: "stato" non è stato dichiarato in questo scopo
C: \ Users \ Antonio \ AppData \ Local \ Arduino15 \ packages \ esp8266 \ hardware \ esp8266 \ 2.0.0 / tools / sdk / include / user_interface.h: 452: 40: errore: 'freedom_outside_cb_t' non è stato dichiarato in questo ambito
int wifi_register_send_pkt_freedom_cb (freedom_outside_cb_t cb); void wifi_unregister_send_pkt_freedom__cb (void); int wifi_send_pkt_freedom (uint8 ** buf, int len, bool sys_seq);
^
exit status 1
Errore durante la compilazione per la scheda WeMos D1 mini.

errore esp8266.jpg
1 answer
0
None
RafaelN1

11 months ago

I have the follow error when I try to compile: If you can provide the versions of libraries used I'll appreciate.

Documents\Arduino\libraries\Universal-Arduino-Telegram-Bot-master\src\UniversalTelegramBot.cpp:706:31: error: 'keyboardBuffer' was not declared in this scope

replyMarkup["keyboard"] = keyboardBuffer.parseArray(keyboard);

3 replies
0
None
GugolRafaelN1

Reply 10 months ago

I have the same error with a similar project, I searched a lot on the internet but i couldn't find any helpful information. Did you find a solution?

Thanks

1
None
محمدا218Gugol

Reply 8 months ago

I got the same error but I solve it.

open Arduino IDE then > Sketch > Include library > Manage libraries

Search for ArduinoJson

if you already installed the beta version you need to downgrade it to version 5.13.2

this solve the problem for me

ArduinoJson.png
0
None
Gugolمحمدا218

Reply 8 months ago

It functioned! Thank you so much, you saved me.

Thanks

0
None
D6equj5

Question 1 year ago on Step 2

I can't find the "Maker" service or applet tingy in IFTTT - does your instructable not now work if things externally have changed?