How to Send a Push Notification to Your Phone With the Press of a Button

by netsnettok in Circuits > Arduino

1221 Views, 1 Favorites, 0 Comments

How to Send a Push Notification to Your Phone With the Press of a Button

Screenshot_20221027-001921_Discord.jpg

Tutorial on how to send push notifications to your smartphone by pressing a push button. This tutorial uses the services of Pushingbox and Pushbullet.

Supplies

d1ac41441237a479940062b5a8135e68.png
Push-Button-Switch.jpg
fb4550b893e7d6b5ff5543027447b51e.png

Hardware

Software & Websites

  • Arduino IDE (with ESP8266 Library installed) | link
  • Pushingbox | link
  • Pushbullet website | link
  • Pushbullet app | link

Connect Pushbutton to ESP8266 NodeMCU

Connect the Pushbutton to the ESP8266 NodeMCU and to your computer.

Check to See If the Button Works

798d315e415d3ef2438ffa73cb4b37ae.png

Open Arduino IDE.

Go to File > Examples > 01.Basics > DigitalReadSerial

Be sure to change the int Pushbutton to the correct pin. In my case, it was on D0.

int pushButton = D0;

Also make sure the amount of baud matches up with your serial monitor. I set mine to 115200 baud.

 Serial.begin(115200);

Upload your code and open the Serial Monitor. If you press the button and you see 0's appear, your button works!

Setting Up Pushingbox

4cde13a95504ba11024c7f350b59fb56.png

Go to the Pushingbox website and create an account.

After creating an account you will see the dashboard. In the menu bar, select My Services.

Adding a Service

95d27ec69a79459824657cb6342313ab.png

Click on the Add a service button and select Pushbullet service. Give your service a fitting name.

Now it asks us to fill in an Acces token, but we don't have one yet.

Getting the Acces Token

39fabb23b2a970130dca5611389b5892.png

Go to Pushbullet.com and create an account. After creating an account, go to Settings and click on Generate acces key. You now have your Acces key.

Switch back to the Pushingbox website and fill it in the form. Click on Submit.

Create a Scenario on Pushingbox

5c18c905b99ae38d77559ccdc7f4024c.png

On the menu bar, click on My Scenarios. Think up a name for your scenario and click on Add.

Adding an Action

5554bbda4889add6a7b8b69b95a2a838.png

Click on Add an action. Select the service you just made and think up a title and the message you want to send. Click on Submit.

Attempting to Set Up the Internet Connection in Arduino

I found this code from another tutorial from 2019 online and merged it with our working file in order to get the internet connection to work. However, the esp8266 just would not connect to the wifi.

Setting Up the Internet Connection in Arduino


After about an hour of troubleshooting I found this tutorial online which showed how to connect the esp8266 to wifi. I made a new file in Arduino IDE and pasted the code I found. Enter your wifi ssid and password.
#include "ESP8266WiFi.h"


const char* ssid = "ssid"; //Enter SSID

const char* password = "password"; //Enter Password


void setup(void)

{

Serial.begin(115200);

// Connect to WiFi

WiFi.begin(ssid, password);

while (WiFi.status() != WL_CONNECTED)

{

delay(500);

Serial.print("*");

}


Serial.println("");

Serial.println("WiFi connection Successful");

Serial.print("The IP Address of ESP8266 Module is: ");

Serial.print(WiFi.localIP());// Print the IP address

}


void loop()

{

// EMPTY

}

Upload the code and open the Serial Monitor. It should be connected now.

Connect to Pushingbox

Add the following code underneath your wifi password. Be sure to add the device id from Pushingbox. You can find your device id on the Pushingbox website under My scenarios.

const char* host = "api.pushingbox.com";
const char* devid = "DEV ID HERE";


int pushButton = D0;
int value = 0;

Add the following code into your void loop(). This code will make sure the information is sent towards Pushingbot.

int buttonState = digitalRead(pushButton);  
    delay(5000);
    value = digitalRead(pushButton);


    if(value = 1){  //value from sensor


    Serial.print("connecting to ");
    Serial.println(host);


    // Use WiFiClient class to create TCP connections
    WiFiClient client;
    const int httpPort = 80;
    if (!client.connect(host, httpPort)) {
        Serial.println("connection failed");
        return;
    }


    // We now create a URI for the request
    String url = "/pushingbox";
    url += "?devid=";
    url += devid;
   
    Serial.print("Requesting URL: ");
    Serial.println(url);


    // This will send the request to the server
    client.print(String("GET ") + url + " HTTP/1.1\r\n" +
                 "Host: " + host + "\r\n" +
                 "Connection: close\r\n\r\n");
    unsigned long timeout = millis();
    while (client.available() == 0) {
        if (millis() - timeout > 5000) {
            Serial.println(">>> Client Timeout !");
            client.stop();
            return;
        }
    }


    // Read all the lines of the reply from server and print them to Serial
    while(client.available()) {
        String line = client.readStringUntil('\r');
        Serial.print(line);
    }


    Serial.println();
    Serial.println("closing connection");
    }else{;}


    Upload the code.

Download Pushbullet App

Screenshot_20221027-001711_Pushbullet.jpg
Screenshot_20221027-001921_Discord.jpg

Download the Pushbullet App to your smartphone. Here's a GooglePlay Store link.

Log in with your account and enable push notifications in the app.

You should now be bombarded with push notifications. However, we only want to receive a push notification when we're pressing the button.

Send a Notification by the Press of a Button

While looking at a tutorial about a button control LED, I noticed my function was wrong. It was:

if(value = 1)

But it should be:

if(value == 0)

When the button isn't pressed, it's value is set at 1. When the button is pressed it's value is set at 0. So because it's constantly at 1, it continues to send pushnotifications.

After we change the function and upload the code, it works as intended!

Now it won't constantly send push notifactions, but only when I press the button.