Send Notifications to Your Phone From an ESP8266

43,206

290

35

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

2 People Made This Project!

Recommendations

  • Fix It! Contest

    Fix It! Contest
  • Tiny Home Contest

    Tiny Home Contest
  • Creative Misuse Contest

    Creative Misuse Contest

35 Discussions

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

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

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!

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

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.

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.

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

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

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

1 more answer

I beilieve they have updated the name of the maker channel to be "webhook" it should work the exact same.

Whenever I go into IFTTT it asks me if I want to "Partner" and for me to get in contact with them - nothing about configuring the new applet - is IFTTT broken?

"getid" doesn't work - how do I get the id thing?

At IFTTT, the name is updated, search for Webhook! Maker is gone.

I had the same problem as ElioM2 with the error with the string message: String message = "SSID: " + ssid + "\n"

I resolved this problem with:

String message1 = "SSID: ";

String message2 = ssid;

String message = message1 + message2 + "\n";

The problem that I am having is the following "if" statement is not executing:

if(bot.sendMessage(CHAT_ID, message, "Markdown")){

Serial.println("TELEGRAM Successfully sent");

}

telegramButtonPressedFlag = false;

}

I am not getting the "TELEGRAM Successfully sent message nor am I receiving a notification from Telegram. My guess is that it has something to do with the UniversalTelegramBot.h library. When the code compiles, the message states: UniversalTelegramBot (legacy). I am trying to use the ESP8266-01 with GP02 to monitor a push button for Telegram only.

5 replies

Yeah there seems to be a missing semi colon in my example :/ , I will update it later

I was using Telegram on an ESP8266-01 yesterday so it does work on the board.

A couple of things to check.


Did you populate the CHAT_ID with your ID? Is your bot token set?

Another thing to check is make sure you open your bot and click start before you can send it a message

The ID is the 9 digit number obtained by using /getid and the bot token is the alpha numeric token for the HTTP API: nnnnnnnnn:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

(9 numeric digits:35 alphanumeric digits)?

If so, then yes, my CHAT_ID is populated with my ID and my bot token is set. I am using a Serial.print statements to to follow the execution of the sketch in the serial monitor. I have placed a Serial.print the line before the "IF" statement and the next line after it. I know that SendTelegramMessage function is being called. For some reason, the "IF" statement is not executing. My bot is started, but before I would be sent a message, I should get something printed via the serial monitor to illustrate that the if statement is executing. I am at a loss on what to do next?

The best way to see whats going on would be to enable debugging.

If you search in your arduino folder for this file: "UniversalTelegramBot.h" and change the _debug flag to be true and build your sketch again, the library should print more to the serial then, including responses.

Sorry, I need to make it easier to enable debugging! Please post back here if that reveals anything.

Turns out the ESP8266-01 that I was using, was operating erratically. A new ESP8266-01 and all is well!

One question on your example circuit. Why did you choose to have the inputs to trigger the interrupt(s) pulled down and sense on RISING? The device will not boot up without moving the GPIO2 input from LOW to HIGH and back again. In other words, why not pull GPIO2 UP and sense on FALLING? The ESP8266 would then boot up without operator intervention.

Thanks for the tip above. I am going to try that. Thanks again all of your help.

Hi Berndu86,

Good to hear!

Honestly I can't remember why I did it that way, I wrote that code for a project over a year ago and I just brought it into this example. I also don't use the ESP8266-01 too often so I'm not too familiar with it. It's a good tip that some people might run into issues with it.

0
None
ElioM2

1 year ago

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