Skip to content

Commit 25747e3

Browse files
author
Federico Fissore
committed
Merge branch 'ide-1.5.x' into ide-1.5.x-avr-toolchain-gcc-4.8.1
2 parents 30a58cd + b2500b3 commit 25747e3

File tree

15 files changed

+692
-358
lines changed

15 files changed

+692
-358
lines changed

Diff for: libraries/Bridge/examples/Temboo/ControlBySMS/ControlBySMS.ino

+59-59
Original file line numberDiff line numberDiff line change
@@ -8,26 +8,26 @@
88
99
Check out the latest Arduino & Temboo examples and support docs at http://www.temboo.com/arduino
1010
11-
A Temboo account and application key are necessary to run all Temboo examples.
12-
If you don't already have one, you can register for a free Temboo account at
11+
A Temboo account and application key are necessary to run all Temboo examples.
12+
If you don't already have one, you can register for a free Temboo account at
1313
http://www.temboo.com
1414
15-
Since this sketch uses Twilio to retrieve the SMS, you'll also need a valid
15+
Since this sketch uses Twilio to retrieve the SMS, you'll also need a valid
1616
Twilio account. You can create one for free at https://www.twilio.com.
17-
18-
The sketch needs your Twilio Account SID and Auth Token you get when you
19-
register with Twilio. Make sure to use the Account SID and Auth Token from
17+
18+
The sketch needs your Twilio Account SID and Auth Token you get when you
19+
register with Twilio. Make sure to use the Account SID and Auth Token from
2020
your Twilio Dashboard (not your test credentials from the Dev Tools panel).
2121
2222
Normally, Twilio expects to contact a web site you provide to get a response
23-
when an SMS message is received for your Twilio number. In this case, we
23+
when an SMS message is received for your Twilio number. In this case, we
2424
don't want to send any response (and we don't want to have to set up a web
2525
site just to receive SMS messages.) You can use a URL that Twilio provides
2626
for this purpose. When a message is received and sent to the Twilio "twimlets"
2727
URL, it returns a code meaning "no response required." To set this up:
2828
2929
1. Log in to your Twilio account and go to this URL:
30-
30+
3131
https://www.twilio.com/user/account/phone-numbers/incoming
3232
3333
2. Select the Twilio number you want to receive SMS messages at.
@@ -40,22 +40,22 @@
4040
4141
https://www.twilio.com/help/faq/sms/how-can-i-receive-sms-messages-without-responding
4242
43-
4. Click the "Save Changes" button at the bottom of the page.
43+
4. Click the "Save Changes" button at the bottom of the page.
4444
4545
Your account will now receive SMS messages, but won't send any responses.
4646
4747
This example assumes basic familiarity with Arduino sketches, and that your Yun is connected
4848
to the Internet.
4949
5050
Looking for another API? We've got over 100 in our Library!
51-
51+
5252
This example code is in the public domain.
5353
*/
5454

5555
#include <Bridge.h>
5656
#include <Temboo.h>
5757
#include "TembooAccount.h" // contains Temboo account information
58-
// as described in the footer comment below
58+
// as described in the footer comment below
5959

6060

6161

@@ -85,7 +85,7 @@ unsigned long lastSMSCheckTime = -SMS_CHECK_PERIOD;
8585
// (we only need to process newer messages)
8686
String lastSid;
8787

88-
// we'll be turning the LED built in to the Yun on and off
88+
// we'll be turning the LED built in to the Yun on and off
8989
// to simulate controlling some device. That LED is on pin 13.
9090
int LED_PIN = 13;
9191

@@ -98,7 +98,7 @@ void setup() {
9898

9999
// for debugging, wait until a serial console is connected
100100
delay(4000);
101-
while (!Serial);
101+
while(!Serial);
102102

103103
// tell the board to treat the LED pin as an output.
104104
pinMode(LED_PIN, OUTPUT);
@@ -109,7 +109,7 @@ void setup() {
109109
// initialize the connection to the Linino processor.
110110
Bridge.begin();
111111

112-
// Twilio will report old SMS messages. We want to
112+
// Twilio will report old SMS messages. We want to
113113
// ignore any existing control messages when we start.
114114
Serial.println("Ignoring any existing control messages...");
115115
checkForMessages(true);
@@ -124,15 +124,15 @@ void loop()
124124

125125
// see if it's time to check for new SMS messages.
126126
if (now - lastSMSCheckTime >= SMS_CHECK_PERIOD) {
127-
127+
128128
// it's time to check for new messages
129129
// save this time so we know when to check next
130130
lastSMSCheckTime = now;
131-
131+
132132
if (numRuns <= maxRuns) {
133133
Serial.println("Checking for new SMS messages - Run #" + String(numRuns++));
134-
135-
// execute the choreo and don't ignore control messages.
134+
135+
// execute the choreo and don't ignore control messages.
136136
checkForMessages(false);
137137
} else {
138138
Serial.println("Already ran " + String(maxRuns) + " times.");
@@ -145,7 +145,7 @@ This function executes the Twilio > SMSMessages > ListMessages choreo
145145
and processes the results.
146146
147147
If ignoreCommands is 'true', this function will read and process messages
148-
updating 'lastSid', but will not actually take any action on any commands
148+
updating 'lastSid', but will not actually take any action on any commands
149149
found. This is so we can ignore any old control messages when we start.
150150
151151
If ignoreCommands is 'false', control messages WILL be acted on.
@@ -156,7 +156,7 @@ void checkForMessages(bool ignoreCommands) {
156156
TembooChoreo ListMessagesChoreo;
157157

158158
ListMessagesChoreo.begin();
159-
159+
160160
// set Temboo account credentials
161161
ListMessagesChoreo.setAccountName(TEMBOO_ACCOUNT);
162162
ListMessagesChoreo.setAppKeyName(TEMBOO_APP_KEY_NAME);
@@ -166,45 +166,45 @@ void checkForMessages(bool ignoreCommands) {
166166
ListMessagesChoreo.setChoreo("/Library/Twilio/SMSMessages/ListMessages");
167167

168168
// set the choreo inputs
169-
// see https://www.temboo.com/library/Library/Twilio/SMSMessages/ListMessages/
169+
// see https://www.temboo.com/library/Library/Twilio/SMSMessages/ListMessages/
170170
// for complete details about the inputs for this Choreo
171171

172172
// the first input is a your Twilio AccountSID
173173
ListMessagesChoreo.addInput("AccountSID", TWILIO_ACCOUNT_SID);
174-
174+
175175
// next is your Twilio Auth Token
176176
ListMessagesChoreo.addInput("AuthToken", TWILIO_AUTH_TOKEN);
177177

178178
// we only want to know about messages sent from our designated phone number
179179
ListMessagesChoreo.addInput("From", FROM_PHONE_NUMBER);
180180

181181
// Twilio can return information about up to 1000 messages at a time.
182-
// we're only interested in the 3 most recent ones. Note that if
183-
// this account receives lots of messages in quick succession,
182+
// we're only interested in the 3 most recent ones. Note that if
183+
// this account receives lots of messages in quick succession,
184184
// (more than 3 per minute in this case), we might miss some control
185-
// messages. But if we request too many messages, we might run out of
185+
// messages. But if we request too many messages, we might run out of
186186
// memory on the Arduino side of the Yun.
187187
ListMessagesChoreo.addInput("PageSize", "3");
188188

189-
// We want the response in XML format to process with our
189+
// We want the response in XML format to process with our
190190
// XPath output filters.
191191
ListMessagesChoreo.addInput("ResponseFormat", "xml");
192192

193-
// we don't want everything from the output, just the
193+
// we don't want everything from the output, just the
194194
// message IDs (the Sids) and the message texts
195195
ListMessagesChoreo.addOutputFilter("sid", "Sid", "Response");
196196
ListMessagesChoreo.addOutputFilter("text", "Body", "Response");
197197

198-
// tell the Choreo to run and wait for the results. The
199-
// return code (returnCode) will tell us whether the Temboo client
198+
// tell the Choreo to run and wait for the results. The
199+
// return code (returnCode) will tell us whether the Temboo client
200200
// was able to send our request to the Temboo servers
201201
unsigned int returnCode = ListMessagesChoreo.run();
202202

203203
// a return code of zero (0) means success
204204
if (returnCode == 0) {
205205

206206
// Need a string to hold the list of message IDs.
207-
String messageSids;
207+
String messageSids;
208208

209209
// Need a string to hold the texts of the messages.
210210
String messageTexts;
@@ -214,8 +214,8 @@ void checkForMessages(bool ignoreCommands) {
214214
// lists containing the Sids and texts of the messages
215215
// from our designated phone number.
216216

217-
while (ListMessagesChoreo.available()) {
218-
217+
while(ListMessagesChoreo.available()) {
218+
219219
// output names are terminated with '\x1F' characters.
220220
String name = ListMessagesChoreo.readStringUntil('\x1F');
221221
name.trim();
@@ -236,46 +236,46 @@ void checkForMessages(bool ignoreCommands) {
236236

237237
// done reading output, close the Choreo to free up resources.
238238
ListMessagesChoreo.close();
239-
240-
// parse the comma delimited lists of messages and Sids
239+
240+
// parse the comma delimited lists of messages and Sids
241241
processMessages(messageTexts, messageSids, ignoreCommands);
242242

243243
} else {
244244
// a non-zero return code means there was an error
245245
// read and print the error message
246-
while (ListMessagesChoreo.available()) {
246+
while(ListMessagesChoreo.available()) {
247247
char c = ListMessagesChoreo.read();
248248
Serial.print(c);
249249
}
250250
}
251251
}
252252

253-
/*
253+
/*
254254
This function processes the lists of message texts and Sids.
255-
If a message contains a comma as part of the
255+
If a message contains a comma as part of the
256256
message text, that message will be enclosed in double quotes
257257
(") in the list. Example:
258258
259259
A message,"Hey, now",Another message text
260260
261261
If the message contains double quotes, it will be enclosed in
262-
double quotes AND the internal quotes will be doubled.
262+
double quotes AND the internal quotes will be doubled.
263263
Example:
264264
265265
"Hi ""Sam"" the man", Led on
266266
267267
NOTE! We are assuming that Twilio returns more recent messages
268-
first. This isn't officially documented by Twilio, but we've
268+
first. This isn't officially documented by Twilio, but we've
269269
not seen any other case.
270270
271271
'messageTexts' is a String containing a comma separated list of
272272
message texts with commas and quotes escaped as described above.
273273
274-
'messageSids' is a String containing a comma separated list of
274+
'messageSids' is a String containing a comma separated list of
275275
message Sids. Sids should not contain embedded commas or quotes.
276276
277-
'ignoreCommands' is a boolean. 'true' means and control messages
278-
will not be acted upon. 'false' means control messages will be
277+
'ignoreCommands' is a boolean. 'true' means and control messages
278+
will not be acted upon. 'false' means control messages will be
279279
acted upon in the usual way.
280280
*/
281281
void processMessages(String messageTexts, String messageSids, bool ignoreCommands) {
@@ -297,14 +297,14 @@ void processMessages(String messageTexts, String messageSids, bool ignoreCommand
297297
// find the start of the next item in the list
298298
i = messageSids.indexOf(',', sidsStart);
299299
if (i >= 0) {
300-
300+
301301
//extract a single Sid from the list.
302302
sid = messageSids.substring(sidsStart, i);
303303
sidsStart = i + 1;
304304

305-
// find the start of the next text in the list.
305+
// find the start of the next text in the list.
306306
// Note that we have to be prepared to handle embedded
307-
// quotes and commans in the message texts.
307+
// quotes and commans in the message texts.
308308
// The standard Arduino String class doesn't handle
309309
// this, so we have to write our own function to do it.
310310
i = quotedIndexOf(messageTexts, ',', textsStart);
@@ -314,12 +314,12 @@ void processMessages(String messageTexts, String messageSids, bool ignoreCommand
314314
text = messageTexts.substring(textsStart, i);
315315
textsStart = i + 1;
316316

317-
// process the Sid and text to see if it's a
317+
// process the Sid and text to see if it's a
318318
// control message.
319319
ledUpdated = processMessage(sid, text, ignoreCommands);
320320
}
321321
} else {
322-
322+
323323
// the last item in the lists won't have a comma at the end,
324324
// so we have to handle them specially.
325325
// Since we know this is the last item, we can just
@@ -333,9 +333,9 @@ void processMessages(String messageTexts, String messageSids, bool ignoreCommand
333333

334334
// keep going until either we run out of list items
335335
// or we run into a message we processed on a previous run.
336-
} while ((i >= 0) && (sid != lastSid));
337-
338-
// print what we've found to the serial monitor,
336+
} while ((i >=0) && (sid != lastSid));
337+
338+
// print what we've found to the serial monitor,
339339
// just so we can see what's going on.
340340
if (sid == lastSid) {
341341
if (ledUpdated)
@@ -359,25 +359,25 @@ A message with the text "LED ON" turns the LED on.
359359
A message with the text "LED OFF" turns the LED off.
360360
(Case is ignored.)
361361
362-
If 'ignoreCommands' is true, the actions described above will NOT
363-
take place.
362+
If 'ignoreCommands' is true, the actions described above will NOT
363+
take place.
364364
365-
It also updates the 'lastSid' global variable when
365+
It also updates the 'lastSid' global variable when
366366
a control message is processed.
367367
368368
It returns 'true' if the message was a control message, and
369369
'false' if it wasn't or if we've already processed this message.
370370
*/
371371
bool processMessage(String sid, String text, bool ignoreCommands) {
372-
372+
373373
// a flag to indicate whether this was a control message or not
374374
bool ledUpdated = false;
375375

376376
// if we haven't already processed this message
377377
if (sid != lastSid) {
378378

379379
if (text.equalsIgnoreCase("LED ON")) {
380-
380+
381381
if (!ignoreCommands) {
382382
//turn on the LED
383383
digitalWrite(LED_PIN, HIGH);
@@ -394,7 +394,7 @@ bool processMessage(String sid, String text, bool ignoreCommands) {
394394
}
395395

396396
// If the LED state was updated, remember the Sid if this message.
397-
if (ledUpdated)
397+
if (ledUpdated)
398398
lastSid = sid;
399399
}
400400
return ledUpdated;
@@ -428,16 +428,16 @@ int quotedIndexOf(String s, char delim, int start) {
428428
by inserting your own Temboo account name and app key information. The contents of the file should
429429
look like:
430430
431-
#define TEMBOO_ACCOUNT "myTembooAccountName" // your Temboo account name
431+
#define TEMBOO_ACCOUNT "myTembooAccountName" // your Temboo account name
432432
#define TEMBOO_APP_KEY_NAME "myFirstApp" // your Temboo app key name
433433
#define TEMBOO_APP_KEY "xxx-xxx-xxx-xx-xxx" // your Temboo app key
434434
435-
You can find your Temboo App Key information on the Temboo website,
435+
You can find your Temboo App Key information on the Temboo website,
436436
under My Account > Application Keys
437437
438438
The same TembooAccount.h file settings can be used for all Temboo SDK sketches.
439439
440-
Keeping your account information in a separate file means you can save it once,
440+
Keeping your account information in a separate file means you can save it once,
441441
then just distribute the main .ino file without worrying that you forgot to delete your credentials.
442442
*/
443443

0 commit comments

Comments
 (0)