Send Notifications to Your Phone From an ESP8266

90,014

319

53

Introduction: Send Notifications to Your Phone From an ESP8266

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 enable…

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

  • Make it Glow Contest

    Make it Glow Contest
  • First Time Author Contest

    First Time Author Contest
  • PCB Challenge

    PCB Challenge

53 Discussions

0
dfiddle
dfiddle

3 years ago

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

0
robomaniac
robomaniac

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

0
witnessmenow
witnessmenow

Reply 3 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
robomaniac
robomaniac

Reply 3 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
witnessmenow
witnessmenow

Reply 3 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
robomaniac
robomaniac

Reply 3 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
witnessmenow
witnessmenow

Reply 3 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
coxinha
coxinha

9 months ago

In all examples, I can see that the bot is being declared as a global variable. This requires the BOTtoken to be available very early in the boot sequence.

I am storing the BOTtoken in EEPROM and would like to have the bot defined during setup, while keeping its global scope.

Is it possible? (let me know if you need the code)

0
ClaudeG21
ClaudeG21

Question 9 months ago on Introduction

Congratulations! But if you just wanted to use Telegram Bot, what parts of the program should I use. I tried to remove the parts with IFTTT and the compilation was successful. But it does not work. Help me? Thank you

0
youjian
youjian

Question 11 months ago

Can someone tell me how to fix this error? Thank you in advance.





Arduino: 1.8.11 (Windows 10), Board: "NodeMCU 1.0 (ESP-12E Module), 80 MHz, Flash, Legacy (new can return nullptr), All SSL ciphers (most compatible), 4MB (FS:2MB OTA:~1019KB), 2, v2 Lower Memory, Disabled, None, Only Sketch, 115200"
C:\Users\ninja\OneDrive\Documents\Arduino\libraries\UniversalArduinoTelegramBot\src\UniversalTelegramBot.cpp:319:11: error: DynamicJsonBuffer is a class from ArduinoJson 5. Please see arduinojson.org/upgrade to learn how to upgrade your program to ArduinoJson version 6
DynamicJsonBuffer jsonBuffer;
^
C:\Users\ninja\OneDrive\Documents\Arduino\libraries\UniversalArduinoTelegramBot\src\UniversalTelegramBot.cpp:369:11: error: DynamicJsonBuffer is a class from ArduinoJson 5. Please see arduinojson.org/upgrade to learn how to upgrade your program to ArduinoJson version 6
DynamicJsonBuffer jsonBuffer;
^
C:\Users\ninja\OneDrive\Documents\Arduino\libraries\UniversalArduinoTelegramBot\src\UniversalTelegramBot.cpp:530:11: error: DynamicJsonBuffer is a class from ArduinoJson 5. Please see arduinojson.org/upgrade to learn how to upgrade your program to ArduinoJson version 6
DynamicJsonBuffer jsonBuffer;
^
C:\Users\ninja\OneDrive\Documents\Arduino\libraries\UniversalArduinoTelegramBot\src\UniversalTelegramBot.cpp:547:11: error: DynamicJsonBuffer is a class from ArduinoJson 5. Please see arduinojson.org/upgrade to learn how to upgrade your program to ArduinoJson version 6
DynamicJsonBuffer jsonBuffer;
^
C:\Users\ninja\OneDrive\Documents\Arduino\libraries\UniversalArduinoTelegramBot\src\UniversalTelegramBot.cpp:564:11: error: DynamicJsonBuffer is a class from ArduinoJson 5. Please see arduinojson.org/upgrade to learn how to upgrade your program to ArduinoJson version 6
DynamicJsonBuffer keyboardBuffer;
^
C:\Users\ninja\OneDrive\Documents\Arduino\libraries\UniversalArduinoTelegramBot\src\UniversalTelegramBot.cpp:589:11: error: DynamicJsonBuffer is a class from ArduinoJson 5. Please see arduinojson.org/upgrade to learn how to upgrade your program to ArduinoJson version 6
DynamicJsonBuffer jsonBuffer;
^
C:\Users\ninja\OneDrive\Documents\Arduino\libraries\UniversalArduinoTelegramBot\src\UniversalTelegramBot.cpp:601:11: error: DynamicJsonBuffer is a class from ArduinoJson 5. Please see arduinojson.org/upgrade to learn how to upgrade your program to ArduinoJson version 6
DynamicJsonBuffer keyboardBuffer;
^
C:\Users\ninja\OneDrive\Documents\Arduino\libraries\UniversalArduinoTelegramBot\src\UniversalTelegramBot.cpp:684:11: error: DynamicJsonBuffer is a class from ArduinoJson 5. Please see arduinojson.org/upgrade to learn how to upgrade your program to ArduinoJson version 6
DynamicJsonBuffer jsonBuffer;
^
C:\Users\ninja\OneDrive\Documents\Arduino\libraries\UniversalArduinoTelegramBot\src\UniversalTelegramBot.cpp:705:11: error: DynamicJsonBuffer is a class from ArduinoJson 5. Please see arduinojson.org/upgrade to learn how to upgrade your program to ArduinoJson version 6
DynamicJsonBuffer keyboardBuffer;
^
C:\Users\ninja\OneDrive\Documents\Arduino\libraries\UniversalArduinoTelegramBot\src\UniversalTelegramBot.cpp: In member function 'String UniversalTelegramBot::sendPostToTelegram(String, ArduinoJson::JsonObject&)':
C:\Users\ninja\OneDrive\Documents\Arduino\libraries\UniversalArduinoTelegramBot\src\UniversalTelegramBot.cpp:120:26: error: 'ArduinoJson::JsonObject' has no member named 'measureLength'
int length = payload.measureLength();
^
C:\Users\ninja\OneDrive\Documents\Arduino\libraries\UniversalArduinoTelegramBot\src\UniversalTelegramBot.cpp:128:13: error: 'ArduinoJson::JsonObject' has no member named 'printTo'
payload.printTo(out);
^
C:\Users\ninja\OneDrive\Documents\Arduino\libraries\UniversalArduinoTelegramBot\src\UniversalTelegramBot.cpp: In member function 'bool UniversalTelegramBot::getMe()':
C:\Users\ninja\OneDrive\Documents\Arduino\libraries\UniversalArduinoTelegramBot\src\UniversalTelegramBot.cpp:319:21: error: 'jsonBuffer' was not declared in this scope
DynamicJsonBuffer jsonBuffer;
^
C:\Users\ninja\OneDrive\Documents\Arduino\libraries\UniversalArduinoTelegramBot\src\UniversalTelegramBot.cpp:324:12: error: 'ArduinoJson::JsonObject' has no member named 'success'
if (root.success()) {
^
C:\Users\ninja\OneDrive\Documents\Arduino\libraries\UniversalArduinoTelegramBot\src\UniversalTelegramBot.cpp: In member function 'int UniversalTelegramBot::getUpdates(long int)':
C:\Users\ninja\OneDrive\Documents\Arduino\libraries\UniversalArduinoTelegramBot\src\UniversalTelegramBot.cpp:369:23: error: 'jsonBuffer' was not declared in this scope
DynamicJsonBuffer jsonBuffer;
^
C:\Users\ninja\OneDrive\Documents\Arduino\libraries\UniversalArduinoTelegramBot\src\UniversalTelegramBot.cpp:372:14: error: 'ArduinoJson::JsonObject' has no member named 'success'
if (root.success()) {
^
C:\Users\ninja\OneDrive\Documents\Arduino\libraries\UniversalArduinoTelegramBot\src\UniversalTelegramBot.cpp:382:50: error: invalid initialization of non-const reference of type 'ArduinoJson::JsonObject& {aka ArduinoJson6141_0000010::ObjectRef&}' from an rvalue of type 'ArduinoJson6141_0000010::ElementProxy<ArduinoJson6141_0000010::MemberProxy<ArduinoJson6141_0000010::ObjectRef, const char*> >'
JsonObject &result = root["result"][i];
^
C:\Users\ninja\OneDrive\Documents\Arduino\libraries\UniversalArduinoTelegramBot\src\UniversalTelegramBot.cpp: In member function 'bool UniversalTelegramBot::processResult(ArduinoJson::JsonObject&, int)':
C:\Users\ninja\OneDrive\Documents\Arduino\libraries\UniversalArduinoTelegramBot\src\UniversalTelegramBot.cpp:431:45: error: invalid initialization of non-const reference of type 'ArduinoJson::JsonObject& {aka ArduinoJson6141_0000010::ObjectRef&}' from an rvalue of type 'ArduinoJson6141_0000010::enable_if<true, ArduinoJson6141_0000010::MemberProxy<ArduinoJson6141_0000010::ObjectRef, const char*> >::type {aka ArduinoJson6141_0000010::MemberProxy<ArduinoJson6141_0000010::ObjectRef, const char*>}'
JsonObject &message = result["message"];
^
C:\Users\ninja\OneDrive\Documents\Arduino\libraries\UniversalArduinoTelegramBot\src\UniversalTelegramBot.cpp:451:50: error: invalid initialization of non-const reference of type 'ArduinoJson::JsonObject& {aka ArduinoJson6141_0000010::ObjectRef&}' from an rvalue of type 'ArduinoJson6141_0000010::enable_if<true, ArduinoJson6141_0000010::MemberProxy<ArduinoJson6141_0000010::ObjectRef, const char*> >::type {aka ArduinoJson6141_0000010::MemberProxy<ArduinoJson6141_0000010::ObjectRef, const char*>}'
JsonObject &message = result["channel_post"];
^
C:\Users\ninja\OneDrive\Documents\Arduino\libraries\UniversalArduinoTelegramBot\src\UniversalTelegramBot.cpp:460:52: error: invalid initialization of non-const reference of type 'ArduinoJson::JsonObject& {aka ArduinoJson6141_0000010::ObjectRef&}' from an rvalue of type 'ArduinoJson6141_0000010::enable_if<true, ArduinoJson6141_0000010::MemberProxy<ArduinoJson6141_0000010::ObjectRef, const char*> >::type {aka ArduinoJson6141_0000010::MemberProxy<ArduinoJson6141_0000010::ObjectRef, const char*>}'
JsonObject &message = result["callback_query"];
^
C:\Users\ninja\OneDrive\Documents\Arduino\libraries\UniversalArduinoTelegramBot\src\UniversalTelegramBot.cpp:472:52: error: invalid initialization of non-const reference of type 'ArduinoJson::JsonObject& {aka ArduinoJson6141_0000010::ObjectRef&}' from an rvalue of type 'ArduinoJson6141_0000010::enable_if<true, ArduinoJson6141_0000010::MemberProxy<ArduinoJson6141_0000010::ObjectRef, const char*> >::type {aka ArduinoJson6141_0000010::MemberProxy<ArduinoJson6141_0000010::ObjectRef, const char*>}'
JsonObject &message = result["edited_message"];
^
C:\Users\ninja\OneDrive\Documents\Arduino\libraries\UniversalArduinoTelegramBot\src\UniversalTelegramBot.cpp: In member function 'bool UniversalTelegramBot::sendMessage(String, String, String)':
C:\Users\ninja\OneDrive\Documents\Arduino\libraries\UniversalArduinoTelegramBot\src\UniversalTelegramBot.cpp:530:21: error: 'jsonBuffer' was not declared in this scope
DynamicJsonBuffer jsonBuffer;
^
C:\Users\ninja\OneDrive\Documents\Arduino\libraries\UniversalArduinoTelegramBot\src\UniversalTelegramBot.cpp: In member function 'bool UniversalTelegramBot::sendMessageWithReplyKeyboard(String, String, String, String, bool, bool, bool)':
C:\Users\ninja\OneDrive\Documents\Arduino\libraries\UniversalArduinoTelegramBot\src\UniversalTelegramBot.cpp:547:21: error: 'jsonBuffer' was not declared in this scope
DynamicJsonBuffer jsonBuffer;
^
C:\Users\ninja\OneDrive\Documents\Arduino\libraries\UniversalArduinoTelegramBot\src\UniversalTelegramBot.cpp:557:70: error: invalid initialization of non-const reference of type 'ArduinoJson::JsonObject& {aka ArduinoJson6141_0000010::ObjectRef&}' from an rvalue of type 'ArduinoJson6141_0000010::ObjectRef'
JsonObject &replyMarkup = payload.createNestedObject("reply_markup");
^
C:\Users\ninja\OneDrive\Documents\Arduino\libraries\UniversalArduinoTelegramBot\src\UniversalTelegramBot.cpp:564:21: error: 'keyboardBuffer' was not declared in this scope
DynamicJsonBuffer keyboardBuffer;
^
C:\Users\ninja\OneDrive\Documents\Arduino\libraries\UniversalArduinoTelegramBot\src\UniversalTelegramBot.cpp: In member function 'bool UniversalTelegramBot::sendMessageWithInlineKeyboard(String, String, String, String)':
C:\Users\ninja\OneDrive\Documents\Arduino\libraries\UniversalArduinoTelegramBot\src\UniversalTelegramBot.cpp:589:21: error: 'jsonBuffer' was not declared in this scope
DynamicJsonBuffer jsonBuffer;
^
C:\Users\ninja\OneDrive\Documents\Arduino\libraries\UniversalArduinoTelegramBot\src\UniversalTelegramBot.cpp:599:70: error: invalid initialization of non-const reference of type 'ArduinoJson::JsonObject& {aka ArduinoJson6141_0000010::ObjectRef&}' from an rvalue of type 'ArduinoJson6141_0000010::ObjectRef'
JsonObject &replyMarkup = payload.createNestedObject("reply_markup");
^
C:\Users\ninja\OneDrive\Documents\Arduino\libraries\UniversalArduinoTelegramBot\src\UniversalTelegramBot.cpp:601:21: error: 'keyboardBuffer' was not declared in this scope
DynamicJsonBuffer keyboardBuffer;
^
C:\Users\ninja\OneDrive\Documents\Arduino\libraries\UniversalArduinoTelegramBot\src\UniversalTelegramBot.cpp: In member function 'String UniversalTelegramBot::sendPhoto(String, String, String, bool, int, String)':
C:\Users\ninja\OneDrive\Documents\Arduino\libraries\UniversalArduinoTelegramBot\src\UniversalTelegramBot.cpp:684:21: error: 'jsonBuffer' was not declared in this scope
DynamicJsonBuffer jsonBuffer;
^
C:\Users\ninja\OneDrive\Documents\Arduino\libraries\UniversalArduinoTelegramBot\src\UniversalTelegramBot.cpp:703:72: error: invalid initialization of non-const reference of type 'ArduinoJson::JsonObject& {aka ArduinoJson6141_0000010::ObjectRef&}' from an rvalue of type 'ArduinoJson6141_0000010::ObjectRef'
JsonObject &replyMarkup = payload.createNestedObject("reply_markup");
^
C:\Users\ninja\OneDrive\Documents\Arduino\libraries\UniversalArduinoTelegramBot\src\UniversalTelegramBot.cpp:705:23: error: 'keyboardBuffer' was not declared in this scope
DynamicJsonBuffer keyboardBuffer;
^
Multiple libraries were found for "UniversalTelegramBot.h"
Used: C:\Users\ninja\OneDrive\Documents\Arduino\libraries\UniversalArduinoTelegramBot
Not used: C:\Users\ninja\OneDrive\Documents\Arduino\libraries\Universal-Arduino-Telegram-Bot-master
exit status 1
Error compiling for board NodeMCU 1.0 (ESP-12E Module).
This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

0
Borkodrvo
Borkodrvo

Answer 11 months ago

Try to instal the old version of the ArduinoJson Library. Find the ArduinoJson library in the "Library Manager" click on it and in dropdown menu "select version" should appear. Try selecting version 5.13.5

0
diy_bloke
diy_bloke

Question 1 year ago on Step 1

Maybe I misunderstand this section but how to go one then ("you now have everything you need to go on using telegram")??
Your sketch requires telegram id's AND IFTT tokens as I understand

0
hasanetakiwa
hasanetakiwa

Question 1 year ago

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

Answer 1 year ago

I have the same problem....

0
Daddys_Stare
Daddys_Stare

3 years ago

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.

0
diy_bloke
diy_bloke

Reply 1 year ago

That's what many apps do. It does that so it can interact with yr phone in order to work. Viber and WhatsApp do the same. Is Telegram the first app you ever install?

0
witnessmenow
witnessmenow

Reply 3 years ago

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.

0
epiCS97
epiCS97

1 year ago

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

0
epiCS97
epiCS97

Reply 1 year ago

Its working now. You need esp Libary in Version 2.4.2

0
SamikshaS3
SamikshaS3

Reply 1 year ago

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