Everything about Internet of Things and more

Internet of Things project – Android push notifications | ESP8266 Arduino Tutorial

What is the purpose of an IoT project if you cannot access it live from everywhere using your smartphone? Even the name of the concept itself – “Internet of things” – suggests the idea of having remote access to your “things” from any place at anytime. In this ESP8266 Arduino tutorial you will find a 3 steps simple method to send push notifications messages from your IoT project to your smartphone using a standalone cheap a Wi-Fi module.

Examples of IoT applications that requires push notifications:

Push notifications from ESP8266 Arduino compatible Wi-Fi module to Android / IOS mobile devices

Is it hard to do it?

Nope, this shouldn’t take more than 30 minutes to make it work. This esp8266 arduino tutorial is so simple that you will just love it at the end. Follow the next steps and in no more than 20-30 minutes your Android or IOS smartphone will receive a push notification like this:

IoT project - Android push notifications | ESP8266 Arduino TutorialProject requirements:

Note: If you don’t know what an ESP8266 is, you should read this complete ESP8266 module tutorial first, and than continue.

Were do you start?

Step 1: setup the PushBullet service (free)

Pushbullet is an internet service which for SMS sending, notification management and file sending between your mobile devices and pc.”

First you need to go to PushBullet and make a new free account. Activate your account, login in the website and you will see the next screen:

IoT project - Android push notifications | ESP8266 Arduino TutorialClick on you mobile OS type (Android or IOS) or go in the apps market / Google play and search for PushBullet and setup the application on your mobile device using the same account you’ve just created. After that you should see your mobile smartphone in the Devices menu.

IoT project - Android push notifications | ESP8266 Arduino TutorialGo to Settings menu and create a new Access Token by pressing Create Access Token button.

IoT project - Android push notifications | ESP8266 Arduino Tutorial

IoT project - Android push notifications | ESP8266 Arduino TutorialGet the access token and save it to a notepad text file.

Step 2: Setup PushingBox, IoT notification center (free)

“PushingBox is a cloud that can send notification, emails, tweets based on API calls in real time.”

Go to PushingBox, create a new account for free and login. Go to Dashboard and click on My Services – > Add a service. Select PushBullet service from the list and you should see the following screen:

IoT project - Android push notifications | ESP8266 Arduino TutorialGive it a name, and paste your pushbullet token which you should have in your notepad text file and submit the form. After that go to My Scenarios and add a new scenario. You should now be able to add a new Action to your scenario.

IoT project - Android push notifications | ESP8266 Arduino TutorialThe text between the $param$ signs will be your HTTP GET parameter, you will see in the code later. You will be able to replace each parameter like that with your data like temperature or humidity. Save the action and go back to your virtual scenarios list. You should be able to see your new scenario and copy the DeviceId.

IoT project - Android push notifications | ESP8266 Arduino TutorialStep 3: Code example for your ESP8266 Arduino compatible module

This code is very simple to use, it just connects to your Wi-Fi router and then sends a HTTP request to pushingbox API related to your unique device ID. Modify the code by replacing the **** with your Wi-Fi credentials and your PushingBox deviceId. Upload the code to your ESP8266 and test it.

/************
GeeksTips.com
ESP8266 Arduino Tutorial - Push notification messages example
Arduino code example
www.geekstips.com

- replace the dots with your Wi-fi credentials and
- your deviceId from pushingBox account
*/
#include <ESP8266WiFi.h>

// PushingBox scenario DeviceId code and API
String deviceId = "*************";
const char* logServer = "api.pushingbox.com";

const char* ssid = "**********";
const char* password = "***********";

void setup() {
  Serial.begin(74880);
  // Sending a notification to your mobile phone
  // function takes the message as a parameter
  sendNotification("Hello World from ESP8266!");
}

void sendNotification(String message){

  Serial.println("- connecting to Home Router SID: " + String(ssid));
  
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  
  Serial.println();
  Serial.println("- succesfully connected");
  Serial.println("- starting client");
  
  WiFiClient client;

  Serial.println("- connecting to pushing server: " + String(logServer));
  if (client.connect(logServer, 80)) {
    Serial.println("- succesfully connected");
    
    String postStr = "devid=";
    postStr += String(deviceId);
    postStr += "&message_parameter=";
    postStr += String(message);
    postStr += "\r\n\r\n";
    
    Serial.println("- sending data...");
    
    client.print("POST /pushingbox HTTP/1.1\n");
    client.print("Host: api.pushingbox.com\n");
    client.print("Connection: close\n");
    client.print("Content-Type: application/x-www-form-urlencoded\n");
    client.print("Content-Length: ");
    client.print(postStr.length());
    client.print("\n\n");
    client.print(postStr);
  }
  client.stop();
  Serial.println("- stopping the client");
}

void loop() {}

The most complete Arduino Starter Kit

Final thoughts

You can send notifications just by using PushBullet standalone, without PushingBox but in order to do that you need to use HTTPS requests with secure connection, and you may consider finding a certificate. Also you need to send a specific data model in JSON format. For more information read the PushBullet API documentation. I use PushingBox because it offers many services, not only for PushBullet, and also the API documentation for PushingBox seems more clear.

PushingBox and PushBullet are two incredible powerful free platforms which you definitely need to try them if you are building an Internet of Things project. I recommend you to test them, the APIs are quite easy to work with, and the features are freaking awesome for paying nothing.

Also if you are interested in monitoring temperature and humidity with Arduino or ESP8266 you can read this Arduino temperature sensors tutorial.

Hoping that this article inspired you, i kindly invite you share this articlesubscribe my YouTube channel and join the communities on social networks. Please feel free to comment or send suggestions / remarks so i can improve the content quality!

Share on: Facebook Twitter Google+

15 Replies to “Internet of Things project – Android push notifications | ESP8266 Arduino Tutorial”

  1. GeeksTips says:

    Enjoy!

  2. Jeen says:

    Hi .Great tutorial..Can you also send me the circuit diagram showing connections between ESP8266 and Arduino ?

  3. Tri Ananda says:

    Thank you for your tutorial! it’s help me..

  4. Mark says:

    Doesn’t seem to work for me, followed the tutorial, got all of the tests to work when pushing the message from pushingbox to pushbullet, but when it came to the code, it wouldn’t push the notification when I uploaded the code. My WIFI creds are correct as is my ID, so I’m quite stumpted as to why it wouldn’t upload. Maybe a video would help to show if I missed anything?

  5. Collin H says:

    Thanks alot,
    It works like a charm.
    Cheers!

  6. Mike Mckay says:

    Out of curiosity, isn’t the ESP able to do all of this by itself as it is a wifi enabled microcontroller in its own right?

    • Short answer: no. ESP its a development board only. The WiFi module embedded allows only TCP transactions. You cannot force input into a Smartphone directly from a ESP (not natively).

  7. Nelu says:

    Hello !
    Why I have error when I test compile cod ? :

    ‘sendNotification’ was not declared in this scope

    Thanks !

    • Hello, make sure you correctly copied the code and you have all your libraries installed. I just compiled exactly this code and it got trough fine. Thanks!

  8. Suresh Doraiswamy says:

    Hello Lucian,
    It works great! I am able to push notifications to my mobile with no problems. Thanks.
    Now, I want to send a command from the PushBox App on my mobile to this app running on my ESp8266.
    Kindly show me how.
    Thanks.
    Suresh

  9. Zeynel says:

    Hello,

    Im try tu use on 3 days of Push note form esp8266 to android.

    But neader your code nor my code doesnt send sny message form IOT devices.
    I think ı make mistake something.

    This is my code please tell me what is wrong at ths code ?

    Thank you

  10. Zeynel says:

    // ESP8266 DS18B20 ArduinoIDE Thingspeak IoT Example code

    #include
    #include
    #include
    #include
    #include
    #include

    #define ONE_WIRE_BUS D3

    // ThingSpeak Connection Detail
    const char* host = “api.thingspeak.com”; // Your domain
    String ApiKey = “BD4EHOFNB3CTV5F0”;
    String path = “/update?api_key=” + ApiKey + “&field1=”;

    // PushingBox scenario DeviceId code and API
    String deviceId = ” v8768796E7358C90″;
    const char* logServer = “api.pushingbox.com”;

    // SSID
    const char* ssid = “IForbs”;
    const char* password = “30061972”;

    //————————————-
    // Deep Sleep Tanımları
    //————————————-
    const int sleepSeconds = 3600;

    char temperatureString[6];

    OneWire oneWire(ONE_WIRE_BUS);
    DallasTemperature DS18B20(&oneWire);

    // ————————————
    // getTemperature Fonksiyonu
    //————————————-
    float getTemperature() {
    float temp;
    do {
    DS18B20.requestTemperatures();
    temp = DS18B20.getTempCByIndex(0);
    delay(100);
    } while (temp == 85.0 || temp == (-127.0));
    return temp;
    }

    //————————————
    // Wifi Bağlantı Fonkriyonu
    //————————————
    void connectWifi (void) {

    WiFi.begin(ssid, password);
    // if you’re not connected, stop here:
    if ( WiFi.status() != WL_CONNECTED) {
    delay(500);
    ESP.restart();
    while(true);
    }

    }

    //————————————-
    // PushBullet Mesaj Gönderim Fonksiyonu
    //————————————-

    void sendNotification(String message){

    WiFiClientSecure client;

    if (client.connect(logServer, 80)) {

    String postStr = “deviceId=”;
    postStr += String(deviceId);
    postStr += “&$message$”;
    postStr += String(message);
    postStr += “&$parameter$=”;
    postStr += String(“Derece”);
    postStr += “\r\n\r\n”;

    client.print(“POST /pushingbox HTTP/1.1\n”);
    client.print(“Host: api.pushingbox.com\n”);
    client.print(“Connection: close\n”);
    client.print(“Content-Type: application/x-www-form-urlencoded\n”);
    client.print(“Content-Length: “);
    client.print(postStr.length());
    client.print(“\n\n”);
    client.print(postStr);
    }
    client.stop();
    }

    //————————————————–
    // ThingSpeak’ Bağlantı ve Veri Gönderme Fonksiyonu
    //————————————————–

    void thingspeak(void){
    float temperature = getTemperature();

    dtostrf(temperature, 2, 2, temperatureString);
    // send temperature to the serial console
    sendNotification(temperatureString);

    WiFiClient client;
    const int httpPort = 80;
    if (!client.connect(host, httpPort)) {
    sendNotification(“connection failed”);
    return;
    }

    client.print(String(“GET “) + path + temperatureString + ” HTTP/1.1\r\n” +
    “Host: ” + host + “\r\n” +
    “Connection: keep-alive\r\n\r\n”);
    delay(500);
    }

    //——————————–
    // Ana Program Bloğu
    //——————————–

    void setup(void){

    // Sending a notification to your mobile phone
    // function takes the message as a parameter
    // sendNotification(“Hello World from ESP8266!”);

    char buf[15];

    connectWifi;

    sendNotification(deviceId);
    sendNotification(“”);
    sendNotification(“Connected to “);
    sendNotification(ssid);

    //DS18B20.begin();

    //thingspeak();

    sendNotification(“Bir saatlik uyku başlangıcı”);
    //ESP.deepSleep(sleepSeconds * 1000000);
    delay(100);

    }

    void loop() {
    delay(10);
    }

  11. Caesar G says:

    Hi Lucian,

    Thank you for your great post! It is the best post on the web about Android push notifications.

    I had no problems making my ESP8266-01 working. It was as simple as copying your fantastic code into empty .ino file, and then setting the Pushbullet and Pushingbox accounts, as you guided.

    It worked beautifully.

    Unfortunately, I run into problem when trying to implement a PIR sensor, or any sensor.

    So, I put the Loop part of the code within the Loop bracket part of your code (which is at the bottom and the last line of your code). The code compiled, but the intrusion event was not triggering any push messages via Bullet.

    The only message that is pushed, is when initializing the device, or resetting it. Just one initial message, there are no messages triggered by sensor’s state change.

    Was I correct to insert the code inside the loop?

    Where the simple sensor code has to be inserted in your code?

  12. VENUS says:

    Hi there! I want to ask. Where do I get the library for my esp8266?

Leave a Reply

Your email address will not be published.