1
0
mirror of https://github.com/arduino/Arduino.git synced 2024-12-12 23:08:52 +01:00
Arduino/libraries/Bridge/examples/Temboo/SendAnSMS/SendAnSMS.ino

155 lines
5.3 KiB
Arduino
Raw Normal View History

2013-06-28 11:08:56 +02:00
/*
SendAnSMS
2013-07-11 11:24:53 +02:00
Demonstrates sending an SMS via Twilio using Temboo from an Arduino Yun.
2013-06-28 11:08:56 +02:00
Check out the latest Arduino & Temboo examples and support docs at http://www.temboo.com/arduino
A Temboo account and application key are necessary to run all Temboo examples.
If you don't already have one, you can register for a free Temboo account at
2013-06-28 11:08:56 +02:00
http://www.temboo.com
Since this sketch uses Twilio to send the SMS, you'll also need a valid
2013-06-28 11:08:56 +02:00
Twilio account. You can create one for free at https://www.twilio.com.
2013-06-28 11:08:56 +02:00
The sketch needs your Twilio phone number, along with
the Account SID and Auth Token you get when you register with Twilio.
Make sure to use the Account SID and Auth Token from your Twilio Dashboard
2013-06-28 11:08:56 +02:00
(not your test credentials from the Dev Tools panel).
Also note that if you're using a free Twilio account, you'll need to verify
2013-06-28 11:08:56 +02:00
the phone number to which messages are being sent by going to twilio.com and following
the instructions under the "Numbers > Verified Caller IDs" tab (this restriction
doesn't apply if you have a paid Twilio account).
2013-06-28 11:08:56 +02:00
This example assumes basic familiarity with Arduino sketches, and that your Yun is connected
to the Internet.
2013-07-11 11:24:53 +02:00
Looking for another API to use with your Arduino Yun? We've got over 100 in our Library!
2013-06-28 11:08:56 +02:00
This example code is in the public domain.
*/
#include <Bridge.h>
2013-07-08 15:09:09 +02:00
#include <Temboo.h>
2013-06-28 11:08:56 +02:00
#include "TembooAccount.h" // contains Temboo account information
// as described in the footer comment below
2013-06-28 11:08:56 +02:00
/*** SUBSTITUTE YOUR VALUES BELOW: ***/
2013-07-03 09:02:59 +02:00
// Note that for additional security and reusability, you could
// use #define statements to specify these values in a .h file.
2013-06-28 11:08:56 +02:00
// the Account SID from your Twilio account
const String TWILIO_ACCOUNT_SID = "xxxxxxxxxx";
// the Auth Token from your Twilio account
const String TWILIO_AUTH_TOKEN = "xxxxxxxxxx";
// your Twilio phone number, e.g., "+1 555-222-1212"
const String TWILIO_NUMBER = "xxxxxxxxxx";
// the number to which the SMS should be sent, e.g., "+1 555-222-1212"
const String RECIPIENT_NUMBER = "xxxxxxxxxx";
// a flag to indicate whether we've attempted to send the SMS yet or not
boolean attempted = false;
2013-06-28 11:08:56 +02:00
void setup() {
Serial.begin(9600);
// for debugging, wait until a serial console is connected
delay(4000);
while (!Serial);
2013-06-28 11:08:56 +02:00
Bridge.begin();
}
void loop()
{
// only try to send the SMS if we haven't already sent it successfully
if (!attempted) {
2013-06-28 11:08:56 +02:00
Serial.println("Running SendAnSMS...");
2013-06-28 11:08:56 +02:00
// we need a Process object to send a Choreo request to Temboo
2013-07-08 15:09:09 +02:00
TembooChoreo SendSMSChoreo;
2013-06-28 11:08:56 +02:00
// invoke the Temboo client
2013-07-08 15:09:09 +02:00
// NOTE that the client must be reinvoked and repopulated with
// appropriate arguments each time its run() method is called.
SendSMSChoreo.begin();
2013-06-28 11:08:56 +02:00
// set Temboo account credentials
2013-07-08 15:09:09 +02:00
SendSMSChoreo.setAccountName(TEMBOO_ACCOUNT);
SendSMSChoreo.setAppKeyName(TEMBOO_APP_KEY_NAME);
SendSMSChoreo.setAppKey(TEMBOO_APP_KEY);
2013-06-28 11:08:56 +02:00
// identify the Temboo Library choreo to run (Twilio > SMSMessages > SendSMS)
2013-07-08 15:09:09 +02:00
SendSMSChoreo.setChoreo("/Library/Twilio/SMSMessages/SendSMS");
2013-06-28 11:08:56 +02:00
// set the required choreo inputs
// see https://www.temboo.com/library/Library/Twilio/SMSMessages/SendSMS/
2013-06-28 11:08:56 +02:00
// for complete details about the inputs for this Choreo
// the first input is a your AccountSID
2013-07-08 15:09:09 +02:00
SendSMSChoreo.addInput("AccountSID", TWILIO_ACCOUNT_SID);
2013-06-28 11:08:56 +02:00
// next is your Auth Token
2013-07-08 15:09:09 +02:00
SendSMSChoreo.addInput("AuthToken", TWILIO_AUTH_TOKEN);
2013-06-28 11:08:56 +02:00
// next is your Twilio phone number
2013-07-08 15:09:09 +02:00
SendSMSChoreo.addInput("From", TWILIO_NUMBER);
2013-06-28 11:08:56 +02:00
// next, what number to send the SMS to
2013-07-08 15:09:09 +02:00
SendSMSChoreo.addInput("To", RECIPIENT_NUMBER);
2013-06-28 11:08:56 +02:00
// finally, the text of the message to send
2013-07-08 15:09:09 +02:00
SendSMSChoreo.addInput("Body", "Hey, there! This is a message from your Arduino Yun!");
// tell the Process to run and wait for the results. The
// return code (returnCode) will tell us whether the Temboo client
2013-06-28 11:08:56 +02:00
// was able to send our request to the Temboo servers
2013-07-03 09:02:59 +02:00
unsigned int returnCode = SendSMSChoreo.run();
2013-06-28 11:08:56 +02:00
// a return code of zero (0) means everything worked
2013-07-03 09:02:59 +02:00
if (returnCode == 0) {
Serial.println("Success! SMS sent!");
2013-06-28 11:08:56 +02:00
} else {
// a non-zero return code means there was an error
// read and print the error message
while (SendSMSChoreo.available()) {
2013-07-03 09:02:59 +02:00
char c = SendSMSChoreo.read();
Serial.print(c);
2013-06-28 11:08:56 +02:00
}
}
2013-06-28 11:08:56 +02:00
SendSMSChoreo.close();
// set the flag indicatine we've tried once.
attempted = true;
2013-06-28 11:08:56 +02:00
}
}
/*
IMPORTANT NOTE: TembooAccount.h:
2013-07-03 09:02:59 +02:00
TembooAccount.h is a file referenced by this sketch that contains your Temboo account information.
You'll need to edit the placeholder version of TembooAccount.h included with this example sketch,
by inserting your own Temboo account name and app key information. The contents of the file should
look like:
2013-06-28 11:08:56 +02:00
#define TEMBOO_ACCOUNT "myTembooAccountName" // your Temboo account name
2013-06-28 11:08:56 +02:00
#define TEMBOO_APP_KEY_NAME "myFirstApp" // your Temboo app key name
#define TEMBOO_APP_KEY "xxx-xxx-xxx-xx-xxx" // your Temboo app key
You can find your Temboo App Key information on the Temboo website,
2013-06-28 11:08:56 +02:00
under My Account > Application Keys
2013-07-03 09:02:59 +02:00
The same TembooAccount.h file settings can be used for all Temboo SDK sketches.
Keeping your account information in a separate file means you can share the main .ino file without worrying
2013-07-09 20:07:54 +02:00
that you forgot to delete your credentials.
2013-07-03 09:02:59 +02:00
*/