source: rtos_arduino/trunk/arduino_lib/libraries/ESP8266_Arudino_AT/Client_ESP8266.h@ 189

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

Thinkgspeakのサポート

File size: 2.6 KB
Line 
1/*
2 Copyright (C) 2015 Embedded and Real-Time Systems Laboratory
3 Graduate School of Information Science, Nagoya Univ., JAPAN
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
13 You should have received a copy of the GNU Lesser General Public
14 License along with this library; if not, write to the Free Software
15 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
16 */
17
18#ifndef _CLIENT_ESP8366_H_
19#define _CLIENT_ESP8366_H_
20
21#include "ESP8266.h"
22#include "IPAddress.h"
23#include "Client.h"
24
25class ESP8266Client: public Client, public ESP8266 {
26 public:
27 ESP8266Client(void) {
28 pbuffer = &rx_buffer[0];
29 }
30
31 /*
32 * @retval 0 : faild
33 * @retval 1 : success
34 */
35 int connect(IPAddress ip, uint16_t port) {
36 if (isConnected()) return 1;
37 String ip_str;
38 ip_str.concat(ip[0]); ip_str.concat(".");
39 ip_str.concat(ip[1]); ip_str.concat(".");
40 ip_str.concat(ip[2]); ip_str.concat(".");
41 ip_str.concat(ip[3]);
42 return (createTCP(ip_str, port))? 1 : 0;
43 };
44
45 int connect(const char *host, uint16_t port) {
46 if (isConnected()) return 1;
47 String ip_str(host);
48 return (createTCP(ip_str, port))? 1 : 0;
49 };
50
51 size_t write(uint8_t data) {
52 if(send(&data, 1)){
53 return 1;
54 }
55 return 0;
56 };
57
58 size_t write(const uint8_t *buf, size_t size){
59 if(send(buf, size)){
60 return size;
61 }
62 return 0;
63 };
64
65 int available(){
66 return isDataAvailable();
67 };
68
69 int read(){
70 uint8_t data;
71 if(recv(&data, 1) == 1) {
72 return data;
73 }
74 return (int)-1;
75 };
76
77 int read(uint8_t *buf, size_t size){
78 return recv(buf, size);
79 };
80
81 int peek(){
82 return pbuffer->peek();
83 };
84
85 void flush(){};
86 void stop(){ if (isConnected()) { releaseTCP(); }}
87 uint8_t connected(){return (isConnected())? 1 : 0;};
88 operator bool(){return isConnected();};
89 private:
90 ESP8266_RingBuffer *pbuffer;
91};
92
93#endif /* _CLIENT_ESP8366_H_ */
Note: See TracBrowser for help on using the repository browser.