ESP32: Send Pushover Notifications (Arduino IDE).

You need to pass the following specifications:

ESP32 Send Pushover Notifications Arduino IDE

You can likewise pass various other optional specifications:

For even more info concerning all the criteria, please.

Introducing Pushover

pushover logo

Finally, shut the HTTPS link using the end() technique:

This instance sends a notice in the setup() when the ESP32 first runs.

Learn more concerning the ESP32 with our resources:

Pushover Pricing

Thanks for reading.

Installing Pushover App

You must pass the complying with criteria:

You can also pass various other optional specifications:

Create Account Pushover App

For even more details regarding all the parameters, please.

Welcome to Pushover Creating an Account

Getting Pushover API Key and User Key

Continue reviewing the find out just how the code functions, or avoid to the.

We also set the message title on the complying with line:

After obtaining all the criteria in a JSON things, we convert it to a String so that we can send it in the body of the HTTP POST demand.

Pushover dashboard user key

Set a safe customer with the certification using the setCACert() approach:

Then, create an HTTPClient instance called https.

Finally, shut the HTTPS link making use of the end() method:

pushover create an application token

This instance sends out a notification in the setup() when the ESP32 initially runs.

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 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 (). 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 .

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

/*
  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 11/10/2031)
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";

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() {
  
}

How the Code Works

Continue reading the learn how the code works, or skip to the .

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

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

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

Learn more about HTTP POST requests with the ESP32:.

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.