ESP32: Send Pushover Notifications (Arduino IDE)

In this guide, you’ll learn how to send ESP32 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.

ESP32 Send Pushover Notifications Arduino IDE

Table of Contents

New to the ESP32? Start here: Getting Started with the ESP32 Development Board.

Introducing Pushover

pushover logo

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.

After publishing this previous tutorial, we found that many of our readers were already using Pushover for other types of notifications. So, we thought it would be useful to know how to integrate Pushover with the ESP32 so that you have all your notifications in one place.

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

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.

Create Account Pushover App

After creating your account, you’ll have a free 30-day trial period.

Welcome to Pushover Creating an Account

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 ESP32, 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.

Pushover dashboard user key

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.

pushover create an application 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 ESP32. So, when we receive a notification, it will be accompanied by the ESP32 icon. Finally, create the application.

Pushover App Create an Application API Key

Now, the application will show up on your dashboard under the Your Applications section.

Application created on pushover app

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.

Get Pushover application API key

Now that you have the user key and API token, you can start sending ESP32 notifications with Pushover.

Pushover Notifications with the ESP32 – Example Sketch

Sending Pushover notifications with the ESP32 is very straightforward thanks to its API. You can read Pushover’s API documentation here. You simply need to POST an HTTPS request with the ESP32 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 here). 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 ESP32 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/esp32-pushover-notifications-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 <WiFi.h>
#include <HTTPClient.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"
                  "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";

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

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

    // Serialize the JSON object to a string
    String jsonStringNotification;
    serializeJson(notification, jsonStringNotification);

    // Create a WiFiClientSecure object
    WiFiClientSecure client;
    // Set the certificate
    client.setCACert(PUSHOVER_ROOT_CA);

    // Create an HTTPClient object
    HTTPClient https;

    // Specify the target URL
    https.begin(client, pushoverApiEndpoint);

    // Add headers
    https.addHeader("Content-Type", "application/json");

    // Send the POST request with the JSON data
    int httpResponseCode = https.POST(jsonStringNotification);

    // Check the response
    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);
    }

    // Close the connection
    https.end();
  }
}

void loop() {
  
}

View raw code

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 WiFi library to connect the ESP32 to your network, so that it can connect to the internet. The HTTPClient 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 <WiFi.h>
#include <HTTPClient.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 2031. 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"
                 "MIIDrzCCApegAwIBAgIQCDvgVpBCRrGhdWrJWZHHSjANBgkqhkiG9w0BAQUFADBh\n"
                 "MQswCQYDVQQGEwJVUzEVMBMGA1UEChMMRGlnaUNlcnQgSW5jMRkwFwYDVQQLExB3\n"
                 "d3cuZGlnaWNlcnQuY29tMSAwHgYDVQQDExdEaWdpQ2VydCBHbG9iYWwgUm9vdCBD\n"
                 "QTAeFw0wNjExMTAwMDAwMDBaFw0zMTExMTAwMDAwMDBaMGExCzAJBgNVBAYTAlVT\n"
                 "MRUwEwYDVQQKEwxEaWdpQ2VydCBJbmMxGTAXBgNVBAsTEHd3dy5kaWdpY2VydC5j\n"
                 "b20xIDAeBgNVBAMTF0RpZ2lDZXJ0IEdsb2JhbCBSb290IENBMIIBIjANBgkqhkiG\n"
                 "9w0BAQEFAAOCAQ8AMIIBCgKCAQEA4jvhEXLeqKTTo1eqUKKPC3eQyaKl7hLOllsB\n"
                 "CSDMAZOnTjC3U/dDxGkAV53ijSLdhwZAAIEJzs4bg7/fzTtxRuLWZscFs3YnFo97\n"
                 "nh6Vfe63SKMI2tavegw5BmV/Sl0fvBf4q77uKNd0f3p4mVmFaG5cIzJLv07A6Fpt\n"
                 "43C/dxC//AH2hdmoRBBYMql1GNXRor5H4idq9Joz+EkIYIvUX7Q6hL+hqkpMfT7P\n"
                 "T19sdl6gSzeRntwi5m3OFBqOasv+zbMUZBfHWymeMr/y7vrTC0LUq7dBMtoM1O/4\n"
                 "gdW7jVg/tRvoSSiicNoxBN33shbyTApOB6jtSj1etX+jkMOvJwIDAQABo2MwYTAO\n"
                 "BgNVHQ8BAf8EBAMCAYYwDwYDVR0TAQH/BAUwAwEB/zAdBgNVHQ4EFgQUA95QNVbR\n"
                 "TLtm8KPiGxvDl7I90VUwHwYDVR0jBBgwFoAUA95QNVbRTLtm8KPiGxvDl7I90VUw\n"
                 "DQYJKoZIhvcNAQEFBQADggEBAMucN6pIExIK+t1EnE9SsPTfrgT1eXkIoyQY/Esr\n"
                 "hMAtudXH/vTBH1jLuG2cenTnmCmrEbXjcKChzUyImZOMkXDiqw8cvpOp/2PV5Adg\n"
                 "06O/nVsJ8dWO41P0jmP6P6fbtGbfYmbW0W5BjfIttep3Sp+dWOIrWcBAI+0tKIJF\n"
                 "PnlUkiaY4IBIqDfv8NZ5YBberOgOzW6sRBc4L0na4UU+Krk2U886UAb3LujEV0ls\n"
                 "YSEY1QSteDwsOoBrp+uvFRTp2InBuThs4pFsiv9kuXclVzDAGySj4dzp30d8tbQk\n"
                 "CAUw7C29C79Fv1C5qfPrmAESrciIxpg0X40KPMbp1ZWVbd4=\n"
                 "-----END CERTIFICATE-----\n";

Connect to Wi-Fi

In the setup(), start by connecting the ESP32 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");

Learn more about ESP32 Wi-Fi functions: ESP32 Useful Wi-Fi Library Functions (Arduino IDE).

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 ESP32"; //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"] = "ESP32 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 ESP32: ESP32 HTTPS Requests (Arduino IDE).

Learn more about HTTP POST requests with the ESP32: ESP32 HTTP POST Requests.

Create a WiFiClientSecure object called client.

WiFiClientSecure client;

Set a secure client with the certificate using the setCACert() method:

client.setCACert(PUSHOVER_ROOT_CA);

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 ESP32 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 ESP32 RST button so that it starts running the code.

You should get a success message (response code: 200) on your Serial Monitor.

Send ESP32 Notifications to Pushover Serial Monitor Demonstration

And you should receive the notification on your smartphone.

ESP32 Notification Pushover App

You can click on the message to open it.

ESP32 Notification Pushover App

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.

pushover notifications settings

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 ESP32 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 ESP8266 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 and SMS:

We hope you find this tutorial useful.

Learn more about the ESP32 with our resources:

Thanks for reading.



Learn how to build a home automation system and we’ll cover the following main subjects: Node-RED, Node-RED Dashboard, Raspberry Pi, ESP32, ESP8266, MQTT, and InfluxDB database DOWNLOAD »
Learn how to build a home automation system and we’ll cover the following main subjects: Node-RED, Node-RED Dashboard, Raspberry Pi, ESP32, ESP8266, MQTT, and InfluxDB database DOWNLOAD »

Recommended Resources

Build a Home Automation System from Scratch » With Raspberry Pi, ESP8266, Arduino, and Node-RED.

Home Automation using ESP8266 eBook and video course » Build IoT and home automation projects.

Arduino Step-by-Step Projects » Build 25 Arduino projects with our course, even with no prior experience!

What to Read Next…


Enjoyed this project? Stay updated by subscribing our newsletter!

11 thoughts on “ESP32: Send Pushover Notifications (Arduino IDE)”

  1. Thanks for the tutorials.
    What would you suggest as the best way, instead of hard coding the WIFI credentials, have an option to input the WIFI info, and also a way to change it, not by coding.
    Thanks
    Al

    Reply
  2. Hello,
    Could you please elaborate on how you can replace the message notification shown in your example sketch (notification[“message”] = “Hello from ESP32”;) where it’s only raw text, by a variable like a temperature value that the ESP32 has retrieved in the loop section ?
    Can you replace it by something like:
    notification[“message”] = mytemperature;
    Thanks !

    Reply
    • Hi.
      Yes, you can do that.
      Or something like:
      notification[“message”] = “The temperature is” + String(mytemperature).c_str();
      Regards,
      Sara

      Reply
  3. Thank you Sara,
    Another question: is this sketch compatible with the use of WifiManager instead of using SSID/password ?

    Reply
  4. Thanks, this works great ! As does Pushover…its a bargain at $5 Onetime.

    One thing I have not been able to figure out is: Can additional people be notified, without them having a Pushover account ?

    Anyone know the answer to this ?

    Reply
    • Hi.
      I’m not sure if that’s possible.
      I think they need to have an account, but I’m not sure.
      It is better to contact pushover support to know how to proceed.
      Regards,
      Sara

      Reply
  5. The above certificate has been deprecated had to download and install new cert from website. As it is a remote system I was designing decided to use only http without the cert. had to modify the code below

    // Create a WiFiClientSecure object ***********not using secure commented out as hardcoded cert will expire on remote system
    //WiFiClientSecure client;
    // Set the certificate
    //client.setCACert(PUSHOVER_ROOT_CA);

    // Create an HTTPClient object
    HTTPClient https; // says https but at the moment only using http

    // Specify the target URL
    https.begin(pushoverApiEndpoint); // not using secure client

    Reply

Leave a Reply to LAUDE Cancel reply

Download Our Free eBooks and Resources

Get instant access to our FREE eBooks, Resources, and Exclusive Electronics Projects by entering your email address below.