Push Notification from Arduino Yún with motion sensor (Part 2/2)

Supposedly, you’ve already filled your theoretical knowledge gaps and prepared hardware after reading the first part. Before we move on to the essence, I just want to mention that while I was writing this part, a few questions arised that most likely would’ve stayed unanswered without Ivan‘s input – thanks (officially 🙂 ) for being so helpful!

Ok, what are we doing again?

We are going to use Temboo’s client (preinstalled on every Yún) to communicate it with API of – a mobile backend – which will then send a push notification to Android device. As it states on the official site “Temboo makes it easy for the Arduino Yún to connect to over 100 web-based resources and services (e.g. Facebook, Dropbox, US Census data) by standardizing how you interact with their Application Programming Interfaces (APIs)”. To be more specific, it makes it easy to call these external API’s with smart code snippets called Choreos (all of Choreos are listed here).


Image source:


Note: You can also call Parse API without Temboo’s Choreos – using the official Arduino Yun Parse SDK.  I’ve decided to describe Temboo as it seems to be much more universal, but if your project is anything more than hobbyist experiment you need to know that Temboo gives you only 250 api calls per month for free (for me, it looks like they’re enforcing usage of their referral plan) so just keep in mind that Parse’s free plan seems much better.

Challenge accepted

Ok, firstly we need to obtain API keys. Register your app on and open it’s Settings > Keys. You will need Application ID and REST API Key.

I've blurred out keys for example project, I must have missed Photoshop.

I’ve blurred out keys for example project, I must have missed Photoshop.


Take a look at getting started with Temboo or just follow these strictly goal-directed steps:

Zrzut ekranu 2015-12-02 02.22.06

Noone cares about blurring, right.

  "data": {
    "channel": "yun",
    "alert": "Quiet! I think something is moving there...",
    "sound": "",
    "badge": "Increment"
  "where": {
    "deviceType": "android"

You can also view your sent pushes in Parse (in Push section).


Note: Don’t miss the fact that the channel is defined to “yun” which means that if any device wants to receive this push it needs to be subscribed to this channel.

Very important little differences

What you’ve copied from Temboo is prepared to be executed as an *.ino file. As you might have noticed, I remain completely unconvinced about using Arduino IDE, it’s serial monitor or even *.ino files. Let me bring out the little differences between *.ino and *.cpp files.


Arduino Sketch File (*.ino) is ‘almost’ valid C code, except it:

  • Does not need functions prototypes
  • Does not need #include “Arduino.h” preprocessor directive

‘Almost’ valid is not valid enough for C compilator, so let’s repair what was generated (and keep it a *.cpp file).

#include <Arduino.h>
#include <Bridge.h>
#include <Temboo.h>
#include "TembooAccount.h" // Contains Temboo account information

// The number of times to trigger the action if the condition is met
// We limit this so you won't use all of your Temboo calls while testing
int maxCalls = 10;

// The number of times this Choreo has been run so far in this sketch
int calls = 0;

int inputPin = 7;

void runSendNotification(int sensorValue);

void setup() {

    // For debugging, wait until the serial console is connected

    // Initialize pins
    pinMode(inputPin, INPUT);

    Serial.println("Setup complete.\n");

void loop() {
    int sensorValue = digitalRead(inputPin);
    Serial.println("Sensor: " + String(sensorValue));

    if (sensorValue == HIGH) {
        if (calls < maxCalls) {
            Serial.println("\nTriggered! Calling SendNotification Choreo...");
        } else {
            Serial.println("\nTriggered! Skipping to save Temboo calls. Adjust maxCalls as required.");

void runSendNotification(int sensorValue) {
    TembooChoreo SendNotificationChoreo;

    // Invoke the Temboo client

    // Set Temboo account credentials

    // Set Choreo inputs
    SendNotificationChoreo.addInput("RESTAPIKey", "o9SchesGIcheskuechesK9jchesEKsqchesrM8zT");
    SendNotificationChoreo.addInput("ApplicationID", "zchesus6Lchesaq39ches1HchesuVOchessltTB6FS");
    SendNotificationChoreo.addInput("Notification", "{\n  \"data\": {\n    \"channel\": \"yun\",\n    \"alert\": \"Quiet! I think something is moving there...\",\n    \"sound\": \"\",\n    \"badge\": \"Increment\"\n  },\n  \"where\": {\n    \"deviceType\": \"android\"\n  }\n}");

    // Identify the Choreo to run

    // Run the Choreo
    unsigned int returnCode =;

    // Read and print the error message
    while (SendNotificationChoreo.available()) {
        char c =;

Note: To be perfectly honest ‘Arduino.h’ is already included in both Bridge and Temboo, but we need to work on good habits, right?


Note: If you would decide to go with *.ino – PlatformIO is also able to handle *.ino files and automatically adds what’s mentioned above at build time before compilation phase!

One more thing…

We also need to include directories with added libraries (Bridge, Temboo) to build path (CMakeLists.txt). PlatformIO handles this too, all we need to do in this case is reiniting the project:

platformio init --ide=clion

Reload the project in CLion and notice newly generated lines:


Now is the time to build & upload, connect serial port monitor and test if pushes are successfully sent through Parse. Then, once you’ve got it all set up..

Android time

Create a new project in Android Studio and edit your applications build file (/app/build.gradle) to add Parse’s SDK.

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile ''
    compile ''
    compile 'com.parse.bolts:bolts-android:1.+'
    compile 'com.parse:parse-android:1.+'

Modify AndroidManifest.xml file in reference to mentioned Parse’s guide (especially remembering about changing the package name!).


Open and add these lines at the end of an onCreate() method (with your api keys):

protected void onCreate(Bundle savedInstanceState) {
    Parse.initialize(this, "o9Sg9PcheseLHygK9jKLIPEKsq4GFyrM8zT", "XIxCJLpclTfqQ3Pwwcp5OKchesecMwybnhsnIEM");
    ParsePush.subscribeInBackground("yun", new SaveCallback() {
        public void done(ParseException e) {
                Toast.makeText(MainActivity.this, "Succesfully subbed to yun channel!", Toast.LENGTH_LONG).show();
                Toast.makeText(MainActivity.this, "Couldn't sub - check internet connection, api keys and AndroidManifest.xml!", Toast.LENGTH_LONG).show();

Run it on your device (with enabled developer options) and check on Parse (Core > Data > Installation) if it subscribed successfully. If so, you should receive push notifications from your Yún!

You don't need to write a simple line of code to view this on watch, #justsayin.

Android Wear device (like my G Watch R) is able to view notifications, no additional code was needed.

Share this Story:
  • facebook
  • twitter
  • gplus

Leave a comment