1 | /*
|
---|
2 | SendAnSMS
|
---|
3 |
|
---|
4 | Demonstrates sending an SMS via Twilio using Temboo from an Arduino Y炭n.
|
---|
5 |
|
---|
6 | Check out the latest Arduino & Temboo examples and support docs at http://www.temboo.com/arduino
|
---|
7 |
|
---|
8 | A Temboo account and application key are necessary to run all Temboo examples.
|
---|
9 | If you don't already have one, you can register for a free Temboo account at
|
---|
10 | http://www.temboo.com
|
---|
11 |
|
---|
12 | Since this sketch uses Twilio to send the SMS, you'll also need a valid
|
---|
13 | Twilio account. You can create one for free at https://www.twilio.com.
|
---|
14 |
|
---|
15 | The sketch needs your Twilio phone number, along with
|
---|
16 | the Account SID and Auth Token you get when you register with Twilio.
|
---|
17 | Make sure to use the Account SID and Auth Token from your Twilio Dashboard
|
---|
18 | (not your test credentials from the Dev Tools panel).
|
---|
19 |
|
---|
20 | Also note that if you're using a free Twilio account, you'll need to verify
|
---|
21 | the phone number to which messages are being sent by going to twilio.com and following
|
---|
22 | the instructions under the "Numbers > Verified Caller IDs" tab (this restriction
|
---|
23 | doesn't apply if you have a paid Twilio account).
|
---|
24 |
|
---|
25 | This example assumes basic familiarity with Arduino sketches, and that your Y炭n is connected
|
---|
26 | to the Internet.
|
---|
27 |
|
---|
28 | Looking for another API to use with your Arduino Y炭n? We've got over 100 in our Library!
|
---|
29 |
|
---|
30 | This example code is in the public domain.
|
---|
31 | */
|
---|
32 |
|
---|
33 | #include <Bridge.h>
|
---|
34 | #include <Temboo.h>
|
---|
35 | #include "TembooAccount.h" // contains Temboo account information
|
---|
36 | // as described in the footer comment below
|
---|
37 |
|
---|
38 |
|
---|
39 |
|
---|
40 | /*** SUBSTITUTE YOUR VALUES BELOW: ***/
|
---|
41 |
|
---|
42 | // Note that for additional security and reusability, you could
|
---|
43 | // use #define statements to specify these values in a .h file.
|
---|
44 |
|
---|
45 | // the Account SID from your Twilio account
|
---|
46 | const String TWILIO_ACCOUNT_SID = "xxxxxxxxxx";
|
---|
47 |
|
---|
48 | // the Auth Token from your Twilio account
|
---|
49 | const String TWILIO_AUTH_TOKEN = "xxxxxxxxxx";
|
---|
50 |
|
---|
51 | // your Twilio phone number, e.g., "+1 555-222-1212"
|
---|
52 | const String TWILIO_NUMBER = "xxxxxxxxxx";
|
---|
53 |
|
---|
54 | // the number to which the SMS should be sent, e.g., "+1 555-222-1212"
|
---|
55 | const String RECIPIENT_NUMBER = "xxxxxxxxxx";
|
---|
56 |
|
---|
57 | // a flag to indicate whether we've attempted to send the SMS yet or not
|
---|
58 | boolean attempted = false;
|
---|
59 |
|
---|
60 | void setup() {
|
---|
61 | Serial.begin(9600);
|
---|
62 |
|
---|
63 | // for debugging, wait until a serial console is connected
|
---|
64 | delay(4000);
|
---|
65 | while(!Serial);
|
---|
66 |
|
---|
67 | Bridge.begin();
|
---|
68 | }
|
---|
69 |
|
---|
70 | void loop()
|
---|
71 | {
|
---|
72 | // only try to send the SMS if we haven't already sent it successfully
|
---|
73 | if (!attempted) {
|
---|
74 |
|
---|
75 | Serial.println("Running SendAnSMS...");
|
---|
76 |
|
---|
77 | // we need a Process object to send a Choreo request to Temboo
|
---|
78 | TembooChoreo SendSMSChoreo;
|
---|
79 |
|
---|
80 | // invoke the Temboo client
|
---|
81 | // NOTE that the client must be reinvoked and repopulated with
|
---|
82 | // appropriate arguments each time its run() method is called.
|
---|
83 | SendSMSChoreo.begin();
|
---|
84 |
|
---|
85 | // set Temboo account credentials
|
---|
86 | SendSMSChoreo.setAccountName(TEMBOO_ACCOUNT);
|
---|
87 | SendSMSChoreo.setAppKeyName(TEMBOO_APP_KEY_NAME);
|
---|
88 | SendSMSChoreo.setAppKey(TEMBOO_APP_KEY);
|
---|
89 |
|
---|
90 | // identify the Temboo Library choreo to run (Twilio > SMSMessages > SendSMS)
|
---|
91 | SendSMSChoreo.setChoreo("/Library/Twilio/SMSMessages/SendSMS");
|
---|
92 |
|
---|
93 | // set the required choreo inputs
|
---|
94 | // see https://www.temboo.com/library/Library/Twilio/SMSMessages/SendSMS/
|
---|
95 | // for complete details about the inputs for this Choreo
|
---|
96 |
|
---|
97 | // the first input is a your AccountSID
|
---|
98 | SendSMSChoreo.addInput("AccountSID", TWILIO_ACCOUNT_SID);
|
---|
99 |
|
---|
100 | // next is your Auth Token
|
---|
101 | SendSMSChoreo.addInput("AuthToken", TWILIO_AUTH_TOKEN);
|
---|
102 |
|
---|
103 | // next is your Twilio phone number
|
---|
104 | SendSMSChoreo.addInput("From", TWILIO_NUMBER);
|
---|
105 |
|
---|
106 | // next, what number to send the SMS to
|
---|
107 | SendSMSChoreo.addInput("To", RECIPIENT_NUMBER);
|
---|
108 |
|
---|
109 | // finally, the text of the message to send
|
---|
110 | SendSMSChoreo.addInput("Body", "Hey, there! This is a message from your Arduino Yun!");
|
---|
111 |
|
---|
112 | // tell the Process to run and wait for the results. The
|
---|
113 | // return code (returnCode) will tell us whether the Temboo client
|
---|
114 | // was able to send our request to the Temboo servers
|
---|
115 | unsigned int returnCode = SendSMSChoreo.run();
|
---|
116 |
|
---|
117 | // a return code of zero (0) means everything worked
|
---|
118 | if (returnCode == 0) {
|
---|
119 | Serial.println("Success! SMS sent!");
|
---|
120 | } else {
|
---|
121 | // a non-zero return code means there was an error
|
---|
122 | // read and print the error message
|
---|
123 | while (SendSMSChoreo.available()) {
|
---|
124 | char c = SendSMSChoreo.read();
|
---|
125 | Serial.print(c);
|
---|
126 | }
|
---|
127 | }
|
---|
128 | SendSMSChoreo.close();
|
---|
129 |
|
---|
130 | // set the flag indicatine we've tried once.
|
---|
131 | attempted=true;
|
---|
132 | }
|
---|
133 | }
|
---|
134 |
|
---|
135 | /*
|
---|
136 | IMPORTANT NOTE: TembooAccount.h:
|
---|
137 |
|
---|
138 | TembooAccount.h is a file referenced by this sketch that contains your Temboo account information.
|
---|
139 | You'll need to edit the placeholder version of TembooAccount.h included with this example sketch,
|
---|
140 | by inserting your own Temboo account name and app key information. The contents of the file should
|
---|
141 | look like:
|
---|
142 |
|
---|
143 | #define TEMBOO_ACCOUNT "myTembooAccountName" // your Temboo account name
|
---|
144 | #define TEMBOO_APP_KEY_NAME "myFirstApp" // your Temboo app key name
|
---|
145 | #define TEMBOO_APP_KEY "xxx-xxx-xxx-xx-xxx" // your Temboo app key
|
---|
146 |
|
---|
147 | You can find your Temboo App Key information on the Temboo website,
|
---|
148 | under My Account > Application Keys
|
---|
149 |
|
---|
150 | The same TembooAccount.h file settings can be used for all Temboo SDK sketches.
|
---|
151 |
|
---|
152 | Keeping your account information in a separate file means you can share the main .ino file without worrying
|
---|
153 | that you forgot to delete your credentials.
|
---|
154 | */
|
---|