Skip to content

Commit 8b0fcbe

Browse files
author
Federico Fissore
committed
Temboo: updated bundled library
1 parent 4cf77cd commit 8b0fcbe

32 files changed

+82
-70
lines changed

libraries/Temboo/README.adoc

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,16 @@ This library allows an Arduino Yun to connect to the Temboo service.
44

55
== License ==
66

7-
Copyright (c) Arduino LLC. All right reserved.
8-
9-
This library is free software; you can redistribute it and/or
10-
modify it under the terms of the GNU Lesser General Public
11-
License as published by the Free Software Foundation; either
12-
version 2.1 of the License, or (at your option) any later version.
13-
14-
This library is distributed in the hope that it will be useful,
15-
but WITHOUT ANY WARRANTY; without even the implied warranty of
16-
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17-
Lesser General Public License for more details.
18-
19-
You should have received a copy of the GNU Lesser General Public
20-
License along with this library; if not, write to the Free Software
21-
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
7+
Copyright 2015, Temboo Inc.
8+
9+
Licensed under the Apache License, Version 2.0 (the "License");
10+
you may not use this file except in compliance with the License.
11+
You may obtain a copy of the License at
12+
13+
http://www.apache.org/licenses/LICENSE-2.0
14+
15+
Unless required by applicable law or agreed to in writing,
16+
software distributed under the License is distributed on an
17+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
18+
either express or implied. See the License for the specific
19+
language governing permissions and limitations under the License.

libraries/Temboo/library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@ paragraph=Use this library to connect your Arduino board to Temboo, making it si
66
category=Communication
77
url=http://www.temboo.com/arduino
88
architectures=*
9-
version=1.1.1
9+
version=1.1.2
1010
core-dependencies=arduino (>=1.5.0)

libraries/Temboo/src/Temboo.cpp

Lines changed: 35 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#
44
# Temboo Arduino library
55
#
6-
# Copyright 2014, Temboo Inc.
6+
# Copyright 2015, Temboo Inc.
77
#
88
# Licensed under the Apache License, Version 2.0 (the "License");
99
# you may not use this file except in compliance with the License.
@@ -92,6 +92,8 @@ void TembooChoreo::setSettingsFileToRead(const String& filePath) {
9292
#include "utility/TembooSession.h"
9393

9494
static const char HTTP_CODE[] PROGMEM = "HTTP_CODE\x0A\x1F";
95+
static char HTTP_EOL[] = "\r\n";
96+
static char HTTP_EOH[] = "\r\n\r\n";
9597

9698
TembooChoreo::TembooChoreo(Client& client) : m_client(client) {
9799
m_accountName = NULL;
@@ -171,7 +173,6 @@ void TembooChoreo::setProfile(const char* profileName) {
171173
}
172174

173175

174-
175176
void TembooChoreo::addInput(const String& inputName, const String& inputValue) {
176177
m_inputs.put(inputName.c_str(), inputValue.c_str());
177178
}
@@ -233,66 +234,76 @@ void TembooChoreo::addOutputFilter(const String& outputName, const String& filte
233234

234235

235236
int TembooChoreo::run() {
236-
return run(INADDR_NONE, 80);
237+
return run(INADDR_NONE, 80, TEMBOO_CHOREO_DEFAULT_TIMEOUT_SECS);
237238
}
238239

240+
int TembooChoreo::run(uint16_t timeoutSecs) {
241+
return run(INADDR_NONE, 80, timeoutSecs);
242+
}
239243

240-
int TembooChoreo::run(IPAddress addr, uint16_t port) {
241-
244+
int TembooChoreo::run(IPAddress addr, uint16_t port, uint16_t timeoutSecs) {
245+
242246
m_nextChar = NULL;
243-
247+
244248
if (m_accountName == NULL || *m_accountName == '\0') {
245249
return TEMBOO_ERROR_ACCOUNT_MISSING;
246250
}
247-
251+
248252
if (m_path == NULL || *m_path == '\0') {
249253
return TEMBOO_ERROR_CHOREO_MISSING;
250254
}
251-
255+
252256
if (m_appKeyName == NULL || *m_appKeyName == '\0') {
253257
return TEMBOO_ERROR_APPKEY_NAME_MISSING;
254258
}
255-
259+
256260
if (m_appKeyValue == NULL || *m_appKeyValue == '\0') {
257261
return TEMBOO_ERROR_APPKEY_MISSING;
258262
}
259-
260-
263+
261264
TembooSession session(m_client, addr, port);
262265
uint16_t httpCode = 0;
263266

264267
for (int i = 0; i < 2; i++) {
268+
unsigned long timeoutBeginSecs = session.getTime();
265269
if (0 != session.executeChoreo(m_accountName, m_appKeyName, m_appKeyValue, m_path, m_inputs, m_outputs, m_preset)) {
266270
httpCode = 0;
267271
break;
268272
}
269-
273+
270274
while(!m_client.available()) {
275+
if((session.getTime() - timeoutBeginSecs) >= timeoutSecs) {
276+
TEMBOO_TRACELN("Receive time out");
277+
m_client.stop();
278+
return TEMBOO_ERROR_STREAM_TIMEOUT;
279+
}
271280
if (!m_client.connected()) {
272281
TEMBOO_TRACELN("Disconnected");
273282
return TEMBOO_ERROR_HTTP_ERROR;
274283
}
275284
delay(10);
276285
}
277-
278-
if (!m_client.find("HTTP/1.1 ")) {
286+
if (!m_client.findUntil("HTTP/1.", HTTP_EOL)) {
279287
TEMBOO_TRACELN("No HTTP");
280288
return TEMBOO_ERROR_HTTP_ERROR;
281289
}
282-
290+
//Don't care if the next byte is a '1' or a '0'
291+
m_client.read();
292+
293+
//Read the HTTP status code
283294
httpCode = (uint16_t)m_client.parseInt();
284-
285-
// We expect HTTP response codes to be <= 599, but
295+
296+
// We expect HTTP response codes to be <= 599, but
286297
// we need to be prepared for anything.
287298
if (httpCode >= 600) {
288299
TEMBOO_TRACELN("Invalid HTTP");
289300
httpCode = 0;
290301
}
291-
302+
292303
// if we get an auth error AND there was an x-temboo-time header,
293304
// update the session timeOffset
294305
if ((httpCode == 401) && (i == 0)) {
295-
if (m_client.find("x-temboo-time:")) {
306+
if (m_client.findUntil("x-temboo-time:", HTTP_EOH)) {
296307
TembooSession::setTime((unsigned long)m_client.parseInt());
297308
while(m_client.available()) {
298309
m_client.read();
@@ -303,20 +314,20 @@ int TembooChoreo::run(IPAddress addr, uint16_t port) {
303314
break;
304315
}
305316
}
306-
317+
307318
uint16toa(httpCode, m_httpCodeStr);
308319
strcat_P(m_httpCodeStr, PSTR("\x0A\x1E"));
309320
m_nextState = START;
310321
m_nextChar = HTTP_CODE;
311-
322+
312323
if (httpCode < 200 || httpCode >= 300) {
313324
return TEMBOO_ERROR_HTTP_ERROR;
314325
}
315-
316-
if (!m_client.find("\x0D\x0A\x0D\x0A")) {
326+
327+
if (!m_client.find(HTTP_EOH)) {
317328
return TEMBOO_ERROR_HTTP_ERROR;
318329
}
319-
330+
320331
return TEMBOO_ERROR_OK;
321332
}
322333

libraries/Temboo/src/Temboo.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#
44
# Temboo Arduino library
55
#
6-
# Copyright 2014, Temboo Inc.
6+
# Copyright 2015, Temboo Inc.
77
#
88
# Licensed under the Apache License, Version 2.0 (the "License");
99
# you may not use this file except in compliance with the License.
@@ -69,6 +69,8 @@ class TembooChoreo : public Process {
6969
#define TEMBOO_ERROR_APPKEY_NAME_MISSING (205)
7070
#define TEMBOO_ERROR_APPKEY_MISSING (207)
7171
#define TEMBOO_ERROR_HTTP_ERROR (223)
72+
#define TEMBOO_ERROR_STREAM_TIMEOUT (225)
73+
#define TEMBOO_CHOREO_DEFAULT_TIMEOUT_SECS (901) //15 minutes and 1 second
7274

7375
class TembooChoreo : public Stream {
7476
public:
@@ -135,7 +137,8 @@ class TembooChoreo : public Stream {
135137

136138
// run the choreo on the Temboo server at the given IP address and port
137139
// (used only when instructed by Temboo customer support.)
138-
int run(IPAddress addr, uint16_t port);
140+
int run(uint16_t timeoutSecs);
141+
int run(IPAddress addr, uint16_t port, uint16_t timeoutSecs);
139142

140143
void close();
141144

libraries/Temboo/src/utility/BaseFormatter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#
44
# Temboo Arduino library
55
#
6-
# Copyright 2014, Temboo Inc.
6+
# Copyright 2015, Temboo Inc.
77
#
88
# Licensed under the Apache License, Version 2.0 (the "License");
99
# you may not use this file except in compliance with the License.

libraries/Temboo/src/utility/BaseFormatter.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#
44
# Temboo Arduino library
55
#
6-
# Copyright 2014, Temboo Inc.
6+
# Copyright 2015, Temboo Inc.
77
#
88
# Licensed under the Apache License, Version 2.0 (the "License");
99
# you may not use this file except in compliance with the License.

libraries/Temboo/src/utility/ChoreoInput.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#
44
# Temboo Arduino library
55
#
6-
# Copyright 2014, Temboo Inc.
6+
# Copyright 2015, Temboo Inc.
77
#
88
# Licensed under the Apache License, Version 2.0 (the "License");
99
# you may not use this file except in compliance with the License.

libraries/Temboo/src/utility/ChoreoInput.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#
44
# Temboo Arduino library
55
#
6-
# Copyright 2014, Temboo Inc.
6+
# Copyright 2015, Temboo Inc.
77
#
88
# Licensed under the Apache License, Version 2.0 (the "License");
99
# you may not use this file except in compliance with the License.

libraries/Temboo/src/utility/ChoreoInputFormatter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#
44
# Temboo Arduino library
55
#
6-
# Copyright 2014, Temboo Inc.
6+
# Copyright 2015, Temboo Inc.
77
#
88
# Licensed under the Apache License, Version 2.0 (the "License");
99
# you may not use this file except in compliance with the License.

libraries/Temboo/src/utility/ChoreoInputFormatter.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#
44
# Temboo Arduino library
55
#
6-
# Copyright 2014, Temboo Inc.
6+
# Copyright 2015, Temboo Inc.
77
#
88
# Licensed under the Apache License, Version 2.0 (the "License");
99
# you may not use this file except in compliance with the License.

0 commit comments

Comments
 (0)