ESP8266 NodeMCU: Send Pushover Notifications (Arduino IDE) | Random Nerd Tutorials (2023)

In this guide, you will learn how to send notifications from ESP8266 to Pushover. Pushover is a notification service that integrates with many apps. You can send push notifications to all your devices and multiple users. You can manage your notifications with priority levels, set silent hours and set different sounds depending on the notification.

ESP8266 NodeMCU: Send Pushover Notifications (Arduino IDE) | Random Nerd Tutorials (1)

Index

  • Introducing the Pushover app
  • Installing the Pushover app
  • Getting pushover API key and user key
  • Pushover Notifications with ESP8266 – Example Sketch (Arduino IDE)
  • Sending Pushover Notifications with the ESP8266 – Demo

New to ESP8266?Start Here: Introduction to the ESP8266 NodeMCU Development Board.

Introducing Pushover

ESP8266 NodeMCU: Send Pushover Notifications (Arduino IDE) | Random Nerd Tutorials (2)

Pushover is a desktop and mobile 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 apps.

You can receive notifications on all your devices simultaneously or send them to groups with multiple users. Plus, you can customize things like priority levels, set silent hours, and even different sounds depending on the type of notification.

pushover prices

Do you have an30 day free trial periodfrom the moment you register so you can experience the app. After that, if you want to continue using the app, just make a one-time purchase of $5. Each user can send up to 10,000 messages per month for free. learn more aboutpushover prices.

Installing the 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 on your smartphone and create an account to get started.

ESP8266 NodeMCU: Send Pushover Notifications (Arduino IDE) | Random Nerd Tutorials (3)

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

ESP8266 NodeMCU: Send Pushover Notifications (Arduino IDE) | Random Nerd Tutorials (4)

After that, you will need to access your email to verify your account.

Getting pushover API key and user key

To send pushover notifications with ESP8266, we need to get an API key and the user (receiver) key.

For this step, we recommend logging into your pushover account on your computer's browser. Between here:https://pushover.net/login.

You will have access to your Pushover dashboard.

ESP8266 NodeMCU: Send Pushover Notifications (Arduino IDE) | Random Nerd Tutorials (5)

In the upper right corner there is theuser key. Save because you'll need it later.

You can also see all your devices and add more devices if you want. You can try sending a notification in the top left corner to check if notifications are working with your device.

Scroll down the page to create an app/API token.

ESP8266 NodeMCU: Send Pushover Notifications (Arduino IDE) | Random Nerd Tutorials (6)

Give a name and description (optional) for the API Token. You can also add an icon to this. Added an icon of an ESP8266 board. So, when we receive a notification, it will be accompanied by the ESP8266 icon. Finally, build the application.

ESP8266 NodeMCU: Send Pushover Notifications (Arduino IDE) | Random Nerd Tutorials (7)

The application will now appear on your dashboard under theyour appssection.

ESP8266 NodeMCU: Send Pushover Notifications (Arduino IDE) | Random Nerd Tutorials (8)

Click on the app name to get its API token. From this menu, you can also check how many notifications you've sent with that API token.

Save the API token because you will need it later.

ESP8266 NodeMCU: Send Pushover Notifications (Arduino IDE) | Random Nerd Tutorials (9)

Now that you have your 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 simple thanks to its API.You can read the Pushover API documentation. You simply need to POST an HTTPS request with the ESP8266 with the correct parameters to the API endpoint:https://api.pushover.net/1/messages.json.

You must pass the following parameters:

  • symbol: Your app's API token
  • from the user: your user key or user group key
  • message: the content of the notification

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 from.
  • html: Set to 1 to enable HTML parsing.
  • priority: Set the notification priority level: a value of -2, -1, 0 (default), 1, or 2.
  • as: the name of a supported sound to override your default sound choice - values ​​can bepushover,bicycle,cornetim,cash register,classic,cosmic, etc (check all available sound options). You can even upload your own sounds to the Pushover panel.
  • timestamp: A Unix timestamp of a time to display instead of when our API received the request.
  • title: the title of your message, otherwise your app name will be used.
  • url: a supplementary URL to display with your message (documentation).
  • url_title: a title for the URL specified as the url parameter, otherwise only the URL is shown.

For more information about all parameters, pleasecheck the Pushover API documentation.

The code below shows how to send Pushover notifications with the ESP8266 using an HTTPS POST request.

Before sending the code to your board, you need to enter your SSID and password,the user key and API token of the Pushover app.

/* Rui Santos Full project details at https://RandomNerdTutorials.com/esp8266-nodemcu-pushover-arduino/ Permission is granted, free of charge, to anyone who obtains a copy of this software and associated documentation files. The above copyright notice and this permission notice must be included in all copies or substantial portions of the Software.*/#include#include#include#includeconst 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 endpointconst char* pushoverApiEndpoint = "https:/ /api.pushover.net/1/messages.json";//Pushover root certificate (válido de 11/10/2006 a 11/10/2031)const char *PUSHOVER_ROOT_CA = "-----BEGIN CERTIFICATE--- --\n" "MIIDrzCCApegAwIBAgIQCDvgVpBCRrGhdWrJWZHHSjANBgkqhkiG9w0BAQUFADBh\n" "MQswCQYDVQQGEwJVUzEVMBMGA1UEChMMRGlnaUNlcnQgSW5jMRkwFwYDVQQLExB3\n" "d3cuZGlnaW NlcnQuY29tMSAwHgYDVQQDExdEaWdpQ2VydCBHbG9iYWwgUm9vdCBD\n" "QTAeFw0wNjExMTAwMDAwMDBaFw0zMTExMTAwMDAwMDBaMGExCzAJBgNVBAYTAlVT\n" "MRUwEwYDVQQKEwxEaWdpQ2Vyd CBJbmMxGTAXBgNVBAsTEHd3dy5kaWdpY2VydC5j\n" "b20xIDAeBgNVBAMTF0RpZ2lDZXJ0IEdsb2JhbCBSb290IENBMIIBIjANBgkqhkiG\n" "9w0BAQEFAAOCAQ8AMIIBCgKCAQEA4jvhEXLeqKTTo1eq UKKPC3eQyaKl7hLOllsB\n" "CSDMAZOnTjC3U/dDxGkAV53ijSLdhwZAAIEJzs4bg7/fzTtxRuLWZscFs3YnFo97\n" " nh6Vfe63SKMI2tavegw5BmV/Sl0fvBf4q77uKNd0f3p4mVmFaG5cIzJLv07A6Fpt\n" "43C/dxC//AH2hdmoRBBYMql1GNXRor5H4idq9Joz+EkIYIvUX7Q6hL+hqkpMfT7P\n" "T 19sdl6gSzeRntwi5m3OFBqOasv+zbMUZBfHWymeMr/y7vrTC0LUq7dBMtoM1O/4\n" "gdW7jVg/tRvoSSiicNoxBN33shbyTApOB6jtSj1etX+jkMOvJwIDAQABo2MwYTAO\n" "BgNVHQ8BAf8EBA MCAYYwDwYDVR0TAQH/BAUwAwEB/zAdBgNVHQ4EFgQUA95QNVbR\n" " TLtm8KPiGxvDl7I90VUwHwYDVR0jBBgwFoAUA95QNVbRTLtm8KPiGxvDl7I90VUw\n" "DQYJKoZIhvcNAQEFBQADggEBAMucN6pIExIK+t1EnE9SsPTfrgT1eXkIoyQY/Esr\n" "hMA tudXH/vTBH1jLuG2cenTnmCmrEbXjcKChzUyImZOMkXDiqw8cvpOp/2PV5Adg\n" "06O/nVsJ8dWO41P0jmP6P6fbtGbfYmbW0W5BjfIttep3Sp+dWOIrWcBAI+0tKIJF\n" "PnlU kiaY4IBIqDfv8NZ5YBberOgOzW6sRBc4L0na4UU+Krk2U886UAb3LujEV0ls\n" "YSEY1QSteDwsOoBrp+uvFRTp2InBuThs4pFsiv9kuXclVzDAGySj4dzp30d8tbQk\n" "CAUw7C29C79Fv 1C5qfPrmAESrciIxpg0X40KPMbp1ZWVbd4= \n" "-----END CERTIFICATE-----\n";// Cria uma lista de certificados com o servidor certificateX509List cert(PUSHOVER_ROOT_CA);void setup() { Serial.begin(115200); WiFi.begin(ssid, senha); while (WiFi.status() != WL_CONNECTED) { delay(1000); Serial.println("Conectando ao WiFi..."); } Serial.println("Conectado ao WiFi"); // Definir hora via NTP, conforme necessário para validação x.509 configTime(3 * 3600, 0, "pool.ntp.org", "time.nist.gov"); Serial.print("Aguardando sincronização de horário NTP: "); time_t agora = time(nullptr); while (agora < 8 * 3600 * 2) { delay(500); Serial.print("."); agora = hora(nullptr); } Serial.println(""); struct tm timeinfo; gmtime_r(&agora, &timeinfo); Serial.print("Hora atual: "); Serial.print(asctime(&timeinfo)); //Faça solicitação HTTPS POST para enviar notificação if (WiFi.status() == WL_CONNECTED) { // Crie um objeto JSON com detalhes de notificação // Verifique os parâmetros da API: https://pushover.net/api StaticJsonDocument<512> notificação; notificação["token"] = apiToken; notificação["usuário"] = userToken; notification["message"] = "Olá do ESP8266"; notification["title"] = "Notificação do ESP8266"; notificação["url"] = ""; notificação["url_title"] = ""; notificação["html"] = ""; notificação["prioridade"] = ""; notificação["som"] = "cósmico"; notificação["timestamp"] = ""; // Serializa o objeto JSON para uma string String jsonStringNotification; serializeJson(notificação, jsonStringNotificação); // Cria um objeto WiFiClientSecure Cliente WiFiClientSecure; // Definir o certificado client.setTrustAnchors(&cert); // Cria um objeto HTTPClient HTTPClient http; // Especifique a URL de destino http.begin(client, pushoverApiEndpoint); // Adicionar cabeçalhos http.addHeader("Content-Type", "application/json"); // Envia a solicitação POST com os dados JSON int httpResponseCode = http.POST(jsonStringNotification); // Verifica a resposta if (httpResponseCode > 0) { Serial.printf("Código de resposta HTTP: %d\n", httpResponseCode); String resposta = http.getString(); Serial.println("Resposta:"); Serial.println(resposta); } else { Serial.printf("Código de resposta HTTP: %d\n", httpResponseCode); } // Fecha a conexão http.end(); }}ciclo vazio() { }

see raw code

How the code works

Read on to learn how the code works, or skip ahead to thedemo section.

include libraries

You start by including the necessary libraries. OESP8266WiFilibrary to connect the ESP8266 to your network so that it can connect to the internet. OESP8266HTTPClienteWiFiClientSecurelibraries will be used to make secure HTTP POST requests, and we will use theArduinoJSONlibrary to create a JSON string to send all the necessary parameters in the body of the HTTP POST request.

#include#include#include#include

network credentials

Insert your network credentials into 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 into the following variables:

const char* apiToken = "API_TOKEN";const char* userToken = "USER_TOKEN";

API endpoint

Next, we define the URL of the API endpoint where we will 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 site's TLS certificate. We are using root certificate. It is valid until 2031. To know how to get a website's TLS certificate, you can read this:Getting a server certificate using Google Chrome.

const char *PUSHOVER_ROOT_CA = "-----BEGIN CERTIFICATE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ImZOMkXDiqw8cvpOp/2PV5Adg\n" "06O/nVsJ8dWO41P0jmP6P6fbtGbfYmbW0W5BjfIttep3Sp+dWOIrWcBAI+0tKIJF\n" " PnlUkiaY4IBIqDfv8NZ5YBberOgOzW6sRBc4L0na4UU+Krk2U886UAb3LujEV0ls\n" "YSEY1QSteDwsOoBrp+uvFRTp2InBuThs4pFsiv9kuXclVzDAGySj4dzp30d8tbQk\n" "CAUw7C29 C79Fv1C5qfPrmAESrciIxpg0X40KPMbp1ZWVbd4=\n" "-----END CERTIFICADO-----\n";

So, you need to create a list of certificatescertificate(even if you only have one certificate) with the server certificate you want to use:

// Create a list of certificates with the server certificateX509List cert(PUSHOVER_ROOT_CA);

Connect to WiFi

Noto set up(), start by connecting the ESP8266 to your network:

Serial.begin(115200);WiFi.begin(ssid, senha);while (WiFi.status() != WL_CONNECTED) { delay(1000); Serial.println("Conectando ao WiFi...");}Serial.println("Conectado ao WiFi");

Setting the time

You need to configure the time on the ESP8266, which is needed to validate the certificate.

// Definir hora via NTP, conforme necessário para x.509 validationconfigTime(3 * 3600, 0, "pool.ntp.org", "time.nist.gov");Serial.print("Waiting for NTP time sync: " );time_t agora = time(nullptr);while (agora < 8 * 3600 * 2) { atraso(500); Serial.print("."); now = time(nullptr);}Serial.println("");struct tm timeinfo;gmtime_r(&now, &timeinfo);Serial.print("Hora atual: ");Serial.print(asctime(&timeinfo));

Defining Notification Parameters

After verifying that we are connected to Wi-Fi, we create a JSON object callednotificationwith the required parameters and some of the optional parameters. Required parameters are API token, user token and message.

Notification StaticJsonDocument<512>; notification["token"] = apiToken; //requirednotification["user"] = userToken; //requirednotification["message"] = "Hello from ESP32"; //requirednotification["title"] = "ESP32 Notification"; //optionalnotification["url"] = ""; //optionalnotification["url_title"] = ""; //optionalnotification["html"] = ""; //optionalnotification["priority"] = ""; //optionalnotification["sound"] = "cosmic"; //optionalnotification["timestamp"] = ""; //optional

As you can see, the message is defined in the following line:

notification["message"] = "Hello from ESP8266"; //mandatory

You can change the message to whatever is useful for your application.

We also define the message title in the following line:

notification["title"] = "ESP8266 Notification"; //optional

After getting all the parameters into a JSON object, we convert it to a String so 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:HTTPS Requests NodeMCU ESP8266 (Arduino IDE).

Learn more about HTTP POST requests with the ESP8266:ESP8266 NodeMCU HTTP POST com Arduino IDE.

Create oneWiFiClientSecurenamed objectclient.

WiFiClientSecure Client;

Next, you need to tell which certificates the client can trust using thesetTrustAnchors()and passing the listcert certificate as an argument (in this case, we added only one certificate).

client.setTrustAnchors(&cert);

Then create aCliente HTTPcalled instancehttps.

HTTPCliente https;

initialize thehttpsclient on the specified host using theto start()method. In this case, we are making a request on the API endpoint.

https.begin(client, pushoverApiEndpoint);

Then add HTTP POST headers - we need to specify that we will send the data as a JSON string in the request body.

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

Finally, we can send the POST request with the JSON data.

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

After making the request, we can check the server's response. This is useful to know if the request was successful or if there were any issues with the request or with the request body. To get the response from the server, we simply need to use thegetString()method nothttpsobject.

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 thefim()method:

https.end();

This example sends a notification on theto set up()when the ESP8266 is run for the first time. Then thelink()it 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 on a regular basis, and many other possibilities in the fields of home automation and IoT.

demonstration

After entering the SSID, password, user key and API key, you can upload the code to your board.

After uploading, open Serial Monitor at a baud rate of 115200. Press the ES8266 RST button so that it starts executing code.

You should get a success message (response code: 200) on your serial monitor.

ESP8266 NodeMCU: Send Pushover Notifications (Arduino IDE) | Random Nerd Tutorials (10)

And you should get the notification on your smartphone.

ESP8266 NodeMCU: Send Pushover Notifications (Arduino IDE) | Random Nerd Tutorials (11)

You can click on the message to open it.

ESP8266 NodeMCU: Send Pushover Notifications (Arduino IDE) | Random Nerd Tutorials (12)

pushover settings

On your device, you can adjust your notification settings. Click the icon (…) in the upper right corner.

You will 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.

ESP8266 NodeMCU: Send Pushover Notifications (Arduino IDE) | Random Nerd Tutorials (13)

Packing

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 silent hours and even set different sounds depending on the incoming notification.

In this tutorial, you learned how to send ESP8266 notifications to Pushover using the Pushover API. Using the Pushover app is not free, but you do have a 30-day free trial. If you decide it's useful for your projects, you can access the app with a one-time payment fee of just 5$.

If you are using an ESP32 board, we have a similar tutorial:

  • Pushover notifications with ESP32

We hope you found this tutorial helpful.

We have other articles and projects showing how to send other forms of notification like email, WhatsApp and Telegram messages:

  • ESP8266 NodeMCU: Send messages to WhatsApp
  • NodeMCU ESP8266 Port Status Monitor with Telegram Notifications
  • ESP8266 NodeMCU Send Emails Using an SMTP Server: HTML, Text, and Attachments (Arduino)

We hope you find this tutorial helpful.

Learn more about the ESP8266 with our resources:

  • Home Automation with ESP8266
  • Create Web Servers with ESP32 and ESP8266
  • Firebase Web App com ESP32 e ESP8266
  • Free ESP8266 projects and tutorials

Thanks for reading.

Top Articles
Latest Posts
Article information

Author: Moshe Kshlerin

Last Updated: 05/16/2023

Views: 6172

Rating: 4.7 / 5 (57 voted)

Reviews: 80% of readers found this page helpful

Author information

Name: Moshe Kshlerin

Birthday: 1994-01-25

Address: Suite 609 315 Lupita Unions, Ronnieburgh, MI 62697

Phone: +2424755286529

Job: District Education Designer

Hobby: Yoga, Gunsmithing, Singing, 3D printing, Nordic skating, Soapmaking, Juggling

Introduction: My name is Moshe Kshlerin, I am a gleaming, attractive, outstanding, pleasant, delightful, outstanding, famous person who loves writing and wants to share my knowledge and understanding with you.