Components and supplies
Arduino Yun
Apps and platforms
Arduino IDE
Project description
Code
Code snippet #1
arduino
1/* 2 RemoteControl 3 4 Demonstrates remotely controlling an Arduino Yun by phone with Nexmo 5 and the Temboo Arduino Yun SDK. 6 7 This example code is in the public domain. 8*/ 9 10#include <Bridge.h> 11#include <Temboo.h> 12#include "TembooAccount.h" 13 14/*** SUBSTITUTE YOUR VALUES BELOW: ***/ 15 16// your Nexmo API key 17const String NEXMO_API_KEY = "xxxxxxxxx"; 18 19// your Nexmo API secret 20const String NEXMO_API_SECRET = "xxxxxxxxx"; 21 22// the phone number you want your Yun to call 23const String PHONE_NUMBER = "xxxxxxxxxxx"; 24 25/***************************************/ 26 27int led = 13; // the LED on pin 13 28int numRuns = 0; // the number of times the sketch has been run 29int maxRuns = 1; // the number of times the sketch should run 30 31void setup(){ 32 Serial.begin(9600); 33 34 delay(4000); 35 while(!Serial); 36 Bridge.begin(); 37 38 // initialize the digital pin as an output 39 pinMode(led, OUTPUT); 40} 41 42void loop(){ 43 if (numRuns < maxRuns) { 44 Serial.println("Making a phone call to " + PHONE_NUMBER + "...\ 45"); 46 if (makeNexmoCall() == 1) { 47 Serial.println("Blinking the LED on 13!\ 48"); 49 // blink the LED on pin 13 ten times 50 for (int i =0; i < 10; i++) { 51 digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level) 52 delay(250); // wait for a 1/4 second 53 digitalWrite(led, LOW); // turn the LED off by making the voltage LOW 54 delay(250); // wait for a 1/4 second 55 } 56 } 57 // if the users choses not to blink the light, do nothing 58 else { 59 Serial.println("The user chose not to blink the light :-(\ 60"); 61 } 62 // increment the number of times the sketch has run 63 numRuns++; 64 Serial.println("Done."); 65 } 66 delay(60000); 67} 68 69/* 70Trigger a voice call via a Temboo Nexmo Choreo. Call the user, give them a menu of options 71and return the selection they make on their phone keypad as an integer. 72*/ 73int makeNexmoCall() { 74 int choice = 0; 75 76 TembooChoreo CaptureTextToSpeechPromptChoreo; 77 78 // invoke the Temboo client 79 CaptureTextToSpeechPromptChoreo.begin(); 80 81 // set Temboo account credentials 82 CaptureTextToSpeechPromptChoreo.setAccountName(TEMBOO_ACCOUNT); 83 CaptureTextToSpeechPromptChoreo.setAppKeyName(TEMBOO_APP_KEY_NAME); 84 CaptureTextToSpeechPromptChoreo.setAppKey(TEMBOO_APP_KEY); 85 86 // set choreo inputs 87 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."); 88 CaptureTextToSpeechPromptChoreo.addInput("APIKey", NEXMO_API_KEY); 89 CaptureTextToSpeechPromptChoreo.addInput("APISecret", NEXMO_API_SECRET); 90 CaptureTextToSpeechPromptChoreo.addInput("To", PHONE_NUMBER); 91 CaptureTextToSpeechPromptChoreo.addInput("MaxDigits", "1"); 92 CaptureTextToSpeechPromptChoreo.addInput("ByeText", "Ok, your wish is my command. Goodbye!"); 93 94 // identify choreo to run 95 CaptureTextToSpeechPromptChoreo.setChoreo("/Library/Nexmo/Voice/CaptureTextToSpeechPrompt"); 96 97 // add an output filter to return only the choice that the user makes from the phone menu 98 CaptureTextToSpeechPromptChoreo.addOutputFilter("choice", "/digits", "CallbackData"); 99 100 // run choreo 101 CaptureTextToSpeechPromptChoreo.run(); 102 103 // parse the results 104 while(CaptureTextToSpeechPromptChoreo.available()) { 105 // read the name of the next output item 106 String name = CaptureTextToSpeechPromptChoreo.readStringUntil('\\x1F'); 107 name.trim(); // use Ã
Code snippet #1
arduino
1/* 2 RemoteControl 3 4 Demonstrates remotely controlling an Arduino 5 Yun by phone with Nexmo 6 and the Temboo Arduino Yun SDK. 7 8 This example 9 code is in the public domain. 10*/ 11 12#include <Bridge.h> 13#include <Temboo.h> 14#include 15 "TembooAccount.h" 16 17/*** SUBSTITUTE YOUR VALUES BELOW: ***/ 18 19// your 20 Nexmo API key 21const String NEXMO_API_KEY = "xxxxxxxxx"; 22 23// your Nexmo 24 API secret 25const String NEXMO_API_SECRET = "xxxxxxxxx"; 26 27// the phone 28 number you want your Yun to call 29const String PHONE_NUMBER = "xxxxxxxxxxx"; 30 31/***************************************/ 32 33int 34 led = 13; // the LED on pin 13 35int numRuns = 0; // the number of times the sketch 36 has been run 37int maxRuns = 1; // the number of times the sketch should run 38 39void 40 setup(){ 41 Serial.begin(9600); 42 43 delay(4000); 44 while(!Serial); 45 46 Bridge.begin(); 47 48 // initialize the digital pin as an output 49 pinMode(led, 50 OUTPUT); 51} 52 53void loop(){ 54 if (numRuns < maxRuns) { 55 Serial.println("Making 56 a phone call to " + PHONE_NUMBER + "...\ 57"); 58 if (makeNexmoCall() == 1) 59 { 60 Serial.println("Blinking the LED on 13!\ 61"); 62 // blink the 63 LED on pin 13 ten times 64 for (int i =0; i < 10; i++) { 65 digitalWrite(led, 66 HIGH); // turn the LED on (HIGH is the voltage level) 67 delay(250); // 68 wait for a 1/4 second 69 digitalWrite(led, LOW); // turn the LED off 70 by making the voltage LOW 71 delay(250); // wait for a 1/4 72 second 73 } 74 } 75 // if the users choses not to blink the light, 76 do nothing 77 else { 78 Serial.println("The user chose not to blink the 79 light :-(\ 80"); 81 } 82 // increment the number of times the sketch has 83 run 84 numRuns++; 85 Serial.println("Done."); 86 } 87 delay(60000); 88} 89 90/* 91Trigger 92 a voice call via a Temboo Nexmo Choreo. Call the user, give them a menu of options 93and 94 return the selection they make on their phone keypad as an integer. 95*/ 96int 97 makeNexmoCall() { 98 int choice = 0; 99 100 TembooChoreo CaptureTextToSpeechPromptChoreo; 101 102 103 // invoke the Temboo client 104 CaptureTextToSpeechPromptChoreo.begin(); 105 106 107 // set Temboo account credentials 108 CaptureTextToSpeechPromptChoreo.setAccountName(TEMBOO_ACCOUNT); 109 110 CaptureTextToSpeechPromptChoreo.setAppKeyName(TEMBOO_APP_KEY_NAME); 111 CaptureTextToSpeechPromptChoreo.setAppKey(TEMBOO_APP_KEY); 112 113 114 // set choreo inputs 115 CaptureTextToSpeechPromptChoreo.addInput("Text", 116 "Hello there. Would you like to blink a light on your Arduino Yun? Press one to 117 blink, or press zero to ignore."); 118 CaptureTextToSpeechPromptChoreo.addInput("APIKey", 119 NEXMO_API_KEY); 120 CaptureTextToSpeechPromptChoreo.addInput("APISecret", NEXMO_API_SECRET); 121 122 CaptureTextToSpeechPromptChoreo.addInput("To", PHONE_NUMBER); 123 CaptureTextToSpeechPromptChoreo.addInput("MaxDigits", 124 "1"); 125 CaptureTextToSpeechPromptChoreo.addInput("ByeText", "Ok, your wish 126 is my command. Goodbye!"); 127 128 // identify choreo to run 129 CaptureTextToSpeechPromptChoreo.setChoreo("/Library/Nexmo/Voice/CaptureTextToSpeechPrompt"); 130 131 132 // add an output filter to return only the choice that the user makes from 133 the phone menu 134 CaptureTextToSpeechPromptChoreo.addOutputFilter("choice", 135 "/digits", "CallbackData"); 136 137 // run choreo 138 CaptureTextToSpeechPromptChoreo.run(); 139 140 141 // parse the results 142 while(CaptureTextToSpeechPromptChoreo.available()) 143 { 144 // read the name of the next output item 145 String name = CaptureTextToSpeechPromptChoreo.readStringUntil('\\x1F'); 146 147 name.trim(); // use Ã
Github
https://github.com/temboo/arduino-examples/tree/master/remote-control-by-phone
Comments
Only logged in users can leave comments
Arduino_Scuola
0 Followers
•0 Projects
Table of contents
Intro
0
0