source: rtos_arduino/trunk/arduino_lib/libraries/Temboo/src/Temboo.h@ 136

Last change on this file since 136 was 136, checked in by ertl-honda, 8 years ago

ライブラリとOS及びベーシックなサンプルの追加.

File size: 6.3 KB
Line 
1/*
2###############################################################################
3#
4# Temboo Arduino library
5#
6# Copyright 2014, Temboo Inc.
7#
8# Licensed under the Apache License, Version 2.0 (the "License");
9# you may not use this file except in compliance with the License.
10# You may obtain a copy of the License at
11#
12# http://www.apache.org/licenses/LICENSE-2.0
13#
14# Unless required by applicable law or agreed to in writing,
15# software distributed under the License is distributed on an
16# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
17# either express or implied. See the License for the specific
18# language governing permissions and limitations under the License.
19#
20###############################################################################
21*/
22
23#ifndef TEMBOO_H_
24#define TEMBOO_H_
25
26#include <Arduino.h>
27
28#if defined (ARDUINO_AVR_YUN) || defined (ARDUINO_AVR_TRE)
29///////////////////////////////////////////////////////
30// BEGIN ARDUINO YUN AND TRE SUPPORT
31///////////////////////////////////////////////////////
32
33#include <Process.h>
34
35class TembooChoreo : public Process {
36
37 public:
38 void begin();
39 void setAccountName(const String& accountName);
40 void setAppKeyName(const String& appKeyName);
41 void setAppKey(const String& appKey);
42 void setChoreo(const String& choreo);
43 void setCredential(const String& credentialName);
44 void setSavedInputs(const String& saveInputsName);
45 void setProfile(const String& profileName);
46 void addInput(const String& inputName, const String& inputValue);
47 void addOutputFilter(const String& filterName, const String& filterPath, const String& variableName);
48 void setSettingsFileToWrite(const String& filePath);
49 void setSettingsFileToRead(const String& filePath);
50
51};
52
53#else //ARDUINO_AVR_YUN
54
55///////////////////////////////////////////////////////
56// BEGIN ARDUINO NON-YUN SUPPORT
57///////////////////////////////////////////////////////
58
59#include <Stream.h>
60#include <Client.h>
61#include <IPAddress.h>
62#include "utility/ChoreoInputSet.h"
63#include "utility/ChoreoOutputSet.h"
64#include "utility/ChoreoPreset.h"
65
66#define TEMBOO_ERROR_OK (0)
67#define TEMBOO_ERROR_ACCOUNT_MISSING (201)
68#define TEMBOO_ERROR_CHOREO_MISSING (203)
69#define TEMBOO_ERROR_APPKEY_NAME_MISSING (205)
70#define TEMBOO_ERROR_APPKEY_MISSING (207)
71#define TEMBOO_ERROR_HTTP_ERROR (223)
72
73class TembooChoreo : public Stream {
74 public:
75
76 // Constructor.
77 // client - an instance of an Arduino Client, usually an EthernetClient
78 // or a WiFiClient. Used to communicate with Temboo.
79 TembooChoreo(Client& client);
80
81 // Does nothing. Just for source compatibility with Yun code.
82 void begin() {};
83
84 // Sets the account name to use when communicating with Temboo.
85 // (required)
86 void setAccountName(const String& accountName);
87 void setAccountName(const char* accountName);
88
89 // Sets the application key name to use with choreo execution requests.
90 // (required)
91 void setAppKeyName(const String& appKeyName);
92 void setAppKeyName(const char* appKeyName);
93
94 // Sets the application key value to use with choreo execution requests
95 // (required)
96 void setAppKey(const String& appKey);
97 void setAppKey(const char* appKey);
98
99 // sets the name of the choreo to be executed.
100 // (required)
101 void setChoreo(const String& choreoPath);
102 void setChoreo(const char* choreoPath);
103
104 // sets the name of the saved inputs to use when executing the choreo
105 // (optional)
106 void setSavedInputs(const String& savedInputsName);
107 void setSavedInputs(const char* savedInputsName);
108
109 void setCredential(const String& credentialName);
110 void setCredential(const char* credentialName);
111
112 void setProfile(const String& profileName);
113 void setProfile(const char* profileName);
114
115 // sets an input to be used when executing a choreo.
116 // (optional or required, depending on the choreo being executed.)
117 void addInput(const String& inputName, const String& inputValue);
118 void addInput(const char* inputName, const char* inputValue);
119 void addInput(const char* inputName, const String& inputValue);
120 void addInput(const String& inputName, const char* inputValue);
121
122 // sets an output filter to be used to process the choreo output
123 // (optional)
124 void addOutputFilter(const char* filterName, const char* filterPath, const char* variableName);
125 void addOutputFilter(const String& filterName, const char* filterPath, const char* variableName);
126 void addOutputFilter(const char* filterName, const String& filterPath, const char* variableName);
127 void addOutputFilter(const String& filterName, const String& filterPath, const char* variableName);
128 void addOutputFilter(const char* filterName, const char* filterPath, const String& variableName);
129 void addOutputFilter(const String& filterName, const char* filterPath, const String& variableName);
130 void addOutputFilter(const char* filterName, const String& filterPath, const String& variableName);
131 void addOutputFilter(const String& filterName, const String& filterPath, const String& variableName);
132
133 // run the choreo using the current input info
134 int run();
135
136 // run the choreo on the Temboo server at the given IP address and port
137 // (used only when instructed by Temboo customer support.)
138 int run(IPAddress addr, uint16_t port);
139
140 void close();
141
142 // Stream interface - see the Arduino library documentation.
143 int available();
144 int read();
145 int peek();
146 void flush();
147
148 //Print interface - see the Arduino library documentation
149 size_t write(uint8_t data);
150
151
152 protected:
153 ChoreoInputSet m_inputs;
154 ChoreoOutputSet m_outputs;
155 ChoreoPreset m_preset;
156
157 const char* m_accountName;
158 const char* m_appKeyValue;
159 const char* m_appKeyName;
160 const char* m_path;
161 Client& m_client;
162 char m_httpCodeStr[6];
163 const char* m_nextChar;
164 enum State {START, HTTP_CODE_TAG, HTTP_CODE_VALUE, END};
165 State m_nextState;
166
167};
168
169#endif //ARDUINO_AVR_YUN
170
171#endif //TEMBOO_H_
Note: See TracBrowser for help on using the repository browser.