forked from adafruit/Adafruit_ESP8266
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ESP8266_AI_Thinker.h
69 lines (58 loc) · 2.72 KB
/
ESP8266_AI_Thinker.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
/*------------------------------------------------------------------------
An Arduino library for the ESP8266 WiFi-serial bridge
https://www.adafruit.com/product/2282
The ESP8266 is a 3.3V device. Safe operation with 5V devices (most
Arduino boards) requires a logic-level shifter for TX and RX signals.
Adafruit invests time and resources providing this open source code,
please support Adafruit and open-source hardware by purchasing
products from Adafruit!
Written by Limor Fried and Phil Burgess for Adafruit Industries.
MIT license, all text above must be included in any redistribution.
------------------------------------------------------------------------*/
#ifndef _ESP8266_AI_Thinker_H_
#define _ESP8266_AI_Thinker_H_
#include <Arduino.h>
#define ESP_RECEIVE_TIMEOUT 1000L
#define ESP_RESET_TIMEOUT 5000L
#define ESP_CONNECT_TIMEOUT 15000L
#define ESP_IPD_TIMEOUT 120000L
typedef const __FlashStringHelper Fstr; // PROGMEM/flash-resident string
typedef const PROGMEM char Pchr; // Ditto, kindasorta
#define defaultBootMarker F("ready\r\n")
// Subclassing Print makes debugging easier -- output en route to
// WiFi module can be duplicated on a second stream (e.g. Serial).
class ESP8266_AI_Thinker : public Print {
public:
ESP8266_AI_Thinker(Stream *s = &Serial, Stream *d = NULL, int8_t r = -1);
boolean hardReset(void),
softReset(void),
find(Fstr *str = NULL, boolean ipd = false),
connectToAP(Fstr *ssid, Fstr *pass),
connectTCP(Fstr *host, int port),
connectTCP(const char *host, int port),
isConnectedTCP(),
requestURL(Fstr *url),
requestURL(char* url),
cipSend(const char* data,Fstr *ack),
httpPostJson(const char *host, const char* uri, const char* data);
int readLine(char *buf, int bufSiz);
void closeAP(void),
closeTCP(void),
debugLoop(void),
setDebug(Stream *d = NULL),
setTimeouts(uint32_t rcv = ESP_RECEIVE_TIMEOUT,
uint32_t rst = ESP_RESET_TIMEOUT,
uint32_t con = ESP_CONNECT_TIMEOUT,
uint32_t ipd = ESP_IPD_TIMEOUT),
setBootMarker(Fstr *s = NULL);
private:
Stream *stream, // -> ESP8266, e.g. SoftwareSerial or Serial1
*debug; // -> host, e.g. Serial
uint32_t receiveTimeout, resetTimeout, connectTimeout, ipdTimeout;
int8_t reset_pin; // -1 if RST not connected
Fstr *host, // Non-NULL when TCP connection open
*bootMarker; // String indicating successful boot
boolean writing;
virtual size_t write(uint8_t); // Because Print subclass
};
#endif // _ESP8266_AI_Thinker_H_