From 2fea76d255dbcdcb56ba30ecdf8d7a49510e39a2 Mon Sep 17 00:00:00 2001 From: kevinbuck-temboo Date: Tue, 7 Apr 2015 16:05:41 -0400 Subject: [PATCH 1/2] Version 1.1.2 update MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We’ve included support for HTTP1.0/1.1 responses. We’ve also included a timeout option for how long the Choreo can wait to receive data from the server --- library.properties | 2 +- src/Temboo.cpp | 57 +++++++++++++++++++++++++++------------------- src/Temboo.h | 5 +++- 3 files changed, 39 insertions(+), 25 deletions(-) diff --git a/library.properties b/library.properties index 22515c6..9b743a3 100644 --- a/library.properties +++ b/library.properties @@ -6,5 +6,5 @@ paragraph=Use this library to connect your Arduino board to Temboo, making it si category=Communication url=http://www.temboo.com/arduino architectures=* -version=1.1.1 +version=1.1.2 core-dependencies=arduino (>=1.5.0) diff --git a/src/Temboo.cpp b/src/Temboo.cpp index f7ddaf9..11b1788 100644 --- a/src/Temboo.cpp +++ b/src/Temboo.cpp @@ -92,6 +92,8 @@ void TembooChoreo::setSettingsFileToRead(const String& filePath) { #include "utility/TembooSession.h" static const char HTTP_CODE[] PROGMEM = "HTTP_CODE\x0A\x1F"; +static char HTTP_EOL[] = "\r\n"; +static char HTTP_EOH[] = "\r\n\r\n"; TembooChoreo::TembooChoreo(Client& client) : m_client(client) { m_accountName = NULL; @@ -171,7 +173,6 @@ void TembooChoreo::setProfile(const char* profileName) { } - void TembooChoreo::addInput(const String& inputName, const String& inputValue) { m_inputs.put(inputName.c_str(), inputValue.c_str()); } @@ -233,66 +234,76 @@ void TembooChoreo::addOutputFilter(const String& outputName, const String& filte int TembooChoreo::run() { - return run(INADDR_NONE, 80); + return run(INADDR_NONE, 80, TEMBOO_CHOREO_DEFAULT_TIMEOUT_SECS); } +int TembooChoreo::run(uint16_t timeoutSecs) { + return run(INADDR_NONE, 80, timeoutSecs); +} -int TembooChoreo::run(IPAddress addr, uint16_t port) { - +int TembooChoreo::run(IPAddress addr, uint16_t port, uint16_t timeoutSecs) { + m_nextChar = NULL; - + if (m_accountName == NULL || *m_accountName == '\0') { return TEMBOO_ERROR_ACCOUNT_MISSING; } - + if (m_path == NULL || *m_path == '\0') { return TEMBOO_ERROR_CHOREO_MISSING; } - + if (m_appKeyName == NULL || *m_appKeyName == '\0') { return TEMBOO_ERROR_APPKEY_NAME_MISSING; } - + if (m_appKeyValue == NULL || *m_appKeyValue == '\0') { return TEMBOO_ERROR_APPKEY_MISSING; } - - + TembooSession session(m_client, addr, port); uint16_t httpCode = 0; for (int i = 0; i < 2; i++) { + unsigned long timeoutBeginSecs = session.getTime(); if (0 != session.executeChoreo(m_accountName, m_appKeyName, m_appKeyValue, m_path, m_inputs, m_outputs, m_preset)) { httpCode = 0; break; } - + while(!m_client.available()) { + if((session.getTime() - timeoutBeginSecs) >= timeoutSecs) { + TEMBOO_TRACELN("Receive time out"); + m_client.stop(); + return TEMBOO_ERROR_STREAM_TIMEOUT; + } if (!m_client.connected()) { TEMBOO_TRACELN("Disconnected"); return TEMBOO_ERROR_HTTP_ERROR; } delay(10); } - - if (!m_client.find("HTTP/1.1 ")) { + if (!m_client.findUntil("HTTP/1.", HTTP_EOL)) { TEMBOO_TRACELN("No HTTP"); return TEMBOO_ERROR_HTTP_ERROR; } - + //Don't care if the next byte is a '1' or a '0' + m_client.read(); + + //Read the HTTP status code httpCode = (uint16_t)m_client.parseInt(); - - // We expect HTTP response codes to be <= 599, but + + // We expect HTTP response codes to be <= 599, but // we need to be prepared for anything. if (httpCode >= 600) { TEMBOO_TRACELN("Invalid HTTP"); httpCode = 0; } - + // if we get an auth error AND there was an x-temboo-time header, // update the session timeOffset if ((httpCode == 401) && (i == 0)) { - if (m_client.find("x-temboo-time:")) { + if (m_client.findUntil("x-temboo-time:", HTTP_EOH)) { TembooSession::setTime((unsigned long)m_client.parseInt()); while(m_client.available()) { m_client.read(); @@ -303,20 +314,20 @@ int TembooChoreo::run(IPAddress addr, uint16_t port) { break; } } - + uint16toa(httpCode, m_httpCodeStr); strcat_P(m_httpCodeStr, PSTR("\x0A\x1E")); m_nextState = START; m_nextChar = HTTP_CODE; - + if (httpCode < 200 || httpCode >= 300) { return TEMBOO_ERROR_HTTP_ERROR; } - - if (!m_client.find("\x0D\x0A\x0D\x0A")) { + + if (!m_client.find(HTTP_EOH)) { return TEMBOO_ERROR_HTTP_ERROR; } - + return TEMBOO_ERROR_OK; } diff --git a/src/Temboo.h b/src/Temboo.h index 3b1b7ec..fabef3d 100644 --- a/src/Temboo.h +++ b/src/Temboo.h @@ -69,6 +69,8 @@ class TembooChoreo : public Process { #define TEMBOO_ERROR_APPKEY_NAME_MISSING (205) #define TEMBOO_ERROR_APPKEY_MISSING (207) #define TEMBOO_ERROR_HTTP_ERROR (223) +#define TEMBOO_ERROR_STREAM_TIMEOUT (225) +#define TEMBOO_CHOREO_DEFAULT_TIMEOUT_SECS (901) //15 minutes and 1 second class TembooChoreo : public Stream { public: @@ -135,7 +137,8 @@ class TembooChoreo : public Stream { // run the choreo on the Temboo server at the given IP address and port // (used only when instructed by Temboo customer support.) - int run(IPAddress addr, uint16_t port); + int run(uint16_t timeoutSecs); + int run(IPAddress addr, uint16_t port, uint16_t timeoutSecs); void close(); From bf21cc03cec958a286f3f9e3e411f755ecad9db5 Mon Sep 17 00:00:00 2001 From: kevinbuck-temboo Date: Tue, 7 Apr 2015 16:14:01 -0400 Subject: [PATCH 2/2] Updated license information --- README.adoc | 28 +++++++++++++-------------- src/Temboo.cpp | 2 +- src/Temboo.h | 2 +- src/utility/BaseFormatter.cpp | 2 +- src/utility/BaseFormatter.h | 2 +- src/utility/ChoreoInput.cpp | 2 +- src/utility/ChoreoInput.h | 2 +- src/utility/ChoreoInputFormatter.cpp | 2 +- src/utility/ChoreoInputFormatter.h | 2 +- src/utility/ChoreoInputSet.cpp | 2 +- src/utility/ChoreoInputSet.h | 2 +- src/utility/ChoreoOutput.cpp | 2 +- src/utility/ChoreoOutput.h | 2 +- src/utility/ChoreoOutputFormatter.cpp | 2 +- src/utility/ChoreoOutputFormatter.h | 2 +- src/utility/ChoreoOutputSet.cpp | 2 +- src/utility/ChoreoOutputSet.h | 2 +- src/utility/ChoreoPreset.cpp | 2 +- src/utility/ChoreoPreset.h | 2 +- src/utility/ChoreoPresetFormatter.cpp | 2 +- src/utility/ChoreoPresetFormatter.h | 2 +- src/utility/DataFormatter.cpp | 2 +- src/utility/DataFormatter.h | 2 +- src/utility/TembooGlobal.c | 2 +- src/utility/TembooGlobal.h | 2 +- src/utility/TembooSession.cpp | 2 +- src/utility/TembooSession.h | 2 +- src/utility/tmbhmac.cpp | 2 +- src/utility/tmbhmac.h | 2 +- src/utility/tmbmd5.cpp | 2 +- src/utility/tmbmd5.h | 2 +- 31 files changed, 43 insertions(+), 45 deletions(-) diff --git a/README.adoc b/README.adoc index 155b6f6..ec74a12 100644 --- a/README.adoc +++ b/README.adoc @@ -4,18 +4,16 @@ This library allows an Arduino Yun to connect to the Temboo service. == License == -Copyright (c) Arduino LLC. All right reserved. - -This library is free software; you can redistribute it and/or -modify it under the terms of the GNU Lesser General Public -License as published by the Free Software Foundation; either -version 2.1 of the License, or (at your option) any later version. - -This library is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -Lesser General Public License for more details. - -You should have received a copy of the GNU Lesser General Public -License along with this library; if not, write to the Free Software -Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +Copyright 2015, Temboo Inc. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + +http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, +software distributed under the License is distributed on an +"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, +either express or implied. See the License for the specific +language governing permissions and limitations under the License. diff --git a/src/Temboo.cpp b/src/Temboo.cpp index 11b1788..f4eb85e 100644 --- a/src/Temboo.cpp +++ b/src/Temboo.cpp @@ -3,7 +3,7 @@ # # Temboo Arduino library # -# Copyright 2014, Temboo Inc. +# Copyright 2015, Temboo Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/src/Temboo.h b/src/Temboo.h index fabef3d..881fe48 100644 --- a/src/Temboo.h +++ b/src/Temboo.h @@ -3,7 +3,7 @@ # # Temboo Arduino library # -# Copyright 2014, Temboo Inc. +# Copyright 2015, Temboo Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/src/utility/BaseFormatter.cpp b/src/utility/BaseFormatter.cpp index b9b77db..1e575e2 100644 --- a/src/utility/BaseFormatter.cpp +++ b/src/utility/BaseFormatter.cpp @@ -3,7 +3,7 @@ # # Temboo Arduino library # -# Copyright 2014, Temboo Inc. +# Copyright 2015, Temboo Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/src/utility/BaseFormatter.h b/src/utility/BaseFormatter.h index d8886ad..3d44431 100644 --- a/src/utility/BaseFormatter.h +++ b/src/utility/BaseFormatter.h @@ -3,7 +3,7 @@ # # Temboo Arduino library # -# Copyright 2014, Temboo Inc. +# Copyright 2015, Temboo Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/src/utility/ChoreoInput.cpp b/src/utility/ChoreoInput.cpp index 00138b7..faf921d 100644 --- a/src/utility/ChoreoInput.cpp +++ b/src/utility/ChoreoInput.cpp @@ -3,7 +3,7 @@ # # Temboo Arduino library # -# Copyright 2014, Temboo Inc. +# Copyright 2015, Temboo Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/src/utility/ChoreoInput.h b/src/utility/ChoreoInput.h index 3e2b8b8..a23ca70 100644 --- a/src/utility/ChoreoInput.h +++ b/src/utility/ChoreoInput.h @@ -3,7 +3,7 @@ # # Temboo Arduino library # -# Copyright 2014, Temboo Inc. +# Copyright 2015, Temboo Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/src/utility/ChoreoInputFormatter.cpp b/src/utility/ChoreoInputFormatter.cpp index e70bd8a..a54c553 100644 --- a/src/utility/ChoreoInputFormatter.cpp +++ b/src/utility/ChoreoInputFormatter.cpp @@ -3,7 +3,7 @@ # # Temboo Arduino library # -# Copyright 2014, Temboo Inc. +# Copyright 2015, Temboo Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/src/utility/ChoreoInputFormatter.h b/src/utility/ChoreoInputFormatter.h index 78b2f97..8946c5d 100644 --- a/src/utility/ChoreoInputFormatter.h +++ b/src/utility/ChoreoInputFormatter.h @@ -3,7 +3,7 @@ # # Temboo Arduino library # -# Copyright 2014, Temboo Inc. +# Copyright 2015, Temboo Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/src/utility/ChoreoInputSet.cpp b/src/utility/ChoreoInputSet.cpp index 5257a16..09a9f1a 100644 --- a/src/utility/ChoreoInputSet.cpp +++ b/src/utility/ChoreoInputSet.cpp @@ -3,7 +3,7 @@ # # Temboo Arduino library # -# Copyright 2014, Temboo Inc. +# Copyright 2015, Temboo Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/src/utility/ChoreoInputSet.h b/src/utility/ChoreoInputSet.h index 4349049..123a38a 100644 --- a/src/utility/ChoreoInputSet.h +++ b/src/utility/ChoreoInputSet.h @@ -3,7 +3,7 @@ # # Temboo Arduino library # -# Copyright 2014, Temboo Inc. +# Copyright 2015, Temboo Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/src/utility/ChoreoOutput.cpp b/src/utility/ChoreoOutput.cpp index 63ede6b..63cdc5f 100644 --- a/src/utility/ChoreoOutput.cpp +++ b/src/utility/ChoreoOutput.cpp @@ -3,7 +3,7 @@ # # Temboo Arduino library # -# Copyright 2014, Temboo Inc. +# Copyright 2015, Temboo Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/src/utility/ChoreoOutput.h b/src/utility/ChoreoOutput.h index a026d95..844e8b5 100644 --- a/src/utility/ChoreoOutput.h +++ b/src/utility/ChoreoOutput.h @@ -3,7 +3,7 @@ # # Temboo Arduino library # -# Copyright 2014, Temboo Inc. +# Copyright 2015, Temboo Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/src/utility/ChoreoOutputFormatter.cpp b/src/utility/ChoreoOutputFormatter.cpp index a4b581b..53561cc 100644 --- a/src/utility/ChoreoOutputFormatter.cpp +++ b/src/utility/ChoreoOutputFormatter.cpp @@ -3,7 +3,7 @@ # # Temboo Arduino library # -# Copyright 2014, Temboo Inc. +# Copyright 2015, Temboo Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/src/utility/ChoreoOutputFormatter.h b/src/utility/ChoreoOutputFormatter.h index c1086fc..52874a6 100644 --- a/src/utility/ChoreoOutputFormatter.h +++ b/src/utility/ChoreoOutputFormatter.h @@ -3,7 +3,7 @@ # # Temboo Arduino library # -# Copyright 2014, Temboo Inc. +# Copyright 2015, Temboo Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/src/utility/ChoreoOutputSet.cpp b/src/utility/ChoreoOutputSet.cpp index f61b83f..084fe62 100644 --- a/src/utility/ChoreoOutputSet.cpp +++ b/src/utility/ChoreoOutputSet.cpp @@ -3,7 +3,7 @@ # # Temboo Arduino library # -# Copyright 2014, Temboo Inc. +# Copyright 2015, Temboo Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/src/utility/ChoreoOutputSet.h b/src/utility/ChoreoOutputSet.h index b158089..2c0fc4b 100644 --- a/src/utility/ChoreoOutputSet.h +++ b/src/utility/ChoreoOutputSet.h @@ -3,7 +3,7 @@ # # Temboo Arduino library # -# Copyright 2014, Temboo Inc. +# Copyright 2015, Temboo Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/src/utility/ChoreoPreset.cpp b/src/utility/ChoreoPreset.cpp index 8b63700..61a7850 100644 --- a/src/utility/ChoreoPreset.cpp +++ b/src/utility/ChoreoPreset.cpp @@ -3,7 +3,7 @@ # # Temboo Arduino library # -# Copyright 2014, Temboo Inc. +# Copyright 2015, Temboo Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/src/utility/ChoreoPreset.h b/src/utility/ChoreoPreset.h index b48b142..2ba457b 100644 --- a/src/utility/ChoreoPreset.h +++ b/src/utility/ChoreoPreset.h @@ -3,7 +3,7 @@ # # Temboo Arduino library # -# Copyright 2014, Temboo Inc. +# Copyright 2015, Temboo Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/src/utility/ChoreoPresetFormatter.cpp b/src/utility/ChoreoPresetFormatter.cpp index a5b8e28..f34d181 100644 --- a/src/utility/ChoreoPresetFormatter.cpp +++ b/src/utility/ChoreoPresetFormatter.cpp @@ -3,7 +3,7 @@ # # Temboo Arduino library # -# Copyright 2014, Temboo Inc. +# Copyright 2015, Temboo Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/src/utility/ChoreoPresetFormatter.h b/src/utility/ChoreoPresetFormatter.h index a0ffaf9..30e4a9b 100644 --- a/src/utility/ChoreoPresetFormatter.h +++ b/src/utility/ChoreoPresetFormatter.h @@ -3,7 +3,7 @@ # # Temboo Arduino library # -# Copyright 2014, Temboo Inc. +# Copyright 2015, Temboo Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/src/utility/DataFormatter.cpp b/src/utility/DataFormatter.cpp index 7291da9..f5cdf98 100644 --- a/src/utility/DataFormatter.cpp +++ b/src/utility/DataFormatter.cpp @@ -3,7 +3,7 @@ # # Temboo Arduino library # -# Copyright 2014, Temboo Inc. +# Copyright 2015, Temboo Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/src/utility/DataFormatter.h b/src/utility/DataFormatter.h index 0ee110f..542c821 100644 --- a/src/utility/DataFormatter.h +++ b/src/utility/DataFormatter.h @@ -3,7 +3,7 @@ # # Temboo Arduino library # -# Copyright 2014, Temboo Inc. +# Copyright 2015, Temboo Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/src/utility/TembooGlobal.c b/src/utility/TembooGlobal.c index 256ea2e..63163c1 100644 --- a/src/utility/TembooGlobal.c +++ b/src/utility/TembooGlobal.c @@ -3,7 +3,7 @@ # # Temboo Arduino library # -# Copyright 2014, Temboo Inc. +# Copyright 2015, Temboo Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/src/utility/TembooGlobal.h b/src/utility/TembooGlobal.h index 91d1658..acb8943 100644 --- a/src/utility/TembooGlobal.h +++ b/src/utility/TembooGlobal.h @@ -3,7 +3,7 @@ # # Temboo Arduino library # -# Copyright 2014, Temboo Inc. +# Copyright 2015, Temboo Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/src/utility/TembooSession.cpp b/src/utility/TembooSession.cpp index bdd7e22..70dbb9e 100644 --- a/src/utility/TembooSession.cpp +++ b/src/utility/TembooSession.cpp @@ -3,7 +3,7 @@ # # Temboo Arduino library # -# Copyright 2014, Temboo Inc. +# Copyright 2015, Temboo Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/src/utility/TembooSession.h b/src/utility/TembooSession.h index 403ed8e..635467f 100644 --- a/src/utility/TembooSession.h +++ b/src/utility/TembooSession.h @@ -3,7 +3,7 @@ # # Temboo Arduino library # -# Copyright 2014, Temboo Inc. +# Copyright 2015, Temboo Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/src/utility/tmbhmac.cpp b/src/utility/tmbhmac.cpp index 736e60d..9e23763 100644 --- a/src/utility/tmbhmac.cpp +++ b/src/utility/tmbhmac.cpp @@ -3,7 +3,7 @@ # # Temboo Arduino library # -# Copyright 2014, Temboo Inc. +# Copyright 2015, Temboo Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/src/utility/tmbhmac.h b/src/utility/tmbhmac.h index 6652dbf..028b2bd 100644 --- a/src/utility/tmbhmac.h +++ b/src/utility/tmbhmac.h @@ -3,7 +3,7 @@ # # Temboo Arduino library # -# Copyright 2014, Temboo Inc. +# Copyright 2015, Temboo Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/src/utility/tmbmd5.cpp b/src/utility/tmbmd5.cpp index e270c1c..fe8d7a9 100644 --- a/src/utility/tmbmd5.cpp +++ b/src/utility/tmbmd5.cpp @@ -3,7 +3,7 @@ # # Temboo Arduino library # -# Copyright 2014, Temboo Inc. +# Copyright 2015, Temboo Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/src/utility/tmbmd5.h b/src/utility/tmbmd5.h index 3a0bcf0..9c22c43 100644 --- a/src/utility/tmbmd5.h +++ b/src/utility/tmbmd5.h @@ -3,7 +3,7 @@ # # Temboo Arduino library # -# Copyright 2014, Temboo Inc. +# Copyright 2015, Temboo Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License.