-
Notifications
You must be signed in to change notification settings - Fork 37
/
ESP8266_TCP.h
143 lines (98 loc) · 2.7 KB
/
ESP8266_TCP.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
/*
WiFlyTCP.h - WiFly Library for Arduino
*/
// ensure this library description is only included once
#ifndef _ESP8266_TCP_H_
#define _ESP8266_TCP_H_
#if defined(ARDUINO) && ARDUINO >= 100
#include "Arduino.h"
#else
#include "WProgram.h"
#endif
#include <Stream.h>
#include <avr/pgmspace.h>
#include <IPAddress.h>
#define WIFI_MODE_STATION 0x01
#define WIFI_MODE_AP 0x02
#define WIFI_MODE_BOTH 0x03
#define WIFI_MUX_SINGLE 0x00
#define WIFI_MUX_MULTI 0x01
#define WIFI_TCP_DISABLE 0x00
#define WIFI_TCP_ENABLE 0x01
#define WIFI_CLIENT 0x00
#define WIFI_SERVER 0x01
#define WIFI_STATE_IDLE 0x00
#define WIFI_STATE_UNAVAILABLE 0x01
#define WIFI_STATE_SEND 0x02
#define WIFI_STATE_CONNECT 0x03
#define WIFI_NEW_NONE 0x00
#define WIFI_NEW_MESSAGE 0x01
#define WIFI_NEW_CONNECTED 0x02
#define WIFI_NEW_DISCONNECTED 0x03
#define WIFI_NEW_SEND_OK 0x04
#define WIFI_NEW_SEND_ERROR 0x05
#define WIFI_NEW_RESET 0x06
#define WIFI_NEW_ALREADY_CONNECT 0x07
#define WIFI_NEW_ETC 0x08
// library interface description
class ESP8266_TCP {
public:
ESP8266_TCP();
void begin(Stream *serial, Stream *serialDebug, int pinReset);
void begin(Stream *serial, int pinReset);
bool test();
void reset();
void hardReset();
bool closeTCPServer();
//bool isTCPEnabled();
void openTCPServer(int port, int timeout);
void connectTCP(String ip, int port);
void closeTCPConnection();
void closeTCPConnection(int id);
int getRunningState();
int getId();
String getMessage();
void clearNewMessage();
String connectAccessPoint(String ssid, String pass);
void openAccessPoint(String ssid, String pass, int channel);
int isNewDataComing(byte type);
bool send(String message);
bool send(int id, String message);
void printClientList();
private:
void waitingForReset();
void waitingForReset(unsigned long timeout);
void waitingForHardReset();
String waitingForJoin();
void waitingForTCPConnection();
bool setMode(int mode);
bool setMux(int mux);
bool enableTCPServer(int port);
bool setTCPTimeout(int timeout);
void flush();
//bool waitForSendStatus();
void setRunningState(int state);
void debugPrintln(String str);
void debugPrint(String str);
bool setAP(String ssid, String pass, int channel);
bool isNewAPSetting(String ssid, String pass, int channel);
void clearBuffer();
int findChar(String str, int start, char c);
void clear();
void write(String str);
int available();
String read();
String readData();
String readData(unsigned long timeout);
String readTCPData();
bool TCPConnected;
bool TCPEnable;
bool isDebug;
int pinReset;
int clientId;
String clientMessage;
Stream *serial;
Stream *serialDebug;
int runningState;
};
#endif