1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-12-12 08:01:46 +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

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