In this guide, you’ll learn how to send ESP8266 notifications to Pushover. Pushover is a notification service that integrates with many applications. You can send push notifications to all of your devices and multiple users. You can manage your notifications with levels of priority, set silent hours, and set different sounds depending on the notification.
Table of Contents
- Introducing Pushover App
- Installing Pushover App
- Getting Pushover API Key and User Key
- Pushover Notifications with the ESP8266 – Example Sketch (Arduino IDE)
- Sending Pushover Notifications with the ESP8266 – Demonstration
New to the ESP8266? Start here: Getting Started with ESP8266 NodeMCU Development Board.
Introducing Pushover
Pushover is a mobile and desktop app compatible with Android and iOS and Windows, MacOS, and Linux. It allows you to receive notifications from different sources and services and integrates with many applications.
You can receive notifications on all your devices simultaneously or send them to groups with multiple users. Additionally, you can customize things such as priority levels, set silent hours, and even different sounds depending on the type of notification.
Pushover Pricing
You have a free 30-day trial period from the time you register so that you can experiment with the app. After that, if you want to continue using the app, it’s just a one-time $5 USD purchase. Each user can send up to 10,000 messages per month for free. Learn more about Pushover pricing.
Installing Pushover App
You can install the Pushover app on your computer, tablet, and smartphone. It is compatible with Windows, MacOS, and Linux, and with Android and iOS.
Download the app into your smartphone and create an account to get started.
After creating your account, you’ll have a free 30-day trial period.
After that, you’ll need to go to your email to verify your account.
Getting Pushover API Key and User Key
To send notifications to Pushover with the ESP8266, we need to get an API key and the user (receiver) key.
For this step, we recommend logging in to your pushover account on your computer browser. Login here: https://pushover.net/login.
You’ll get access to your Pushover dashboard.
At the top right corner, there’s the User Key. Save it because you’ll need it later.
You can also see all your devices and add more devices if you want. You can try to Push a Notification at the top left corner to check if notifications are working with your device.
Scroll down the page to create an Application/API Token.
Give a name and description(optional) to the API Token. You can also add an icon to that. We added an icon of an ESP8266 board. So, when we receive a notification, it will be accompanied by the ESP8266 icon. Finally, create the application.
Now, the application will show up on your dashboard under the Your Applications section.
Click on the application name to get its API token. On that menu, you can also check how many notifications you have sent with that API token.
Save the API token because you’ll need it later.
Now that you have the user key and API token, you can start sending ESP8266 notifications with Pushover.
Pushover Notifications with the ESP8266 – Example Sketch
Sending Pushover notifications with the ESP8266 is very straightforward thanks to its API. You can read Pushover’s API documentation. You simply need to POST an HTTPS request with the ESP8266 with the right parameters to the API endpoint: https://api.pushover.net/1/messages.json.
You must pass the following parameters:
- token: your application’s API token
- user: your user key or user group key
- message: the notification content
You can also pass other optional parameters:
- attachment: an image attachment to send with the message.
- device: the name of the device you want to receive the notification.
- html: set to 1 to enable HTML parsing.
- priority: set the notification priority level: a value of -2, -1, 0 (default), 1, or 2.
- sound: the name of a supported sound to override your default sound choice—values can be pushover, bike, bugle, cashregister, classical, cosmic, etc (check all available sound options). You can even upload your own sounds to your Pushover dashboard.
- timestamp: a Unix timestamp of a time to display instead of when our API received the request.
- title: your message’s title, otherwise your app’s name is used.
- url: a supplementary URL to show with your message (documentation).
- url_title: a title for the URL specified as the url parameter, otherwise just the URL is shown.
For more information about all the parameters, please check Pushover’s API documentation.
The code below shows how to send Pushover notifications with the ESP8266 using an HTTPS POST request.
Before uploading the code to your board you need to insert your SSID and password, the user key, and Pushover App API token.
/*
Rui Santos
Complete project details at https://RandomNerdTutorials.com/esp8266-nodemcu-pushover-arduino/
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files.
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
*/
#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>
#include <WiFiClientSecure.h>
#include <ArduinoJson.h>
const char* ssid = "REPLACE_WITH_YOUR_SSID";
const char* password = "REPLACE_WITH_YOUR_PASSWORD";
const char* apiToken = "API_TOKEN";
const char* userToken = "USER_TOKEN";
//Pushover API endpoint
const char* pushoverApiEndpoint = "https://api.pushover.net/1/messages.json";
//Pushover root certificate (valid from 11/10/2006 to 15/01/2038)
const char *PUSHOVER_ROOT_CA = "-----BEGIN CERTIFICATE-----\n"
"MIIDjjCCAnagAwIBAgIQAzrx5qcRqaC7KGSxHQn65TANBgkqhkiG9w0BAQsFADBh\n"
"MQswCQYDVQQGEwJVUzEVMBMGA1UEChMMRGlnaUNlcnQg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n"
"8rGOmaFvE7FBcf6IKshPECBV1/MUReXgRPTqh5Uykw7+U0b6LJ3/iyK5S9kJRaTe\n"
"pLiaWN0bfVKfjllDiIGknibVb63dDcY3fe0Dkhvld1927jyNxF1WW6LZZm6zNTfl\n"
"MrY=\n"
"-----END CERTIFICATE-----\n";
// Create a list of certificates with the server certificate
X509List cert(PUSHOVER_ROOT_CA);
void setup() {
Serial.begin(115200);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.println("Connecting to WiFi...");
}
Serial.println("Connected to WiFi");
// Set time via NTP, as required for x.509 validation
configTime(3 * 3600, 0, "pool.ntp.org", "time.nist.gov");
Serial.print("Waiting for NTP time sync: ");
time_t now = time(nullptr);
while (now < 8 * 3600 * 2) {
delay(500);
Serial.print(".");
now = time(nullptr);
}
Serial.println("");
struct tm timeinfo;
gmtime_r(&now, &timeinfo);
Serial.print("Current time: ");
Serial.print(asctime(&timeinfo));
//Make HTTPS POST request to send notification
if (WiFi.status() == WL_CONNECTED) {
// Create a JSON object with notification details
// Check the API parameters: https://pushover.net/api
StaticJsonDocument<512> notification;
notification["token"] = apiToken;
notification["user"] = userToken;
notification["message"] = "Hello from ESP8266";
notification["title"] = "ESP8266 Notification";
notification["url"] = "";
notification["url_title"] = "";
notification["html"] = "";
notification["priority"] = "";
notification["sound"] = "cosmic";
notification["timestamp"] = "";
// Serialize the JSON object to a string
String jsonStringNotification;
serializeJson(notification, jsonStringNotification);
// Create a WiFiClientSecure object
WiFiClientSecure client;
// Set the certificate
client.setTrustAnchors(&cert);
// Create an HTTPClient object
HTTPClient http;
// Specify the target URL
http.begin(client, pushoverApiEndpoint);
// Add headers
http.addHeader("Content-Type", "application/json");
// Send the POST request with the JSON data
int httpResponseCode = http.POST(jsonStringNotification);
// Check the response
if (httpResponseCode > 0) {
Serial.printf("HTTP response code: %d\n", httpResponseCode);
String response = http.getString();
Serial.println("Response:");
Serial.println(response);
} else {
Serial.printf("HTTP response code: %d\n", httpResponseCode);
}
// Close the connection
http.end();
}
}
void loop() {
}
How the Code Works
Continue reading the learn how the code works, or skip to the demonstration section.
Include Libraries
You start by including the required libraries. The ESP8266WiFi library to connect the ESP8266 to your network, so that it can connect to the internet. The ESP8266HTTPClient and WiFiClientSecure libraries will be used to make secure HTTP POST requests, and we’ll use the ArduinoJSON library to create a JSON string to send all the required parameters on the body of the HTTP POST request.
#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>
#include <WiFiClientSecure.h>
#include <ArduinoJson.h>
Network Credentials
Insert your network credentials in the following variables.
const char* ssid = "REPLACE_WITH_YOUR_SSID";
const char* password = "REPLACE_WITH_YOUR_PASSWORD";
API Token and User Token
Insert the API token and user token on the following variables:
const char* apiToken = "API_TOKEN";
const char* userToken = "USER_TOKEN";
API Endpoint
Then, we set the API endpoint URL where we’ll make the requests. According to the documentation, it is as follows:
const char* pushoverApiEndpoint = "https://api.pushover.net/1/messages.json";
SSL Certificate
To make secure HTTPS requests, we need the pushover’s website TLS certificate. We’re using the root certificate. It is valid until 2038. To learn how to get a website’s TLS certificate, you can read this: Getting a Server’s Certificate using Google Chrome.
const char *PUSHOVER_ROOT_CA = "-----BEGIN CERTIFICATE-----\n"
"MIIDjjCCAnagAwIBAgIQAzrx5qcRqaC7KGSxHQn65TANBgkqhkiG9w0BAQsFADBh\n"
"MQswCQYDVQQGEwJVUzEVMBMGA1UEChMMRGlnaUNlcnQgSW5jMRkwFwYDVQQLExB3\n"
"d3cuZGlnaWNlcnQuY29tMSAwHgYDVQQDExdEaWdpQ2VydCBHbG9iYWwgUm9vdCBH\n"
"MjAeFw0xMzA4MDExMjAwMDBaFw0zODAxMTUxMjAwMDBaMGExCzAJBgNVBAYTAlVT\n"
"MRUwEwYDVQQKEwxEaWdpQ2VydCBJbmMxGTAXBgNVBAsTEHd3dy5kaWdpY2VydC5j\n"
"b20xIDAeBgNVBAMTF0RpZ2lDZXJ0IEdsb2JhbCBSb290IEcyMIIBIjANBgkqhkiG\n"
"9w0BAQEFAAOCAQ8AMIIBCgKCAQEAuzfNNNx7a8myaJCtSnX/RrohCgiN9RlUyfuI\n"
"2/Ou8jqJkTx65qsGGmvPrC3oXgkkRLpimn7Wo6h+4FR1IAWsULecYxpsMNzaHxmx\n"
"1x7e/dfgy5SDN67sH0NO3Xss0r0upS/kqbitOtSZpLYl6ZtrAGCSYP9PIUkY92eQ\n"
"q2EGnI/yuum06ZIya7XzV+hdG82MHauVBJVJ8zUtluNJbd134/tJS7SsVQepj5Wz\n"
"tCO7TG1F8PapspUwtP1MVYwnSlcUfIKdzXOS0xZKBgyMUNGPHgm+F6HmIcr9g+UQ\n"
"vIOlCsRnKPZzFBQ9RnbDhxSJITRNrw9FDKZJobq7nMWxM4MphQIDAQABo0IwQDAP\n"
"BgNVHRMBAf8EBTADAQH/MA4GA1UdDwEB/wQEAwIBhjAdBgNVHQ4EFgQUTiJUIBiV\n"
"5uNu5g/6+rkS7QYXjzkwDQYJKoZIhvcNAQELBQADggEBAGBnKJRvDkhj6zHd6mcY\n"
"1Yl9PMWLSn/pvtsrF9+wX3N3KjITOYFnQoQj8kVnNeyIv/iPsGEMNKSuIEyExtv4\n"
"NeF22d+mQrvHRAiGfzZ0JFrabA0UWTW98kndth/Jsw1HKj2ZL7tcu7XUIOGZX1NG\n"
"Fdtom/DzMNU+MeKNhJ7jitralj41E6Vf8PlwUHBHQRFXGU7Aj64GxJUTFy8bJZ91\n"
"8rGOmaFvE7FBcf6IKshPECBV1/MUReXgRPTqh5Uykw7+U0b6LJ3/iyK5S9kJRaTe\n"
"pLiaWN0bfVKfjllDiIGknibVb63dDcY3fe0Dkhvld1927jyNxF1WW6LZZm6zNTfl\n"
"MrY=\n"
"-----END CERTIFICATE-----\n";
Then, you need to create a list of certificates cert (even if you only have one certificate) with the server certificate you want to use:
// Create a list of certificates with the server certificate
X509List cert(PUSHOVER_ROOT_CA);
Connect to Wi-Fi
In the setup(), start by connecting the ESP8266 to your network:
Serial.begin(115200);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.println("Connecting to WiFi...");
}
Serial.println("Connected to WiFi");
Setting the Time
You need to configure the time on the ESP8266, which is necessary to validate the certificate.
// Set time via NTP, as required for x.509 validation
configTime(3 * 3600, 0, "pool.ntp.org", "time.nist.gov");
Serial.print("Waiting for NTP time sync: ");
time_t now = time(nullptr);
while (now < 8 * 3600 * 2) {
delay(500);
Serial.print(".");
now = time(nullptr);
}
Serial.println("");
struct tm timeinfo;
gmtime_r(&now, &timeinfo);
Serial.print("Current time: ");
Serial.print(asctime(&timeinfo));
Setting Notification Parameters
After making sure we are connected to Wi-Fi, we create a JSON object called notification with the required parameters and some of the optional parameters. The required parameters are the API token, user token and the message.
StaticJsonDocument<512> notification;
notification["token"] = apiToken; //required
notification["user"] = userToken; //required
notification["message"] = "Hello from ESP32"; //required
notification["title"] = "ESP32 Notification"; //optional
notification["url"] = ""; //optional
notification["url_title"] = ""; //optional
notification["html"] = ""; //optional
notification["priority"] = ""; //optional
notification["sound"] = "cosmic"; //optional
notification["timestamp"] = ""; //optional
As you can see, the message is set on the following line:
notification["message"] = "Hello from ESP8266"; //required
You can change the message to whatever it’s useful for your application.
We also set the message title on the following line:
notification["title"] = "ESP8266 Notification"; //optional
After getting all the parameters in a JSON object, we convert it to a String so that we can send it in the body of the HTTP POST request.
String jsonStringNotification;
serializeJson(notification, jsonStringNotification);
HTTPS POST Request
Now, we can finally make the HTTPS POST request.
Learn more about secure HTTPS requests with the ESP8266: ESP8266 NodeMCU HTTPS Requests (Arduino IDE).
Learn more about HTTP POST requests with the ESP8266: ESP8266 NodeMCU HTTP POST with Arduino IDE.
Create a WiFiClientSecure object called client.
WiFiClientSecure client;
Then, you need to tell which certificates the client can trust using the setTrustAnchors() method and passing as an argument the certificate list cert (in this case, we only added one certificate).
client.setTrustAnchors(&cert);
Then, create an HTTPClient instance called https.
HTTPClient https;
Initialize the https client on the host specified using the begin() method. In this case, we’re making a request on the API endpoint.
https.begin(client, pushoverApiEndpoint);
Then, add the HTTP POST headers—we need to specify that we’re going to send the data as a JSON string in the request body.
// Add headers
https.addHeader("Content-Type", "application/json");
Finally, we can send the POST request with the JSON data.
// Send the POST request with the JSON data
int httpResponseCode = https.POST(jsonStringNotification);
After making the request, we can check the server response. This is useful to know if the request succeeded or if there were any problems during the request or with the request body. To get the server response, we simply need to use the getString() method on the https object.
if (httpResponseCode > 0) {
Serial.printf("HTTP response code: %d\n", httpResponseCode);
String response = https.getString();
Serial.println("Response:");
Serial.println(response);
} else {
Serial.printf("HTTP response code: %d\n", httpResponseCode);
}
Finally, close the HTTPS connection using the end() method:
https.end();
This example sends a notification in the setup() when the ESP8266 first runs. So, the loop() is empty. The idea is that you use this example in your own application. For example, to send a notification when motion is detected, when a sensor reading is above or below a certain threshold, to send sensor readings or GPIO states regularly, and many other possibilities in the home automation and IoT fields.
Demonstration
After inserting the SSID, password, user key, and API key, you can upload the code to your board.
After uploading, open the Serial Monitor at a baud rate of 115200. Press the ES8266 RST button so that it starts running the code.
You should get a success message (response code: 200) on your Serial Monitor.
And you should receive the notification on your smartphone.
You can click on the message to open it.
Pushover Settings
On your device, you can adjust the settings for your notifications. Click on the (…) icon at the top right corner.
You’ll get a page as shown below. You can set quiet hours and other settings like volume and sound for critical alerts, add custom sounds, and more.
Wrapping Up
Pushover is a notification service that you can use to receive notifications from different apps and services in the same place. You can manage your notifications in terms of priority, set silence hours, and even set different sounds depending on the notification received.
In this tutorial, you learned how to send ESP8266 notifications to Pushover using Pushover’s API. Using the Pushover app is not free, but you have a 30-day free trial. If you decide that it is useful for your projects, you can have access to the app with a one-time payment fee of just 5$.
If you’re using an ESP32 board, we have a similar tutorial:
We hope you found this tutorial useful.
We have other articles and projects showing how to send other notification methods like email, WhatsApp, and Telegram messages:
- ESP8266 NodeMCU: Send Messages to WhatsApp
- ESP8266 NodeMCU Door Status Monitor with Telegram Notifications
- ESP8266 NodeMCU Send Emails using an SMTP Server: HTML, Text, and Attachments (Arduino)
We hope you find this tutorial useful.
Learn more about the ESP8266 with our resources:
- Home Automation using ESP8266
- Build Web Servers with ESP32 and ESP8266
- Firebase Web App with ESP32 and ESP8266
- Free ESP8266 Projects and Tutorials
Thanks for reading.
I will certainly just pay for Pushover, it is a no-brainer, for 5$.
I currently use WhatsApp to warn me that the temperature is too low at a cabin I have. A big concern in the winter months.
The first improvement I see with Pushover compared to WhatsApp looks to be a custom audio tone when the notification arrives.
You have played around with it and have you come across any other improvements over WhatsApp and CallMeBot?
Hi.
As I mentioned in the tutorial, you can configure different tones for the notification, you can set silent hours, you can notify more than one user, you can have it on all your devices, etc…
You an try the free trial period to check if it is appropriate for your projects.
This app was very recommended by some of our readers, that’s why we decided to create this tutorial.
Regards,
Sara
Helllo
what is the memory requirement for addition in 8266, ?
Regards
Anis
Hi.
What do you mean?
Can you better describe your question?
Regards,
Sara
Hello
I made a temperature monitoring using 8266 and display oled 1inch, if I add a notification function, won’t it be too heavy for the 8266?
No. It should run just fine.
Regards,
Sara
Thank you
I will do according to your instructions, anyway, 1 API key for 1 device ?
Hi.
I think you can use the same API key for all devices.
Regards,
Sara
Hi, i used this example sketch and it worked great. However, round about 4 Feb 2024 it stopped working and gives http response of -1. I’m not sure but may it be something to do with the SSL cert used in the sketch. I have tried pasting new cert but get same -1 response.
Bill
Hi.
Yes, you’re right.
Thanks for letting us know.
Yes, the problem is with the certificate.
We updated the code with the new certificate.
The code should work now.
Regards,
Sara
The cert change was a problem for me, too. How often does it happen? Is there a way to get a notification that is going to happen? PS: you still have the old cert in the explanation section.
Hi.
This certificate is valid until 2038. But, Pushover might change their certificate whenever they want.
There might be a way to know when the certificate has changed, but I don’t know how to do that at the moment.
Regards,
Sara
Hello,
I’ve tried this sketch which works well “alone”.
I have integrated the code in another one already in place with http requests but it doesn’t work.
After many different approaches, it looks like it is not possible to manage both HTTP and HTTPS in the same sketch with the ESP8266.
Regards,
Romain