Arduino  1.8.10
TembooSession クラス

#include <TembooSession.h>

公開メンバ関数

 TembooSession (Client &client, IPAddress serverAddr=INADDR_NONE, uint16_t port=80)
 
int executeChoreo (const char *accountName, const char *appKeyName, const char *appKeyValue, const char *path, const ChoreoInputSet &inputSet, const ChoreoInputExpressionSet &expressionSet, const ChoreoSensorInputSet &sensorSet, const ChoreoOutputSet &outputSet, const ChoreoPreset &preset, const ChoreoDevice &deviceType, const ChoreoDevice &deviceName)
 

静的公開メンバ関数

static void setTime (unsigned long currentTime)
 
static unsigned long getTime ()
 

詳解

TembooSession.h51 行目に定義があります。

構築子と解体子

◆ TembooSession()

TembooSession::TembooSession ( Client client,
IPAddress  serverAddr = INADDR_NONE,
uint16_t  port = 80 
)

TembooSession.cpp49 行目に定義があります。

51  : m_client(client) {
52  m_addr = serverAddr;
53  m_port = port;
54  m_sendQueueDepth = 0;
55 }
EthernetClient client

関数詳解

◆ executeChoreo()

int TembooSession::executeChoreo ( const char *  accountName,
const char *  appKeyName,
const char *  appKeyValue,
const char *  path,
const ChoreoInputSet inputSet,
const ChoreoInputExpressionSet expressionSet,
const ChoreoSensorInputSet sensorSet,
const ChoreoOutputSet outputSet,
const ChoreoPreset preset,
const ChoreoDevice deviceType,
const ChoreoDevice deviceName 
)

TembooSession.cpp69 行目に定義があります。

80  {
81 
82  DataFormatter fmt(&inputSet, &expressionSet, &sensorSet,&outputSet, &preset, &deviceType, &deviceName);
83  char auth[HMAC_HEX_SIZE_BYTES + 1];
84  char buffer[11];
85 
86  // We use the current time-of-day as salt on the app key.
87  // We keep track of time-of-day by getting the current time
88  // from the server and applying an offset (the length of time
89  // we've been running.)
91 
92  uint16_t contentLength = getAuth(fmt, appKeyValue, buffer, auth);
93  if (m_client.connected()) {
94  m_client.stop();
95  }
96  m_client.flush();
97 
98  int connected = 0;
99  TEMBOO_TRACE("Connecting: ");
100 
101  // reserve space for the "host" string sufficient to hold either the
102  // (dotted-quad) IP address + port, or the default <account>.temboolive.com
103  // host string.
104  int hostLen = strlen_P(TEMBOO_DOMAIN) + strlen(accountName) + 1;
105  char host[hostLen];
106 
107  // Construct the "host" string from the account name and the temboo domain name.
108 
109  strcpy(host, accountName);
110  strcat_P(host, TEMBOO_DOMAIN);
111 
112  bool useProxy = false;
113 
114  if (m_addr == INADDR_NONE) {
115  TEMBOO_TRACELN(host);
116  connected = m_client.connect(host, m_port);
117  } else {
118 
119  TEMBOO_TRACELN(host);
120  connected = m_client.connect(m_addr, m_port);
121 
122  useProxy = true;
123  }
124 
125  if (connected) {
126 
127  TEMBOO_TRACELN("OK. req:");
128  qsendProgmem(POST);
129  if(useProxy) {
130  qsendProgmem(HTTP);
131  qsend(host);
132  }
133  qsendProgmem(BASE_CHOREO_URI);
134  qsend(path);
135  qsendProgmem(SDK_ID);
136  if (deviceType.isEmpty()) {
137  qsendProgmem(SDK_ID_DEFAULT);
138  } else {
139  qsend(deviceType.getName());
140  }
141  qsendlnProgmem(POSTAMBLE);
142 
143  // Send our custom authentication header
144  // (app-key-name:hmac)
145  qsendProgmem(HEADER_AUTH);
146  qsend(appKeyName);
147  qsend(":");
148  qsendln(auth);
149 
150  // send the standard host header
151  qsendProgmem(HEADER_HOST);
152  qsendln(host);
153 
154  // send the standard accept header
155  qsendlnProgmem(HEADER_ACCEPT);
156 
157  // send our custom account name neader
158  qsendProgmem(HEADER_ORG);
159  qsend(accountName);
160  qsendlnProgmem(HEADER_DOM);
161 
162  // send the standard content type header
163  qsendlnProgmem(HEADER_CONTENT_TYPE);
164 
165  // send our custom client time header
166  qsendProgmem(HEADER_TIME);
167  qsendln(buffer);
168 
169  // send the standard content length header
170  qsendProgmem(HEADER_CONTENT_LENGTH);
171  qsendln(uint16toa(contentLength, buffer));
172 
173  qsendProgmem(EOL);
174 
175  // Format and send the body of the request
176  fmt.reset();
177  while(fmt.hasNext()) {
178  qsend(fmt.next());
179  }
180 
181  qsendProgmem(EOL);
182  qflush();
183  return 0;
184  } else {
185  TEMBOO_TRACELN("FAIL");
186  return 1;
187  }
188 }
virtual int connect(IPAddress ip, uint16_t port)=0
virtual uint8_t connected()=0
const IPAddress INADDR_NONE(0, 0, 0, 0)
char buffer[42]
virtual void stop()=0
const char HEADER_CONTENT_LENGTH[]
const char HEADER_ACCEPT[]
const char HEADER_HOST[]
#define TEMBOO_TRACELN(x)
Definition: TembooGlobal.h:37
const char BASE_CHOREO_URI[]
const char HEADER_DOM[]
#define HMAC_HEX_SIZE_BYTES
Definition: tmbhmac.h:31
char * uint32toa(uint32_t value, char *dest)
Definition: TembooGlobal.c:29
size_t strlen(const char *) __ATTR_PURE__
Calculate the length of a string.
const char TEMBOO_DOMAIN[]
static unsigned long getTime()
const char HEADER_TIME[]
const char * getName() const
Definition: ChoreoDevice.h:33
#define TEMBOO_TRACE(x)
Definition: TembooGlobal.h:35
const char HEADER_AUTH[]
const char HEADER_ORG[]
char * uint16toa(uint16_t value, char *dest)
Definition: TembooGlobal.c:25
bool isEmpty() const
Definition: ChoreoDevice.h:35
const char POSTAMBLE[]
char * strcat_P(char *, const char *)
const char POST[]
const char EOL[]
virtual void flush()=0
const char HEADER_CONTENT_TYPE[]
const char SDK_ID[]
char * strcpy(char *, const char *)
Copy a string.

◆ getTime()

unsigned long TembooSession::getTime ( )
static

TembooSession.cpp63 行目に定義があります。

63  {
64  return s_timeOffset + (millis()/1000);
65 }
unsigned long millis(void)
Definition: wiring.c:65

◆ setTime()

void TembooSession::setTime ( unsigned long  currentTime)
static

TembooSession.cpp58 行目に定義があります。

58  {
59  s_timeOffset = currentTime - (millis()/1000);
60 }
unsigned long millis(void)
Definition: wiring.c:65

このクラス詳解は次のファイルから抽出されました: