Arduino_Scuola
Published © GPL3+

Control your Yún from your Phone with Temboo

Here we'll show you how to use your phone as a remote control for your Arduino Yún. Specifically, the example sketch calls a phone number.

IntermediateFull instructions provided30 minutes2,053
Control your Yún from your Phone with Temboo

Things used in this project

Hardware components

Arduino Yun
Arduino Yun
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Code

Code snippet #1

Arduino
/*
  RemoteControl

  Demonstrates remotely controlling an Arduino Yun by phone with Nexmo 
  and the Temboo Arduino Yun SDK.
  
  This example code is in the public domain.
*/

#include <Bridge.h>
#include <Temboo.h>
#include "TembooAccount.h"

/*** SUBSTITUTE YOUR VALUES BELOW: ***/

// your Nexmo API key
const String NEXMO_API_KEY = "xxxxxxxxx";

// your Nexmo API secret
const String NEXMO_API_SECRET = "xxxxxxxxx";

// the phone number you want your Yun to call
const String PHONE_NUMBER = "xxxxxxxxxxx";

/***************************************/

int led = 13; // the LED on pin 13
int numRuns = 0; // the number of times the sketch has been run
int maxRuns = 1; // the number of times the sketch should run

void setup(){
  Serial.begin(9600);
  
  delay(4000);
  while(!Serial);
  Bridge.begin();
  
  // initialize the digital pin as an output
  pinMode(led, OUTPUT);  
}

void loop(){
  if (numRuns < maxRuns) {
    Serial.println("Making a phone call to " + PHONE_NUMBER + "...\n");
    if (makeNexmoCall() == 1) {
      Serial.println("Blinking the LED on 13!\n");
      // blink the LED on pin 13 ten times
      for (int i =0; i < 10; i++) {
        digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
        delay(250);               // wait for a 1/4 second
        digitalWrite(led, LOW);    // turn the LED off by making the voltage LOW
        delay(250);               // wait for a 1/4 second
      } 
    } 
    // if the users choses not to blink the light, do nothing
    else {
      Serial.println("The user chose not to blink the light :-(\n");
    }
    // increment the number of times the sketch has run
    numRuns++;
    Serial.println("Done.");
  }
  delay(60000);
}

/*
Trigger a voice call via a Temboo Nexmo Choreo. Call the user, give them a menu of options
and return the selection they make on their phone keypad as an integer. 
*/
int makeNexmoCall() {
  int choice = 0;
  
  TembooChoreo CaptureTextToSpeechPromptChoreo;

  // invoke the Temboo client
  CaptureTextToSpeechPromptChoreo.begin();
    
  // set Temboo account credentials
  CaptureTextToSpeechPromptChoreo.setAccountName(TEMBOO_ACCOUNT);
  CaptureTextToSpeechPromptChoreo.setAppKeyName(TEMBOO_APP_KEY_NAME);
  CaptureTextToSpeechPromptChoreo.setAppKey(TEMBOO_APP_KEY);
    
  // set choreo inputs
  CaptureTextToSpeechPromptChoreo.addInput("Text", "Hello there. Would you like to blink a light on your Arduino Yun? Press one to blink, or press zero to ignore.");
  CaptureTextToSpeechPromptChoreo.addInput("APIKey", NEXMO_API_KEY);
  CaptureTextToSpeechPromptChoreo.addInput("APISecret", NEXMO_API_SECRET);
  CaptureTextToSpeechPromptChoreo.addInput("To", PHONE_NUMBER);
  CaptureTextToSpeechPromptChoreo.addInput("MaxDigits", "1");
  CaptureTextToSpeechPromptChoreo.addInput("ByeText", "Ok, your wish is my command. Goodbye!");
    
  // identify choreo to run
  CaptureTextToSpeechPromptChoreo.setChoreo("/Library/Nexmo/Voice/CaptureTextToSpeechPrompt");
  
  // add an output filter to return only the choice that the user makes from the phone menu
  CaptureTextToSpeechPromptChoreo.addOutputFilter("choice", "/digits", "CallbackData");
    
  // run choreo
  CaptureTextToSpeechPromptChoreo.run();
  
  // parse the results 
  while(CaptureTextToSpeechPromptChoreo.available()) {
    // read the name of the next output item
    String name = CaptureTextToSpeechPromptChoreo.readStringUntil('\x1F');
    name.trim(); // use Ã

Github

https://github.com/temboo/arduino-examples/tree/master/remote-control-by-phone

Credits

Temboo_OFFICIAL

Posted by Arduino_Scuola

Comments