-
Notifications
You must be signed in to change notification settings - Fork 41
/
ESP8266.h
76 lines (57 loc) · 1.65 KB
/
ESP8266.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
/*
Convenience functions for us with ESP8266 module.
Presumes the 8266 is attached to the hardware Serial port on the Arduino
*/
#include <Arduino.h> // for type definitions
#ifndef ESP8266_h
#define ESP8266_h
#include <AltSoftSerial.h>
typedef int (*DataCallback)(char *);
typedef void (*ConnectCallback)(void);
enum wifiModes {
WIFI_MODE_STA = 1,
WIFI_MODE_AP,
WIFI_MODE_APSTA
};
enum wifiErrors {
WIFI_ERR_NONE = 0,
WIFI_ERR_AT,
WIFI_ERR_RESET,
WIFI_ERR_CONNECT,
WIFI_ERR_LINK
};
class ESP8266
{
public:
// constructor - set link mode and server port
ESP8266(int mode = 1, long baudrate = 9600, int debugLevel = 0);
// init / connect / disconnect access point
int initializeWifi(DataCallback dcb, ConnectCallback ccb);
int connectWifi(char *ssid, char *password);
bool disconnectWifi();
// server
bool startServer(int port = 8000, long timeout = 300);
// client
bool startClient(char *ip, int port, long timeout = 300);
// discovery beacon
bool enableBeacon(char *device);
bool disableBeacon();
// send data across the link
bool send(char *data);
// process wifi messages - MUST be called from main app's loop
void run();
// informational
char *ip();
int scan(char *out, int max);
private:
void clearResults();
bool sendData(int chan, char *data);
bool setLinkMode(int mode);
bool startUDPChannel(int chan, char *address, int port);
void processWifiMessage();
bool getIP();
bool getBroadcast();
void debug(char *msg);
bool searchResults(char *target, long timeout, int dbg = 0);
};
#endif