Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 13 additions & 15 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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.
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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)
59 changes: 35 additions & 24 deletions src/Temboo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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());
}
Expand Down Expand Up @@ -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();
Expand All @@ -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;
}

Expand Down
7 changes: 5 additions & 2 deletions src/Temboo.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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();

Expand Down
2 changes: 1 addition & 1 deletion src/utility/BaseFormatter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion src/utility/BaseFormatter.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion src/utility/ChoreoInput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion src/utility/ChoreoInput.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion src/utility/ChoreoInputFormatter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion src/utility/ChoreoInputFormatter.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion src/utility/ChoreoInputSet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion src/utility/ChoreoInputSet.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion src/utility/ChoreoOutput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion src/utility/ChoreoOutput.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion src/utility/ChoreoOutputFormatter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion src/utility/ChoreoOutputFormatter.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion src/utility/ChoreoOutputSet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion src/utility/ChoreoOutputSet.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion src/utility/ChoreoPreset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion src/utility/ChoreoPreset.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion src/utility/ChoreoPresetFormatter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion src/utility/ChoreoPresetFormatter.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion src/utility/DataFormatter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion src/utility/DataFormatter.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Loading