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

View File

@ -6,5 +6,5 @@ paragraph=Use this library to connect your Arduino board to Temboo, making it si
category=Communication category=Communication
url=http://www.temboo.com/arduino url=http://www.temboo.com/arduino
architectures=* architectures=*
version=1.1.1 version=1.1.2
core-dependencies=arduino (>=1.5.0) core-dependencies=arduino (>=1.5.0)

View File

@ -3,7 +3,7 @@
# #
# Temboo Arduino library # Temboo Arduino library
# #
# Copyright 2014, Temboo Inc. # Copyright 2015, Temboo Inc.
# #
# Licensed under the Apache License, Version 2.0 (the "License"); # Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with 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" #include "utility/TembooSession.h"
static const char HTTP_CODE[] PROGMEM = "HTTP_CODE\x0A\x1F"; 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) { TembooChoreo::TembooChoreo(Client& client) : m_client(client) {
m_accountName = NULL; m_accountName = NULL;
@ -171,7 +173,6 @@ void TembooChoreo::setProfile(const char* profileName) {
} }
void TembooChoreo::addInput(const String& inputName, const String& inputValue) { void TembooChoreo::addInput(const String& inputName, const String& inputValue) {
m_inputs.put(inputName.c_str(), inputValue.c_str()); 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() { 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; m_nextChar = NULL;
if (m_accountName == NULL || *m_accountName == '\0') { if (m_accountName == NULL || *m_accountName == '\0') {
return TEMBOO_ERROR_ACCOUNT_MISSING; return TEMBOO_ERROR_ACCOUNT_MISSING;
} }
if (m_path == NULL || *m_path == '\0') { if (m_path == NULL || *m_path == '\0') {
return TEMBOO_ERROR_CHOREO_MISSING; return TEMBOO_ERROR_CHOREO_MISSING;
} }
if (m_appKeyName == NULL || *m_appKeyName == '\0') { if (m_appKeyName == NULL || *m_appKeyName == '\0') {
return TEMBOO_ERROR_APPKEY_NAME_MISSING; return TEMBOO_ERROR_APPKEY_NAME_MISSING;
} }
if (m_appKeyValue == NULL || *m_appKeyValue == '\0') { if (m_appKeyValue == NULL || *m_appKeyValue == '\0') {
return TEMBOO_ERROR_APPKEY_MISSING; return TEMBOO_ERROR_APPKEY_MISSING;
} }
TembooSession session(m_client, addr, port); TembooSession session(m_client, addr, port);
uint16_t httpCode = 0; uint16_t httpCode = 0;
for (int i = 0; i < 2; i++) { 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)) { if (0 != session.executeChoreo(m_accountName, m_appKeyName, m_appKeyValue, m_path, m_inputs, m_outputs, m_preset)) {
httpCode = 0; httpCode = 0;
break; break;
} }
while(!m_client.available()) { 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()) { if (!m_client.connected()) {
TEMBOO_TRACELN("Disconnected"); TEMBOO_TRACELN("Disconnected");
return TEMBOO_ERROR_HTTP_ERROR; return TEMBOO_ERROR_HTTP_ERROR;
} }
delay(10); delay(10);
} }
if (!m_client.findUntil("HTTP/1.", HTTP_EOL)) {
if (!m_client.find("HTTP/1.1 ")) {
TEMBOO_TRACELN("No HTTP"); TEMBOO_TRACELN("No HTTP");
return TEMBOO_ERROR_HTTP_ERROR; 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(); 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. // we need to be prepared for anything.
if (httpCode >= 600) { if (httpCode >= 600) {
TEMBOO_TRACELN("Invalid HTTP"); TEMBOO_TRACELN("Invalid HTTP");
httpCode = 0; httpCode = 0;
} }
// if we get an auth error AND there was an x-temboo-time header, // if we get an auth error AND there was an x-temboo-time header,
// update the session timeOffset // update the session timeOffset
if ((httpCode == 401) && (i == 0)) { 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()); TembooSession::setTime((unsigned long)m_client.parseInt());
while(m_client.available()) { while(m_client.available()) {
m_client.read(); m_client.read();
@ -303,20 +314,20 @@ int TembooChoreo::run(IPAddress addr, uint16_t port) {
break; break;
} }
} }
uint16toa(httpCode, m_httpCodeStr); uint16toa(httpCode, m_httpCodeStr);
strcat_P(m_httpCodeStr, PSTR("\x0A\x1E")); strcat_P(m_httpCodeStr, PSTR("\x0A\x1E"));
m_nextState = START; m_nextState = START;
m_nextChar = HTTP_CODE; m_nextChar = HTTP_CODE;
if (httpCode < 200 || httpCode >= 300) { if (httpCode < 200 || httpCode >= 300) {
return TEMBOO_ERROR_HTTP_ERROR; 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_HTTP_ERROR;
} }
return TEMBOO_ERROR_OK; return TEMBOO_ERROR_OK;
} }

View File

@ -3,7 +3,7 @@
# #
# Temboo Arduino library # Temboo Arduino library
# #
# Copyright 2014, Temboo Inc. # Copyright 2015, Temboo Inc.
# #
# Licensed under the Apache License, Version 2.0 (the "License"); # Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with 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_NAME_MISSING (205)
#define TEMBOO_ERROR_APPKEY_MISSING (207) #define TEMBOO_ERROR_APPKEY_MISSING (207)
#define TEMBOO_ERROR_HTTP_ERROR (223) #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 { class TembooChoreo : public Stream {
public: public:
@ -135,7 +137,8 @@ class TembooChoreo : public Stream {
// run the choreo on the Temboo server at the given IP address and port // run the choreo on the Temboo server at the given IP address and port
// (used only when instructed by Temboo customer support.) // (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(); void close();

View File

@ -3,7 +3,7 @@
# #
# Temboo Arduino library # Temboo Arduino library
# #
# Copyright 2014, Temboo Inc. # Copyright 2015, Temboo Inc.
# #
# Licensed under the Apache License, Version 2.0 (the "License"); # Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License. # you may not use this file except in compliance with the License.

View File

@ -3,7 +3,7 @@
# #
# Temboo Arduino library # Temboo Arduino library
# #
# Copyright 2014, Temboo Inc. # Copyright 2015, Temboo Inc.
# #
# Licensed under the Apache License, Version 2.0 (the "License"); # Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License. # you may not use this file except in compliance with the License.

View File

@ -3,7 +3,7 @@
# #
# Temboo Arduino library # Temboo Arduino library
# #
# Copyright 2014, Temboo Inc. # Copyright 2015, Temboo Inc.
# #
# Licensed under the Apache License, Version 2.0 (the "License"); # Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License. # you may not use this file except in compliance with the License.

View File

@ -3,7 +3,7 @@
# #
# Temboo Arduino library # Temboo Arduino library
# #
# Copyright 2014, Temboo Inc. # Copyright 2015, Temboo Inc.
# #
# Licensed under the Apache License, Version 2.0 (the "License"); # Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License. # you may not use this file except in compliance with the License.

View File

@ -3,7 +3,7 @@
# #
# Temboo Arduino library # Temboo Arduino library
# #
# Copyright 2014, Temboo Inc. # Copyright 2015, Temboo Inc.
# #
# Licensed under the Apache License, Version 2.0 (the "License"); # Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License. # you may not use this file except in compliance with the License.

View File

@ -3,7 +3,7 @@
# #
# Temboo Arduino library # Temboo Arduino library
# #
# Copyright 2014, Temboo Inc. # Copyright 2015, Temboo Inc.
# #
# Licensed under the Apache License, Version 2.0 (the "License"); # Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License. # you may not use this file except in compliance with the License.

View File

@ -3,7 +3,7 @@
# #
# Temboo Arduino library # Temboo Arduino library
# #
# Copyright 2014, Temboo Inc. # Copyright 2015, Temboo Inc.
# #
# Licensed under the Apache License, Version 2.0 (the "License"); # Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License. # you may not use this file except in compliance with the License.

View File

@ -3,7 +3,7 @@
# #
# Temboo Arduino library # Temboo Arduino library
# #
# Copyright 2014, Temboo Inc. # Copyright 2015, Temboo Inc.
# #
# Licensed under the Apache License, Version 2.0 (the "License"); # Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License. # you may not use this file except in compliance with the License.

View File

@ -3,7 +3,7 @@
# #
# Temboo Arduino library # Temboo Arduino library
# #
# Copyright 2014, Temboo Inc. # Copyright 2015, Temboo Inc.
# #
# Licensed under the Apache License, Version 2.0 (the "License"); # Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License. # you may not use this file except in compliance with the License.

View File

@ -3,7 +3,7 @@
# #
# Temboo Arduino library # Temboo Arduino library
# #
# Copyright 2014, Temboo Inc. # Copyright 2015, Temboo Inc.
# #
# Licensed under the Apache License, Version 2.0 (the "License"); # Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License. # you may not use this file except in compliance with the License.

View File

@ -3,7 +3,7 @@
# #
# Temboo Arduino library # Temboo Arduino library
# #
# Copyright 2014, Temboo Inc. # Copyright 2015, Temboo Inc.
# #
# Licensed under the Apache License, Version 2.0 (the "License"); # Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License. # you may not use this file except in compliance with the License.

View File

@ -3,7 +3,7 @@
# #
# Temboo Arduino library # Temboo Arduino library
# #
# Copyright 2014, Temboo Inc. # Copyright 2015, Temboo Inc.
# #
# Licensed under the Apache License, Version 2.0 (the "License"); # Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License. # you may not use this file except in compliance with the License.

View File

@ -3,7 +3,7 @@
# #
# Temboo Arduino library # Temboo Arduino library
# #
# Copyright 2014, Temboo Inc. # Copyright 2015, Temboo Inc.
# #
# Licensed under the Apache License, Version 2.0 (the "License"); # Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License. # you may not use this file except in compliance with the License.

View File

@ -3,7 +3,7 @@
# #
# Temboo Arduino library # Temboo Arduino library
# #
# Copyright 2014, Temboo Inc. # Copyright 2015, Temboo Inc.
# #
# Licensed under the Apache License, Version 2.0 (the "License"); # Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License. # you may not use this file except in compliance with the License.

View File

@ -3,7 +3,7 @@
# #
# Temboo Arduino library # Temboo Arduino library
# #
# Copyright 2014, Temboo Inc. # Copyright 2015, Temboo Inc.
# #
# Licensed under the Apache License, Version 2.0 (the "License"); # Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License. # you may not use this file except in compliance with the License.

View File

@ -3,7 +3,7 @@
# #
# Temboo Arduino library # Temboo Arduino library
# #
# Copyright 2014, Temboo Inc. # Copyright 2015, Temboo Inc.
# #
# Licensed under the Apache License, Version 2.0 (the "License"); # Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License. # you may not use this file except in compliance with the License.

View File

@ -3,7 +3,7 @@
# #
# Temboo Arduino library # Temboo Arduino library
# #
# Copyright 2014, Temboo Inc. # Copyright 2015, Temboo Inc.
# #
# Licensed under the Apache License, Version 2.0 (the "License"); # Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License. # you may not use this file except in compliance with the License.

View File

@ -3,7 +3,7 @@
# #
# Temboo Arduino library # Temboo Arduino library
# #
# Copyright 2014, Temboo Inc. # Copyright 2015, Temboo Inc.
# #
# Licensed under the Apache License, Version 2.0 (the "License"); # Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License. # you may not use this file except in compliance with the License.

View File

@ -3,7 +3,7 @@
# #
# Temboo Arduino library # Temboo Arduino library
# #
# Copyright 2014, Temboo Inc. # Copyright 2015, Temboo Inc.
# #
# Licensed under the Apache License, Version 2.0 (the "License"); # Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License. # you may not use this file except in compliance with the License.

View File

@ -3,7 +3,7 @@
# #
# Temboo Arduino library # Temboo Arduino library
# #
# Copyright 2014, Temboo Inc. # Copyright 2015, Temboo Inc.
# #
# Licensed under the Apache License, Version 2.0 (the "License"); # Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License. # you may not use this file except in compliance with the License.

View File

@ -3,7 +3,7 @@
# #
# Temboo Arduino library # Temboo Arduino library
# #
# Copyright 2014, Temboo Inc. # Copyright 2015, Temboo Inc.
# #
# Licensed under the Apache License, Version 2.0 (the "License"); # Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License. # you may not use this file except in compliance with the License.

View File

@ -3,7 +3,7 @@
# #
# Temboo Arduino library # Temboo Arduino library
# #
# Copyright 2014, Temboo Inc. # Copyright 2015, Temboo Inc.
# #
# Licensed under the Apache License, Version 2.0 (the "License"); # Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License. # you may not use this file except in compliance with the License.

View File

@ -3,7 +3,7 @@
# #
# Temboo Arduino library # Temboo Arduino library
# #
# Copyright 2014, Temboo Inc. # Copyright 2015, Temboo Inc.
# #
# Licensed under the Apache License, Version 2.0 (the "License"); # Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License. # you may not use this file except in compliance with the License.

View File

@ -3,7 +3,7 @@
# #
# Temboo Arduino library # Temboo Arduino library
# #
# Copyright 2014, Temboo Inc. # Copyright 2015, Temboo Inc.
# #
# Licensed under the Apache License, Version 2.0 (the "License"); # Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License. # you may not use this file except in compliance with the License.

View File

@ -3,7 +3,7 @@
# #
# Temboo Arduino library # Temboo Arduino library
# #
# Copyright 2014, Temboo Inc. # Copyright 2015, Temboo Inc.
# #
# Licensed under the Apache License, Version 2.0 (the "License"); # Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License. # you may not use this file except in compliance with the License.

View File

@ -3,7 +3,7 @@
# #
# Temboo Arduino library # Temboo Arduino library
# #
# Copyright 2014, Temboo Inc. # Copyright 2015, Temboo Inc.
# #
# Licensed under the Apache License, Version 2.0 (the "License"); # Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License. # you may not use this file except in compliance with the License.

View File

@ -3,7 +3,7 @@
# #
# Temboo Arduino library # Temboo Arduino library
# #
# Copyright 2014, Temboo Inc. # Copyright 2015, Temboo Inc.
# #
# Licensed under the Apache License, Version 2.0 (the "License"); # Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License. # you may not use this file except in compliance with the License.

View File

@ -3,7 +3,7 @@
# #
# Temboo Arduino library # Temboo Arduino library
# #
# Copyright 2014, Temboo Inc. # Copyright 2015, Temboo Inc.
# #
# Licensed under the Apache License, Version 2.0 (the "License"); # Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License. # you may not use this file except in compliance with the License.