Components and supplies
Arduino Yun
Apps and platforms
Arduino IDE
Project description
Code
Code snippet #1
arduino
1/* 2 SendAnSMS 3 4 Demonstrates sending an SMS via a Twilio account using the Temboo Arduino Yun SDK. 5 6 This example code is in the public domain. 7*/ 8 9#include <Bridge.h> 10#include <Temboo.h> 11#include "TembooAccount.h" // contains Temboo account information 12 13/*** SUBSTITUTE YOUR VALUES BELOW: ***/ 14 15// Note that for additional security and reusability, you could 16// use #define statements to specify these values in a .h file. 17 18// the Account SID from your Twilio account 19const String TWILIO_ACCOUNT_SID = "xxxxxxxxxx"; 20 21// the Auth Token from your Twilio account 22const String TWILIO_AUTH_TOKEN = "xxxxxxxxxx"; 23 24// your Twilio phone number, e.g., "+1 555-222-1212" 25const String TWILIO_NUMBER = "xxxxxxxxxx"; 26 27// the number to which the SMS should be sent, e.g., "+1 555-222-1212" 28const String RECIPIENT_NUMBER = "xxxxxxxxxx"; 29 30boolean success = false; // a flag to indicate whether we've sent the SMS yet or not 31 32void setup() { 33 Serial.begin(9600); 34 35 // for debugging, wait until a serial console is connected 36 delay(4000); 37 while(!Serial); 38 39 Bridge.begin(); 40} 41 42void loop() 43{ 44 // only try to send the SMS if we haven't already sent it successfully 45 if (!success) { 46 47 Serial.println("Running SendAnSMS..."); 48 49 // we need a Process object to send a Choreo request to Temboo 50 TembooChoreo SendSMSChoreo; 51 52 // invoke the Temboo client 53 // NOTE that the client must be reinvoked and repopulated with 54 // appropriate arguments each time its run() method is called. 55 SendSMSChoreo.begin(); 56 57 // set Temboo account credentials 58 SendSMSChoreo.setAccountName(TEMBOO_ACCOUNT); 59 SendSMSChoreo.setAppKeyName(TEMBOO_APP_KEY_NAME); 60 SendSMSChoreo.setAppKey(TEMBOO_APP_KEY); 61 62 // identify the Temboo Library choreo to run (Twilio > SMSMessages > SendSMS) 63 SendSMSChoreo.setChoreo("/Library/Twilio/SMSMessages/SendSMS"); 64 65 // set the required choreo inputs 66 // see https://www.temboo.com/library/Library/Twilio/SMSMessages/SendSMS/ 67 // for complete details about the inputs for this Choreo 68 69 // the first input is a your AccountSID 70 SendSMSChoreo.addInput("AccountSID", TWILIO_ACCOUNT_SID); 71 72 // next is your Auth Token 73 SendSMSChoreo.addInput("AuthToken", TWILIO_AUTH_TOKEN); 74 75 // next is your Twilio phone number 76 SendSMSChoreo.addInput("From", TWILIO_NUMBER); 77 78 // next, what number to send the SMS to 79 SendSMSChoreo.addInput("To", RECIPIENT_NUMBER); 80 81 // finally, the text of the message to send 82 SendSMSChoreo.addInput("Body", "Hey, there! This is a message from your Arduino Yun!"); 83 84 // tell the Process to run and wait for the results. The 85 // return code (returnCode) will tell us whether the Temboo client 86 // was able to send our request to the Temboo servers 87 unsigned int returnCode = SendSMSChoreo.run(); 88 89 // a return code of zero (0) means everything worked 90 if (returnCode == 0) { 91 Serial.println("Success! SMS sent!"); 92 success = true; 93 } else { 94 // a non-zero return code means there was an error 95 // read and print the error message 96 while (SendSMSChoreo.available()) { 97 char c = SendSMSChoreo.read(); 98 Serial.print(c); 99 } 100 } 101 SendSMSChoreo.close(); 102 103 // do nothing for the next 60 seconds 104 Serial.println("Waiting..."); 105 delay(60000); 106 } 107}
Comments
Only logged in users can leave comments
Arduino_Scuola
0 Followers
•0 Projects
Table of contents
Intro
0
0