1
0
mirror of https://github.com/arduino/Arduino.git synced 2024-11-29 10:24:12 +01:00

Temboo: updated bundled library

This commit is contained in:
Federico Fissore 2015-04-23 12:45:31 +02:00
parent 4cf77cd90d
commit 8b0fcbe281
32 changed files with 82 additions and 70 deletions

View File

@ -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.

View File

@ -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)

View File

@ -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.
@ -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;
}

View File

@ -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.
@ -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();

View File

@ -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.

View File

@ -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.

View File

@ -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.

View File

@ -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.

View File

@ -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.

View File

@ -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.

View File

@ -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.

View File

@ -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.

View File

@ -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.

View File

@ -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.

View File

@ -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.

View File

@ -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.

View File

@ -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.

View File

@ -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.

View File

@ -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.

View File

@ -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.

View File

@ -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.

View File

@ -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.

View File

@ -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.

View File

@ -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.

View File

@ -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.

View File

@ -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.

View File

@ -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.

View File

@ -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.

View File

@ -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.

View File

@ -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.

View File

@ -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.

View File

@ -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.