-
Notifications
You must be signed in to change notification settings - Fork 27
/
IoTgo.h
84 lines (71 loc) · 2.08 KB
/
IoTgo.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/**
* @file IoTgo.h
*
* API of IoTgo (iotgo.iteadstudio.com)
*
* @author Wu Pengfei (email:<[email protected]>)
* @date 2014/11/11
* @copyright
* Copyright (C) 2013-2014 ITEAD Intelligent Systems Co., Ltd. \n
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*/
#ifndef __ITEADIOT_H__
#define __ITEADIOT_H__
#include <string.h>
#include <SoftwareSerial.h>
#include "IoTgo_config.h"
#include "IoTgo_error.h"
#include "Net_NetInterface.h"
/**
* @addtogroup IoTgo
* @{
*/
/**
* Constants of IoTgo platform.
*
* Maybe these are useless for users.
*/
enum IoTgoConstant
{
IOT_BUFFER_SIZE = 512, /**< the length of http request */
APIKEY_LEN = 36, /**< the length of apikey */
DEVICE_ID_LEN = 10, /**< the length of device id */
};
/**
* Indicates the type of device.
*
* Used in method: @ref IoTgo::init. If the deviceid is created by developers on website
* of IoTgo platform, the type is DEVICE_DIY. Else DEVICE_PRODUCT.
*/
enum IoTgoDeviceType
{
DEVICE_DIY = 0, /**< DIY deviceid */
DEVICE_PRODUCT = 1, /**< Product deviceid */
};
/**
* IoTgo provides some simple API for device of IoT.
*/
class IoTgo
{
public: /* public methods */
IoTgo(NetInterface *net);
void setHost(const char *ip, const char *domain_name);
const char *init(const char *device_id, const char *apikey,
IoTgoDeviceType device_type = DEVICE_DIY);
const char *query(const char *params[]);
const char *update(const char *params[], const char *values[]);
private: /* private methods */
const char * request(const char *http_body, char *const buffer, int32_t len);
private: /* private datas */
NetInterface *net;
char buffer[IOT_BUFFER_SIZE];
char apikey[APIKEY_LEN + 1];
char device_id[DEVICE_ID_LEN + 1];
char ip[30];
char domain_name[30];
};
/** @} */
#endif /* #ifndef __ITEADIOT_H__ */