Lesson 25: How to Push Notifications to Smartphone

 

Written by Jonathan Sim

You can find this lesson and more in the Arduino IDE (File -> Examples -> Andee). If you are unable to find them, you will need to install the Andee Library for Arduino IDE.

Works on Android
Apart from sending SMSes, you can also get the Annikken Andee to push notifications directly to your smartphone to alert you of a change in sensor reading and more!

Here's how a push notification typically looks:

Lesson25.png


Contents

Top of the Code

#include <SPI.h>
#include <Andee.h>

// We'll use a button to send the message
AndeeHelper btnNotify;
AndeeHelper notificationObject; // The notification must be declared as an object

setup()

void setup()
{
  Andee.begin();  // Setup communication between Annikken Andee and Arduino
  Andee.clear();  // Clear the screen of any previous displays
  setInitialData(); // Define object types and their appearance
}

setInitialData()

void setInitialData()
{
  btnNotify.setId(0);
  btnNotify.setType(BUTTON_IN);
  btnNotify.setLocation(0,0,FULL);
  btnNotify.setTitle("Push Notification");
  
  notificationObject.setId(1);
  notificationObject.setType(NOTIFICATION); // Sets object as an SMS object
  notificationObject.setTitle("Notification Title"); 
  notificationObject.setMessage("Notification Message"); 
  notificationObject.setTicker("Text that appears at status bar when notification is pushed"); 

}

loop()

void loop()
{
  if( btnNotify.isPressed() ) // When user presses the send button on phone
  {
    btnNotify.ack(); // Acknowledge button press
    notificationObject.notify(); // Pushes the notification to the smartphone
  }

  btnNotify.update();
  // Do not update push notification objects!
  
  delay(500); // Always leave a short delay for Bluetooth communication
}
comments powered by Disqus