API: README

API
For Arduino developers
  • Main Page
  • Related Pages
  • Classes
  • Files
  • Examples
README
Generated on Tue Mar 17 2015 10:34:17 for API by doxygen 1.8.7


API: Class List

API
  • Related Pages
  • Classes
  • Files
  • Examples
  • Class List
  • Class Index
  • Class Members
Class List
Here are the classes, structs, unions and interfaces with brief descriptions:
C ESP8266 Provide an easy-to-use way to manipulate ESP8266


API: ESP8266 Class Reference

API
  • Related Pages
  • Classes
  • Files
  • Examples
  • Class List
  • Class Index
  • Class Members
Public Member Functions | List of all members
ESP8266 Class Reference

Provide an easy-to-use way to manipulate ESP8266. More...

#include <ESP8266.h>

Public Member Functions

bool | kick (void)
Verify ESP8266 whether live or not. More...
bool | restart (void)
Restart ESP8266 by "AT+RST". More...
String | getVersion (void)
Get the version of AT Command Set. More...
bool | setOprToStation (void)
Set operation mode to staion. More...
bool | setOprToSoftAP (void)
Set operation mode to softap. More...
bool | setOprToStationSoftAP (void)
Set operation mode to station + softap. More...
String | getAPList (void)
Search available AP list and return it. More...
bool | joinAP (String ssid, String pwd)
Join in AP. More...
bool | leaveAP (void)
Leave AP joined before. More...
bool | setSoftAPParam (String ssid, String pwd, uint8_t chl=7, uint8_t ecn=4)
Set SoftAP parameters. More...
String | getJoinedDeviceIP (void)
Get the IP list of devices connected to SoftAP. More...
String | getIPStatus (void)
Get the current status of connection(UDP and TCP). More...
String | getLocalIP (void)
Get the IP address of ESP8266. More...
bool | enableMUX (void)
Enable IP MUX(multiple connection mode). More...
bool | disableMUX (void)
Disable IP MUX(single connection mode). More...
bool | createTCP (String addr, uint32_t port)
Create TCP connection in single mode. More...
bool | releaseTCP (void)
Release TCP connection in single mode. More...
bool | registerUDP (String addr, uint32_t port)
Register UDP port number in single mode. More...
bool | unregisterUDP (void)
Unregister UDP port number in single mode. More...
bool | createTCP (uint8_t mux_id, String addr, uint32_t port)
Create TCP connection in multiple mode. More...
bool | releaseTCP (uint8_t mux_id)
Release TCP connection in multiple mode. More...
bool | registerUDP (uint8_t mux_id, String addr, uint32_t port)
Register UDP port number in multiple mode. More...
bool | unregisterUDP (uint8_t mux_id)
Unregister UDP port number in multiple mode. More...
bool | setTCPServerTimeout (uint32_t timeout=180)
Set the timeout of TCP Server. More...
bool | startTCPServer (uint32_t port=333)
Start TCP Server(Only in multiple mode). More...
bool | stopTCPServer (void)
Stop TCP Server(Only in multiple mode). More...
bool | startServer (uint32_t port=333)
Start Server(Only in multiple mode). More...
bool | stopServer (void)
Stop Server(Only in multiple mode). More...
bool | send (const uint8_t *buffer, uint32_t len)
Send data based on TCP or UDP builded already in single mode. More...
bool | send (uint8_t mux_id, const uint8_t *buffer, uint32_t len)
Send data based on one of TCP or UDP builded already in multiple mode. More...
uint32_t | recv (uint8_t *buffer, uint32_t buffer_size, uint32_t timeout=1000)
Receive data from TCP or UDP builded already in single mode. More...
uint32_t | recv (uint8_t mux_id, uint8_t *buffer, uint32_t buffer_size, uint32_t timeout=1000)
Receive data from one of TCP or UDP builded already in multiple mode. More...
uint32_t | recv (uint8_t *coming_mux_id, uint8_t *buffer, uint32_t buffer_size, uint32_t timeout=1000)
Receive data from all of TCP or UDP builded already in multiple mode. More...

Detailed Description

Provide an easy-to-use way to manipulate ESP8266.

Examples:
ConnectWiFi.ino, HTTPGET.ino, TCPClientMultiple.ino, TCPClientSingle.ino, TCPClientSingleUNO.ino, TCPServer.ino, UDPClientMultiple.ino, and UDPClientSingle.ino.

Definition at line 38 of file ESP8266.h.

Member Function Documentation

bool ESP8266::createTCP | ( | String | addr,
 |  | uint32_t | port
 | ) |  |

Create TCP connection in single mode.

Parameters
addr | - the IP or domain name of the target host.
port | - the port number of the target host.
Return values
true | - success.
false | - failure.
Examples:
HTTPGET.ino, TCPClientMultiple.ino, TCPClientSingle.ino, and TCPClientSingleUNO.ino.

Definition at line 191 of file ESP8266.cpp.

bool ESP8266::createTCP | ( | uint8_t | mux_id,
 |  | String | addr,
 |  | uint32_t | port
 | ) |  |

Create TCP connection in multiple mode.

Parameters
mux_id | - the identifier of this TCP(available value: 0 - 4).
addr | - the IP or domain name of the target host.
port | - the port number of the target host.
Return values
true | - success.
false | - failure.

Definition at line 211 of file ESP8266.cpp.

bool ESP8266::disableMUX ( void )

Disable IP MUX(single connection mode).

In single connection mode, only one TCP or UDP communication can be builded.

Return values
true | - success.
false | - failure.
Examples:
HTTPGET.ino, TCPClientSingle.ino, TCPClientSingleUNO.ino, and UDPClientSingle.ino.

Definition at line 186 of file ESP8266.cpp.

bool ESP8266::enableMUX ( void )

Enable IP MUX(multiple connection mode).

In multiple connection mode, a couple of TCP and UDP communication can be builded. They can be distinguished by the identifier of TCP or UDP named mux_id.

Return values
true | - success.
false | - failure.
Examples:
TCPClientMultiple.ino, TCPServer.ino, and UDPClientMultiple.ino.

Definition at line 181 of file ESP8266.cpp.

String ESP8266::getAPList ( void )

Search available AP list and return it.

Returns
the list of available APs.
Note
This method will occupy a lot of memeory(hundreds of Bytes to a couple of KBytes). Do not call this method unless you must and ensure that your board has enough memery left.

Definition at line 138 of file ESP8266.cpp.

String ESP8266::getIPStatus ( void )

Get the current status of connection(UDP and TCP).

Returns
the status.
Examples:
TCPServer.ino.

Definition at line 167 of file ESP8266.cpp.

String ESP8266::getJoinedDeviceIP ( void )

Get the IP list of devices connected to SoftAP.

Returns
the list of IP.
Note
This method should not be called when station mode.

Definition at line 160 of file ESP8266.cpp.

String ESP8266::getLocalIP ( void )

Get the IP address of ESP8266.

Returns
the IP list.
Examples:
ConnectWiFi.ino, HTTPGET.ino, TCPClientMultiple.ino, TCPClientSingle.ino, TCPClientSingleUNO.ino, TCPServer.ino, UDPClientMultiple.ino, and UDPClientSingle.ino.

Definition at line 174 of file ESP8266.cpp.

String ESP8266::getVersion ( void )

Get the version of AT Command Set.

Returns
the string of version.
Examples:
ConnectWiFi.ino, HTTPGET.ino, TCPClientMultiple.ino, TCPClientSingle.ino, TCPClientSingleUNO.ino, TCPServer.ino, UDPClientMultiple.ino, and UDPClientSingle.ino.

Definition at line 80 of file ESP8266.cpp.

bool ESP8266::joinAP | ( | String | ssid,
 |  | String | pwd
 | ) |  |

Join in AP.

Parameters
ssid | - SSID of AP to join in.
pwd | - Password of AP to join in.
Return values
true | - success.
false | - failure.
Note
This method will take a couple of seconds.
Examples:
ConnectWiFi.ino, HTTPGET.ino, TCPClientMultiple.ino, TCPClientSingle.ino, TCPClientSingleUNO.ino, TCPServer.ino, UDPClientMultiple.ino, and UDPClientSingle.ino.

Definition at line 145 of file ESP8266.cpp.

bool ESP8266::kick ( void )

Verify ESP8266 whether live or not.

Actually, this method will send command "AT" to ESP8266 and waiting for "OK".

Return values
true | - alive.
false | - dead.

Definition at line 58 of file ESP8266.cpp.

bool ESP8266::leaveAP ( void )

Leave AP joined before.

Return values
true | - success.
false | - failure.

Definition at line 150 of file ESP8266.cpp.

uint32_t ESP8266::recv | ( | uint8_t * | buffer,
 |  | uint32_t | buffer_size,
 |  | uint32_t | timeout = 1000
 | ) |  |

Receive data from TCP or UDP builded already in single mode.

Parameters
buffer | - the buffer for storing data.
buffer_size | - the length of the buffer.
timeout | - the time waiting data.
Returns
the length of data received actually.
Examples:
HTTPGET.ino, TCPClientMultiple.ino, TCPClientSingle.ino, TCPClientSingleUNO.ino, TCPServer.ino, UDPClientMultiple.ino, and UDPClientSingle.ino.

Definition at line 271 of file ESP8266.cpp.

uint32_t ESP8266::recv | ( | uint8_t | mux_id,
 |  | uint8_t * | buffer,
 |  | uint32_t | buffer_size,
 |  | uint32_t | timeout = 1000
 | ) |  |

Receive data from one of TCP or UDP builded already in multiple mode.

Parameters
mux_id | - the identifier of this TCP(available value: 0 - 4).
buffer | - the buffer for storing data.
buffer_size | - the length of the buffer.
timeout | - the time waiting data.
Returns
the length of data received actually.

Definition at line 276 of file ESP8266.cpp.

uint32_t ESP8266::recv | ( | uint8_t * | coming_mux_id,
 |  | uint8_t * | buffer,
 |  | uint32_t | buffer_size,
 |  | uint32_t | timeout = 1000
 | ) |  |

Receive data from all of TCP or UDP builded already in multiple mode.

After return, coming_mux_id store the id of TCP or UDP from which data coming. User should read the value of coming_mux_id and decide what next to do.

Parameters
coming_mux_id | - the identifier of TCP or UDP.
buffer | - the buffer for storing data.
buffer_size | - the length of the buffer.
timeout | - the time waiting data.
Returns
the length of data received actually.

Definition at line 287 of file ESP8266.cpp.

bool ESP8266::registerUDP | ( | String | addr,
 |  | uint32_t | port
 | ) |  |

Register UDP port number in single mode.

Parameters
addr | - the IP or domain name of the target host.
port | - the port number of the target host.
Return values
true | - success.
false | - failure.
Examples:
UDPClientMultiple.ino, and UDPClientSingle.ino.

Definition at line 201 of file ESP8266.cpp.

bool ESP8266::registerUDP | ( | uint8_t | mux_id,
 |  | String | addr,
 |  | uint32_t | port
 | ) |  |

Register UDP port number in multiple mode.

Parameters
mux_id | - the identifier of this TCP(available value: 0 - 4).
addr | - the IP or domain name of the target host.
port | - the port number of the target host.
Return values
true | - success.
false | - failure.

Definition at line 221 of file ESP8266.cpp.

bool ESP8266::releaseTCP ( void )

Release TCP connection in single mode.

Return values
true | - success.
false | - failure.
Examples:
HTTPGET.ino, TCPClientMultiple.ino, TCPClientSingle.ino, TCPClientSingleUNO.ino, and TCPServer.ino.

Definition at line 196 of file ESP8266.cpp.

bool ESP8266::releaseTCP ( uint8_t mux_id )

Release TCP connection in multiple mode.

Parameters
mux_id - the identifier of this TCP(available value: 0 - 4).
Return values
true | - success.
false | - failure.

Definition at line 216 of file ESP8266.cpp.

bool ESP8266::restart ( void )

Restart ESP8266 by "AT+RST".

This method will take 3 seconds or more.

Return values
true | - success.
false | - failure.

Definition at line 63 of file ESP8266.cpp.

bool ESP8266::send | ( | const uint8_t * | buffer,
 |  | uint32_t | len
 | ) |  |

Send data based on TCP or UDP builded already in single mode.

Parameters
buffer | - the buffer of data to send.
len | - the length of data to send.
Return values
true | - success.
false | - failure.
Examples:
HTTPGET.ino, TCPClientMultiple.ino, TCPClientSingle.ino, TCPClientSingleUNO.ino, TCPServer.ino, UDPClientMultiple.ino, and UDPClientSingle.ino.

Definition at line 261 of file ESP8266.cpp.

bool ESP8266::send | ( | uint8_t | mux_id,
 |  | const uint8_t * | buffer,
 |  | uint32_t | len
 | ) |  |

Send data based on one of TCP or UDP builded already in multiple mode.

Parameters
mux_id | - the identifier of this TCP(available value: 0 - 4).
buffer | - the buffer of data to send.
len | - the length of data to send.
Return values
true | - success.
false | - failure.

Definition at line 266 of file ESP8266.cpp.

bool ESP8266::setOprToSoftAP ( void )

Set operation mode to softap.

Return values
true | - success.
false | - failure.

Definition at line 104 of file ESP8266.cpp.

bool ESP8266::setOprToStation ( void )

Set operation mode to staion.

Return values
true | - success.
false | - failure.
Examples:
ConnectWiFi.ino.

Definition at line 87 of file ESP8266.cpp.

bool ESP8266::setOprToStationSoftAP ( void )

Set operation mode to station + softap.

Return values
true | - success.
false | - failure.
Examples:
HTTPGET.ino, TCPClientMultiple.ino, TCPClientSingle.ino, TCPClientSingleUNO.ino, TCPServer.ino, UDPClientMultiple.ino, and UDPClientSingle.ino.

Definition at line 121 of file ESP8266.cpp.

bool ESP8266::setSoftAPParam | ( | String | ssid,
 |  | String | pwd,
 |  | uint8_t | chl = 7,
 |  | uint8_t | ecn = 4
 | ) |  |

Set SoftAP parameters.

Parameters
ssid | - SSID of SoftAP.
pwd | - PASSWORD of SoftAP.
chl | - the channel (1 - 13, default: 7).
ecn | - the way of encrypstion (0 - OPEN, 1 - WEP, 2 - WPA_PSK, 3 - WPA2_PSK, 4 - WPA_WPA2_PSK, default: 4).
Note
This method should not be called when station mode.

Definition at line 155 of file ESP8266.cpp.

bool ESP8266::setTCPServerTimeout ( uint32_t timeout = 180 )

Set the timeout of TCP Server.

Parameters
timeout - the duration for timeout by second(0 ~ 28800, default:180).
Return values
true | - success.
false | - failure.
Examples:
TCPServer.ino.

Definition at line 231 of file ESP8266.cpp.

bool ESP8266::startServer ( uint32_t port = 333 )

Start Server(Only in multiple mode).

Parameters
port - the port number to listen(default: 333).
Return values
true | - success.
false | - failure.
See also
String getIPStatus(void);
uint32_t recv(uint8_t *coming_mux_id, uint8_t *buffer, uint32_t len, uint32_t timeout);

Definition at line 251 of file ESP8266.cpp.

bool ESP8266::startTCPServer ( uint32_t port = 333 )

Start TCP Server(Only in multiple mode).

After started, user should call method: getIPStatus to know the status of TCP connections. The methods of receiving data can be called for user's any purpose. After communication, release the TCP connection is needed by calling method: releaseTCP with mux_id.

Parameters
port - the port number to listen(default: 333).
Return values
true | - success.
false | - failure.
See also
String getIPStatus(void);
uint32_t recv(uint8_t *coming_mux_id, uint8_t *buffer, uint32_t len, uint32_t timeout);
bool releaseTCP(uint8_t mux_id);
Examples:
TCPServer.ino.

Definition at line 236 of file ESP8266.cpp.

bool ESP8266::stopServer ( void )

Stop Server(Only in multiple mode).

Return values
true | - success.
false | - failure.

Definition at line 256 of file ESP8266.cpp.

bool ESP8266::stopTCPServer ( void )

Stop TCP Server(Only in multiple mode).

Return values
true | - success.
false | - failure.

Definition at line 244 of file ESP8266.cpp.

bool ESP8266::unregisterUDP ( void )

Unregister UDP port number in single mode.

Return values
true | - success.
false | - failure.
Examples:
UDPClientMultiple.ino, and UDPClientSingle.ino.

Definition at line 206 of file ESP8266.cpp.

bool ESP8266::unregisterUDP ( uint8_t mux_id )

Unregister UDP port number in multiple mode.

Parameters
mux_id - the identifier of this TCP(available value: 0 - 4).
Return values
true | - success.
false | - failure.

Definition at line 226 of file ESP8266.cpp.

The documentation for this class was generated from the following files:
  • ESP8266.h
  • ESP8266.cpp


API: Class Index

API
  • Related Pages
  • Classes
  • Files
  • Examples
  • Class List
  • Class Index
  • Class Members
Class Index
E
E
ESP8266
E


API: Class Members

API
  • Related Pages
  • Classes
  • Files
  • Examples
  • Class List
  • Class Index
  • Class Members
  • All
  • Functions
  • c
  • d
  • e
  • g
  • j
  • k
  • l
  • r
  • s
  • u
Here is a list of all documented class members with links to the class documentation for each member:

- c -

  • createTCP() : ESP8266

- d -

  • disableMUX() : ESP8266

- e -

  • enableMUX() : ESP8266

- g -

  • getAPList() : ESP8266
  • getIPStatus() : ESP8266
  • getJoinedDeviceIP() : ESP8266
  • getLocalIP() : ESP8266
  • getVersion() : ESP8266

- j -

  • joinAP() : ESP8266

- k -

  • kick() : ESP8266

- l -

  • leaveAP() : ESP8266

- r -

  • recv() : ESP8266
  • registerUDP() : ESP8266
  • releaseTCP() : ESP8266
  • restart() : ESP8266

- s -

  • send() : ESP8266
  • setOprToSoftAP() : ESP8266
  • setOprToStation() : ESP8266
  • setOprToStationSoftAP() : ESP8266
  • setSoftAPParam() : ESP8266
  • setTCPServerTimeout() : ESP8266
  • startServer() : ESP8266
  • startTCPServer() : ESP8266
  • stopServer() : ESP8266
  • stopTCPServer() : ESP8266

- u -

  • unregisterUDP() : ESP8266


API: Class Members - Functions

API
  • Related Pages
  • Classes
  • Files
  • Examples
  • Class List
  • Class Index
  • Class Members
  • All
  • Functions
  • c
  • d
  • e
  • g
  • j
  • k
  • l
  • r
  • s
  • u

- c -

  • createTCP() : ESP8266

- d -

  • disableMUX() : ESP8266

- e -

  • enableMUX() : ESP8266

- g -

  • getAPList() : ESP8266
  • getIPStatus() : ESP8266
  • getJoinedDeviceIP() : ESP8266
  • getLocalIP() : ESP8266
  • getVersion() : ESP8266

- j -

  • joinAP() : ESP8266

- k -

  • kick() : ESP8266

- l -

  • leaveAP() : ESP8266

- r -

  • recv() : ESP8266
  • registerUDP() : ESP8266
  • releaseTCP() : ESP8266
  • restart() : ESP8266

- s -

  • send() : ESP8266
  • setOprToSoftAP() : ESP8266
  • setOprToStation() : ESP8266
  • setOprToStationSoftAP() : ESP8266
  • setSoftAPParam() : ESP8266
  • setTCPServerTimeout() : ESP8266
  • startServer() : ESP8266
  • startTCPServer() : ESP8266
  • stopServer() : ESP8266
  • stopTCPServer() : ESP8266

- u -

  • unregisterUDP() : ESP8266


API: File List

API
  • Related Pages
  • Classes
  • Files
  • Examples
  • File List
File List
Here is a list of all documented files with brief descriptions:
[detail level 123]
▼ examples |
▼ ConnectWiFi |
ConnectWiFi.ino |
▼ HTTPGET |
HTTPGET.ino |
▼ TCPClientMultiple |
TCPClientMultiple.ino |
▼ TCPClientSingle |
TCPClientSingle.ino |
▼ TCPClientSingleUNO |
TCPClientSingleUNO.ino |
▼ TCPServer |
TCPServer.ino |
▼ UDPClientMultiple |
UDPClientMultiple.ino |
▼ UDPClientSingle |
UDPClientSingle.ino |
doxygen.h | Define modules in API doc
ESP8266.cpp | The implementation of class ESP8266
ESP8266.h | The definition of class ESP8266


API: examples Directory Reference

API
  • Related Pages
  • Classes
  • Files
  • Examples
  • examples
examples Directory Reference

Directories

directory | ConnectWiFi
directory | HTTPGET
directory | TCPClientMultiple
directory | TCPClientSingle
directory | TCPClientSingleUNO
directory | TCPServer
directory | UDPClientMultiple
directory | UDPClientSingle


API: examples/ConnectWiFi Directory Reference

API
  • Related Pages
  • Classes
  • Files
  • Examples
  • examples
  • ConnectWiFi
ConnectWiFi Directory Reference

Files

file ConnectWiFi.ino [code]


API: examples/ConnectWiFi/ConnectWiFi.ino Source File

API
  • Related Pages
  • Classes
  • Files
  • Examples
  • File List
  • examples
  • ConnectWiFi
ConnectWiFi.ino
1
21 #include "ESP8266.h"
22
23 #define SSID "ITEAD"
24 #define PASSWORD "12345678"
25
26 ESP8266 wifi(Serial1);
27
28 void setup(void)
29 {
30 Serial.begin(9600);
31 Serial.print("setup begin\r\n");
32
33 Serial.print("FW Version: ");
34 Serial.println(wifi.getVersion().c_str());
35
36
37 if (wifi.setOprToStation()) {
38 Serial.print("to station ok\r\n");
39 } else {
40 Serial.print("to station err\r\n");
41 }
42
43 if (wifi.joinAP(SSID, PASSWORD)) {
44 Serial.print("Join AP success\r\n");
45 Serial.print("IP: ");
46 Serial.println(wifi.getLocalIP().c_str());
47 } else {
48 Serial.print("Join AP failure\r\n");
49 }
50
51 Serial.print("setup end\r\n");
52 }
53
54 void loop(void)
55 {
56 }
57
ESP8266::getVersion
String getVersion(void)
Get the version of AT Command Set.
Definition: ESP8266.cpp:80
ESP8266::getLocalIP
String getLocalIP(void)
Get the IP address of ESP8266.
Definition: ESP8266.cpp:174
ESP8266.h
The definition of class ESP8266.
ESP8266::joinAP
bool joinAP(String ssid, String pwd)
Join in AP.
Definition: ESP8266.cpp:145
ESP8266
Provide an easy-to-use way to manipulate ESP8266.
Definition: ESP8266.h:38
ESP8266::setOprToStation
bool setOprToStation(void)
Set operation mode to staion.
Definition: ESP8266.cpp:87


API: examples/HTTPGET Directory Reference

API
  • Related Pages
  • Classes
  • Files
  • Examples
  • examples
  • HTTPGET
HTTPGET Directory Reference

Files

file HTTPGET.ino [code]


API: examples/HTTPGET/HTTPGET.ino Source File

API
  • Related Pages
  • Classes
  • Files
  • Examples
  • File List
  • examples
  • HTTPGET
HTTPGET.ino
1
22 #include "ESP8266.h"
23
24 #define SSID "ITEAD"
25 #define PASSWORD "12345678"
26 #define HOST_NAME "www.baidu.com"
27 #define HOST_PORT (80)
28
29 ESP8266 wifi(Serial1);
30
31 void setup(void)
32 {
33 Serial.begin(9600);
34 Serial.print("setup begin\r\n");
35
36 Serial.print("FW Version:");
37 Serial.println(wifi.getVersion().c_str());
38
39 if (wifi.setOprToStationSoftAP()) {
40 Serial.print("to station + softap ok\r\n");
41 } else {
42 Serial.print("to station + softap err\r\n");
43 }
44
45 if (wifi.joinAP(SSID, PASSWORD)) {
46 Serial.print("Join AP success\r\n");
47
48 Serial.print("IP:");
49 Serial.println( wifi.getLocalIP().c_str());
50 } else {
51 Serial.print("Join AP failure\r\n");
52 }
53
54 if (wifi.disableMUX()) {
55 Serial.print("single ok\r\n");
56 } else {
57 Serial.print("single err\r\n");
58 }
59
60 Serial.print("setup end\r\n");
61 }
62
63 void loop(void)
64 {
65 uint8_t buffer[1024] = {0};
66
67 if (wifi.createTCP(HOST_NAME, HOST_PORT)) {
68 Serial.print("create tcp ok\r\n");
69 } else {
70 Serial.print("create tcp err\r\n");
71 }
72
73 char *hello = "GET / HTTP/1.1\r\nHost: www.baidu.com\r\nConnection: close\r\n\r\n";
74 wifi.send((const uint8_t*)hello, strlen(hello));
75
76 uint32_t len = wifi.recv(buffer, sizeof(buffer), 10000);
77 if (len > 0) {
78 Serial.print("Received:[");
79 for(uint32_t i = 0; i < len; i++) {
80 Serial.print((char)buffer[i]);
81 }
82 Serial.print("]\r\n");
83 }
84
85 if (wifi.releaseTCP()) {
86 Serial.print("release tcp ok\r\n");
87 } else {
88 Serial.print("release tcp err\r\n");
89 }
90
91 while(1);
92
93 }
94
ESP8266::send
bool send(const uint8_t *buffer, uint32_t len)
Send data based on TCP or UDP builded already in single mode.
Definition: ESP8266.cpp:261
ESP8266::getVersion
String getVersion(void)
Get the version of AT Command Set.
Definition: ESP8266.cpp:80
ESP8266::releaseTCP
bool releaseTCP(void)
Release TCP connection in single mode.
Definition: ESP8266.cpp:196
ESP8266::recv
uint32_t recv(uint8_t *buffer, uint32_t buffer_size, uint32_t timeout=1000)
Receive data from TCP or UDP builded already in single mode.
Definition: ESP8266.cpp:271
ESP8266::getLocalIP
String getLocalIP(void)
Get the IP address of ESP8266.
Definition: ESP8266.cpp:174
ESP8266.h
The definition of class ESP8266.
ESP8266::setOprToStationSoftAP
bool setOprToStationSoftAP(void)
Set operation mode to station + softap.
Definition: ESP8266.cpp:121
ESP8266::createTCP
bool createTCP(String addr, uint32_t port)
Create TCP connection in single mode.
Definition: ESP8266.cpp:191
ESP8266::disableMUX
bool disableMUX(void)
Disable IP MUX(single connection mode).
Definition: ESP8266.cpp:186
ESP8266::joinAP
bool joinAP(String ssid, String pwd)
Join in AP.
Definition: ESP8266.cpp:145
ESP8266
Provide an easy-to-use way to manipulate ESP8266.
Definition: ESP8266.h:38


API: examples/TCPClientMultiple Directory Reference

API
  • Related Pages
  • Classes
  • Files
  • Examples
  • examples
  • TCPClientMultiple
TCPClientMultiple Directory Reference

Files

file TCPClientMultiple.ino [code]


API: examples/TCPClientMultiple/TCPClientMultiple.ino Source File

API
  • Related Pages
  • Classes
  • Files
  • Examples
  • File List
  • examples
  • TCPClientMultiple
TCPClientMultiple.ino
1
21 #include "ESP8266.h"
22
23 #define SSID "ITEAD"
24 #define PASSWORD "12345678"
25 #define HOST_NAME "172.16.5.12"
26 #define HOST_PORT (8090)
27
28 ESP8266 wifi(Serial1);
29
30 void setup(void)
31 {
32 Serial.begin(9600);
33 Serial.print("setup begin\r\n");
34
35 Serial.print("FW Version: ");
36 Serial.println(wifi.getVersion().c_str());
37
38
39 if (wifi.setOprToStationSoftAP()) {
40 Serial.print("to station + softap ok\r\n");
41 } else {
42 Serial.print("to station + softap err\r\n");
43 }
44
45 if (wifi.joinAP(SSID, PASSWORD)) {
46 Serial.print("Join AP success\r\n");
47 Serial.print("IP: ");
48 Serial.println(wifi.getLocalIP().c_str());
49 } else {
50 Serial.print("Join AP failure\r\n");
51 }
52
53 if (wifi.enableMUX()) {
54 Serial.print("multiple ok\r\n");
55 } else {
56 Serial.print("multiple err\r\n");
57 }
58
59 Serial.print("setup end\r\n");
60 }
61
62 void loop(void)
63 {
64 uint8_t buffer[128] = {0};
65 static uint8_t mux_id = 0;
66
67 if (wifi.createTCP(mux_id, HOST_NAME, HOST_PORT)) {
68 Serial.print("create tcp ");
69 Serial.print(mux_id);
70 Serial.println(" ok");
71 } else {
72 Serial.print("create tcp ");
73 Serial.print(mux_id);
74 Serial.println(" err");
75 }
76
77
78 char *hello = "Hello, this is client!";
79 if (wifi.send(mux_id, (const uint8_t*)hello, strlen(hello))) {
80 Serial.println("send ok");
81 } else {
82 Serial.println("send err");
83 }
84
85 uint32_t len = wifi.recv(mux_id, buffer, sizeof(buffer), 10000);
86 if (len > 0) {
87 Serial.print("Received:[");
88 for(uint32_t i = 0; i < len; i++) {
89 Serial.print((char)buffer[i]);
90 }
91 Serial.print("]\r\n");
92 }
93
94 if (wifi.releaseTCP(mux_id)) {
95 Serial.print("release tcp ");
96 Serial.print(mux_id);
97 Serial.println(" ok");
98 } else {
99 Serial.print("release tcp ");
100 Serial.print(mux_id);
101 Serial.println(" err");
102 }
103
104 delay(3000);
105 mux_id++;
106 if (mux_id >= 5) {
107 mux_id = 0;
108 }
109 }
110
ESP8266::send
bool send(const uint8_t *buffer, uint32_t len)
Send data based on TCP or UDP builded already in single mode.
Definition: ESP8266.cpp:261
ESP8266::getVersion
String getVersion(void)
Get the version of AT Command Set.
Definition: ESP8266.cpp:80
ESP8266::releaseTCP
bool releaseTCP(void)
Release TCP connection in single mode.
Definition: ESP8266.cpp:196
ESP8266::recv
uint32_t recv(uint8_t *buffer, uint32_t buffer_size, uint32_t timeout=1000)
Receive data from TCP or UDP builded already in single mode.
Definition: ESP8266.cpp:271
ESP8266::enableMUX
bool enableMUX(void)
Enable IP MUX(multiple connection mode).
Definition: ESP8266.cpp:181
ESP8266::getLocalIP
String getLocalIP(void)
Get the IP address of ESP8266.
Definition: ESP8266.cpp:174
ESP8266.h
The definition of class ESP8266.
ESP8266::setOprToStationSoftAP
bool setOprToStationSoftAP(void)
Set operation mode to station + softap.
Definition: ESP8266.cpp:121
ESP8266::createTCP
bool createTCP(String addr, uint32_t port)
Create TCP connection in single mode.
Definition: ESP8266.cpp:191
ESP8266::joinAP
bool joinAP(String ssid, String pwd)
Join in AP.
Definition: ESP8266.cpp:145
ESP8266
Provide an easy-to-use way to manipulate ESP8266.
Definition: ESP8266.h:38


API: examples/TCPClientSingle Directory Reference

API
  • Related Pages
  • Classes
  • Files
  • Examples
  • examples
  • TCPClientSingle
TCPClientSingle Directory Reference

Files

file TCPClientSingle.ino [code]


API: examples/TCPClientSingle/TCPClientSingle.ino Source File

API
  • Related Pages
  • Classes
  • Files
  • Examples
  • File List
  • examples
  • TCPClientSingle
TCPClientSingle.ino
1
21 #include "ESP8266.h"
22
23 #define SSID "ITEAD"
24 #define PASSWORD "12345678"
25 #define HOST_NAME "172.16.5.12"
26 #define HOST_PORT (8090)
27
28 ESP8266 wifi(Serial1);
29
30 void setup(void)
31 {
32 Serial.begin(9600);
33 Serial.print("setup begin\r\n");
34
35 Serial.print("FW Version:");
36 Serial.println(wifi.getVersion().c_str());
37
38 if (wifi.setOprToStationSoftAP()) {
39 Serial.print("to station + softap ok\r\n");
40 } else {
41 Serial.print("to station + softap err\r\n");
42 }
43
44 if (wifi.joinAP(SSID, PASSWORD)) {
45 Serial.print("Join AP success\r\n");
46 Serial.print("IP:");
47 Serial.println( wifi.getLocalIP().c_str());
48 } else {
49 Serial.print("Join AP failure\r\n");
50 }
51
52 if (wifi.disableMUX()) {
53 Serial.print("single ok\r\n");
54 } else {
55 Serial.print("single err\r\n");
56 }
57
58 Serial.print("setup end\r\n");
59 }
60
61 void loop(void)
62 {
63 uint8_t buffer[128] = {0};
64
65 if (wifi.createTCP(HOST_NAME, HOST_PORT)) {
66 Serial.print("create tcp ok\r\n");
67 } else {
68 Serial.print("create tcp err\r\n");
69 }
70
71 char *hello = "Hello, this is client!";
72 wifi.send((const uint8_t*)hello, strlen(hello));
73
74 uint32_t len = wifi.recv(buffer, sizeof(buffer), 10000);
75 if (len > 0) {
76 Serial.print("Received:[");
77 for(uint32_t i = 0; i < len; i++) {
78 Serial.print((char)buffer[i]);
79 }
80 Serial.print("]\r\n");
81 }
82
83 if (wifi.releaseTCP()) {
84 Serial.print("release tcp ok\r\n");
85 } else {
86 Serial.print("release tcp err\r\n");
87 }
88 delay(5000);
89 }
90
ESP8266::send
bool send(const uint8_t *buffer, uint32_t len)
Send data based on TCP or UDP builded already in single mode.
Definition: ESP8266.cpp:261
ESP8266::getVersion
String getVersion(void)
Get the version of AT Command Set.
Definition: ESP8266.cpp:80
ESP8266::releaseTCP
bool releaseTCP(void)
Release TCP connection in single mode.
Definition: ESP8266.cpp:196
ESP8266::recv
uint32_t recv(uint8_t *buffer, uint32_t buffer_size, uint32_t timeout=1000)
Receive data from TCP or UDP builded already in single mode.
Definition: ESP8266.cpp:271
ESP8266::getLocalIP
String getLocalIP(void)
Get the IP address of ESP8266.
Definition: ESP8266.cpp:174
ESP8266.h
The definition of class ESP8266.
ESP8266::setOprToStationSoftAP
bool setOprToStationSoftAP(void)
Set operation mode to station + softap.
Definition: ESP8266.cpp:121
ESP8266::createTCP
bool createTCP(String addr, uint32_t port)
Create TCP connection in single mode.
Definition: ESP8266.cpp:191
ESP8266::disableMUX
bool disableMUX(void)
Disable IP MUX(single connection mode).
Definition: ESP8266.cpp:186
ESP8266::joinAP
bool joinAP(String ssid, String pwd)
Join in AP.
Definition: ESP8266.cpp:145
ESP8266
Provide an easy-to-use way to manipulate ESP8266.
Definition: ESP8266.h:38


API: examples/TCPClientSingleUNO Directory Reference

API
  • Related Pages
  • Classes
  • Files
  • Examples
  • examples
  • TCPClientSingleUNO
TCPClientSingleUNO Directory Reference

Files

file TCPClientSingleUNO.ino [code]


API: examples/TCPClientSingleUNO/TCPClientSingleUNO.ino Source File

API
  • Related Pages
  • Classes
  • Files
  • Examples
  • File List
  • examples
  • TCPClientSingleUNO
TCPClientSingleUNO.ino
1
21 #include "ESP8266.h"
22 #include <SoftwareSerial.h>
23
24 #define SSID "ITEAD"
25 #define PASSWORD "12345678"
26 #define HOST_NAME "172.16.5.12"
27 #define HOST_PORT (8090)
28
29 SoftwareSerial mySerial(3, 2); /* RX:D3, TX:D2 */
30 ESP8266 wifi(mySerial);
31
32 void setup(void)
33 {
34 Serial.begin(9600);
35 Serial.print("setup begin\r\n");
36
37 Serial.print("FW Version:");
38 Serial.println(wifi.getVersion().c_str());
39
40 if (wifi.setOprToStationSoftAP()) {
41 Serial.print("to station + softap ok\r\n");
42 } else {
43 Serial.print("to station + softap err\r\n");
44 }
45
46 if (wifi.joinAP(SSID, PASSWORD)) {
47 Serial.print("Join AP success\r\n");
48 Serial.print("IP:");
49 Serial.println( wifi.getLocalIP().c_str());
50 } else {
51 Serial.print("Join AP failure\r\n");
52 }
53
54 if (wifi.disableMUX()) {
55 Serial.print("single ok\r\n");
56 } else {
57 Serial.print("single err\r\n");
58 }
59
60 Serial.print("setup end\r\n");
61 }
62
63 void loop(void)
64 {
65 uint8_t buffer[128] = {0};
66
67 if (wifi.createTCP(HOST_NAME, HOST_PORT)) {
68 Serial.print("create tcp ok\r\n");
69 } else {
70 Serial.print("create tcp err\r\n");
71 }
72
73 char *hello = "Hello, this is client!";
74 wifi.send((const uint8_t*)hello, strlen(hello));
75
76 uint32_t len = wifi.recv(buffer, sizeof(buffer), 10000);
77 if (len > 0) {
78 Serial.print("Received:[");
79 for(uint32_t i = 0; i < len; i++) {
80 Serial.print((char)buffer[i]);
81 }
82 Serial.print("]\r\n");
83 }
84
85 if (wifi.releaseTCP()) {
86 Serial.print("release tcp ok\r\n");
87 } else {
88 Serial.print("release tcp err\r\n");
89 }
90 delay(5000);
91 }
92
ESP8266::send
bool send(const uint8_t *buffer, uint32_t len)
Send data based on TCP or UDP builded already in single mode.
Definition: ESP8266.cpp:261
ESP8266::getVersion
String getVersion(void)
Get the version of AT Command Set.
Definition: ESP8266.cpp:80
ESP8266::releaseTCP
bool releaseTCP(void)
Release TCP connection in single mode.
Definition: ESP8266.cpp:196
ESP8266::recv
uint32_t recv(uint8_t *buffer, uint32_t buffer_size, uint32_t timeout=1000)
Receive data from TCP or UDP builded already in single mode.
Definition: ESP8266.cpp:271
ESP8266::getLocalIP
String getLocalIP(void)
Get the IP address of ESP8266.
Definition: ESP8266.cpp:174
ESP8266.h
The definition of class ESP8266.
ESP8266::setOprToStationSoftAP
bool setOprToStationSoftAP(void)
Set operation mode to station + softap.
Definition: ESP8266.cpp:121
ESP8266::createTCP
bool createTCP(String addr, uint32_t port)
Create TCP connection in single mode.
Definition: ESP8266.cpp:191
ESP8266::disableMUX
bool disableMUX(void)
Disable IP MUX(single connection mode).
Definition: ESP8266.cpp:186
ESP8266::joinAP
bool joinAP(String ssid, String pwd)
Join in AP.
Definition: ESP8266.cpp:145
ESP8266
Provide an easy-to-use way to manipulate ESP8266.
Definition: ESP8266.h:38


API: examples/TCPServer Directory Reference

API
  • Related Pages
  • Classes
  • Files
  • Examples
  • examples
  • TCPServer
TCPServer Directory Reference

Files

file TCPServer.ino [code]


API: examples/TCPServer/TCPServer.ino Source File

API
  • Related Pages
  • Classes
  • Files
  • Examples
  • File List
  • examples
  • TCPServer
TCPServer.ino
1
22 #include "ESP8266.h"
23
24 #define SSID "ITEAD"
25 #define PASSWORD "12345678"
26
27 ESP8266 wifi(Serial1);
28
29 void setup(void)
30 {
31 Serial.begin(9600);
32 Serial.print("setup begin\r\n");
33
34 Serial.print("FW Version:");
35 Serial.println(wifi.getVersion().c_str());
36
37 if (wifi.setOprToStationSoftAP()) {
38 Serial.print("to station + softap ok\r\n");
39 } else {
40 Serial.print("to station + softap err\r\n");
41 }
42
43 if (wifi.joinAP(SSID, PASSWORD)) {
44 Serial.print("Join AP success\r\n");
45 Serial.print("IP: ");
46 Serial.println(wifi.getLocalIP().c_str());
47 } else {
48 Serial.print("Join AP failure\r\n");
49 }
50
51 if (wifi.enableMUX()) {
52 Serial.print("multiple ok\r\n");
53 } else {
54 Serial.print("multiple err\r\n");
55 }
56
57 if (wifi.startTCPServer(8090)) {
58 Serial.print("start tcp server ok\r\n");
59 } else {
60 Serial.print("start tcp server err\r\n");
61 }
62
63 if (wifi.setTCPServerTimeout(10)) {
64 Serial.print("set tcp server timout 10 seconds\r\n");
65 } else {
66 Serial.print("set tcp server timout err\r\n");
67 }
68
69 Serial.print("setup end\r\n");
70 }
71
72 void loop(void)
73 {
74 uint8_t buffer[128] = {0};
75 uint8_t mux_id;
76 uint32_t len = wifi.recv(&mux_id, buffer, sizeof(buffer), 100);
77 if (len > 0) {
78 Serial.print("Status:[");
79 Serial.print(wifi.getIPStatus().c_str());
80 Serial.println("]");
81
82 Serial.print("Received from :");
83 Serial.print(mux_id);
84 Serial.print("[");
85 for(uint32_t i = 0; i < len; i++) {
86 Serial.print((char)buffer[i]);
87 }
88 Serial.print("]\r\n");
89
90 if(wifi.send(mux_id, buffer, len)) {
91 Serial.print("send back ok\r\n");
92 } else {
93 Serial.print("send back err\r\n");
94 }
95
96 if (wifi.releaseTCP(mux_id)) {
97 Serial.print("release tcp ");
98 Serial.print(mux_id);
99 Serial.println(" ok");
100 } else {
101 Serial.print("release tcp");
102 Serial.print(mux_id);
103 Serial.println(" err");
104 }
105
106 Serial.print("Status:[");
107 Serial.print(wifi.getIPStatus().c_str());
108 Serial.println("]");
109 }
110 }
111
ESP8266::send
bool send(const uint8_t *buffer, uint32_t len)
Send data based on TCP or UDP builded already in single mode.
Definition: ESP8266.cpp:261
ESP8266::getVersion
String getVersion(void)
Get the version of AT Command Set.
Definition: ESP8266.cpp:80
ESP8266::releaseTCP
bool releaseTCP(void)
Release TCP connection in single mode.
Definition: ESP8266.cpp:196
ESP8266::recv
uint32_t recv(uint8_t *buffer, uint32_t buffer_size, uint32_t timeout=1000)
Receive data from TCP or UDP builded already in single mode.
Definition: ESP8266.cpp:271
ESP8266::enableMUX
bool enableMUX(void)
Enable IP MUX(multiple connection mode).
Definition: ESP8266.cpp:181
ESP8266::getLocalIP
String getLocalIP(void)
Get the IP address of ESP8266.
Definition: ESP8266.cpp:174
ESP8266.h
The definition of class ESP8266.
ESP8266::setOprToStationSoftAP
bool setOprToStationSoftAP(void)
Set operation mode to station + softap.
Definition: ESP8266.cpp:121
ESP8266::joinAP
bool joinAP(String ssid, String pwd)
Join in AP.
Definition: ESP8266.cpp:145
ESP8266::setTCPServerTimeout
bool setTCPServerTimeout(uint32_t timeout=180)
Set the timeout of TCP Server.
Definition: ESP8266.cpp:231
ESP8266
Provide an easy-to-use way to manipulate ESP8266.
Definition: ESP8266.h:38
ESP8266::startTCPServer
bool startTCPServer(uint32_t port=333)
Start TCP Server(Only in multiple mode).
Definition: ESP8266.cpp:236
ESP8266::getIPStatus
String getIPStatus(void)
Get the current status of connection(UDP and TCP).
Definition: ESP8266.cpp:167


API: examples/UDPClientMultiple Directory Reference

API
  • Related Pages
  • Classes
  • Files
  • Examples
  • examples
  • UDPClientMultiple
UDPClientMultiple Directory Reference

Files

file UDPClientMultiple.ino [code]


API: examples/UDPClientMultiple/UDPClientMultiple.ino Source File

API
  • Related Pages
  • Classes
  • Files
  • Examples
  • File List
  • examples
  • UDPClientMultiple
UDPClientMultiple.ino
1
22 #include "ESP8266.h"
23
24 #define SSID "ITEAD"
25 #define PASSWORD "12345678"
26 #define HOST_NAME "172.16.5.12"
27 #define HOST_PORT (5416)
28
29 ESP8266 wifi(Serial1);
30
31 void setup(void)
32 {
33 Serial.begin(9600);
34 Serial.print("setup begin\r\n");
35
36 Serial.print("FW Version:");
37 Serial.println(wifi.getVersion().c_str());
38
39 if (wifi.setOprToStationSoftAP()) {
40 Serial.print("to station + softap ok\r\n");
41 } else {
42 Serial.print("to station + softap err\r\n");
43 }
44
45 if (wifi.joinAP(SSID, PASSWORD)) {
46 Serial.print("Join AP success\r\n");
47 Serial.print("IP: ");
48 Serial.println(wifi.getLocalIP().c_str());
49 } else {
50 Serial.print("Join AP failure\r\n");
51 }
52
53 if (wifi.enableMUX()) {
54 Serial.print("multiple ok\r\n");
55 } else {
56 Serial.print("multiple err\r\n");
57 }
58
59 Serial.print("setup end\r\n");
60 }
61
62 void loop(void)
63 {
64 uint8_t buffer[128] = {0};
65 static uint8_t mux_id = 0;
66
67 if (wifi.registerUDP(mux_id, HOST_NAME, HOST_PORT)) {
68 Serial.print("register udp ");
69 Serial.print(mux_id);
70 Serial.println(" ok");
71 } else {
72 Serial.print("register udp ");
73 Serial.print(mux_id);
74 Serial.println(" err");
75 }
76
77 char *hello = "Hello, this is client!";
78 wifi.send(mux_id, (const uint8_t*)hello, strlen(hello));
79
80 uint32_t len = wifi.recv(mux_id, buffer, sizeof(buffer), 10000);
81 if (len > 0) {
82 Serial.print("Received:[");
83 for(uint32_t i = 0; i < len; i++) {
84 Serial.print((char)buffer[i]);
85 }
86 Serial.print("]\r\n");
87 }
88
89 if (wifi.unregisterUDP(mux_id)) {
90 Serial.print("unregister udp ");
91 Serial.print(mux_id);
92 Serial.println(" ok");
93 } else {
94 Serial.print("unregister udp ");
95 Serial.print(mux_id);
96 Serial.println(" err");
97 }
98 delay(5000);
99 mux_id++;
100 if (mux_id >= 5) {
101 mux_id = 0;
102 }
103 }
104
ESP8266::send
bool send(const uint8_t *buffer, uint32_t len)
Send data based on TCP or UDP builded already in single mode.
Definition: ESP8266.cpp:261
ESP8266::getVersion
String getVersion(void)
Get the version of AT Command Set.
Definition: ESP8266.cpp:80
ESP8266::recv
uint32_t recv(uint8_t *buffer, uint32_t buffer_size, uint32_t timeout=1000)
Receive data from TCP or UDP builded already in single mode.
Definition: ESP8266.cpp:271
ESP8266::enableMUX
bool enableMUX(void)
Enable IP MUX(multiple connection mode).
Definition: ESP8266.cpp:181
ESP8266::getLocalIP
String getLocalIP(void)
Get the IP address of ESP8266.
Definition: ESP8266.cpp:174
ESP8266.h
The definition of class ESP8266.
ESP8266::setOprToStationSoftAP
bool setOprToStationSoftAP(void)
Set operation mode to station + softap.
Definition: ESP8266.cpp:121
ESP8266::unregisterUDP
bool unregisterUDP(void)
Unregister UDP port number in single mode.
Definition: ESP8266.cpp:206
ESP8266::joinAP
bool joinAP(String ssid, String pwd)
Join in AP.
Definition: ESP8266.cpp:145
ESP8266::registerUDP
bool registerUDP(String addr, uint32_t port)
Register UDP port number in single mode.
Definition: ESP8266.cpp:201
ESP8266
Provide an easy-to-use way to manipulate ESP8266.
Definition: ESP8266.h:38


API: examples/UDPClientSingle Directory Reference

API
  • Related Pages
  • Classes
  • Files
  • Examples
  • examples
  • UDPClientSingle
UDPClientSingle Directory Reference

Files

file UDPClientSingle.ino [code]


API: examples/UDPClientSingle/UDPClientSingle.ino Source File

API
  • Related Pages
  • Classes
  • Files
  • Examples
  • File List
  • examples
  • UDPClientSingle
UDPClientSingle.ino
1
22 #include "ESP8266.h"
23
24 #define SSID "ITEAD"
25 #define PASSWORD "12345678"
26 #define HOST_NAME "172.16.5.12"
27 #define HOST_PORT (5416)
28
29 ESP8266 wifi(Serial1);
30
31 void setup(void)
32 {
33 Serial.begin(9600);
34 Serial.print("setup begin\r\n");
35
36 Serial.print("FW Version:");
37 Serial.println(wifi.getVersion().c_str());
38
39 if (wifi.setOprToStationSoftAP()) {
40 Serial.print("to station + softap ok\r\n");
41 } else {
42 Serial.print("to station + softap err\r\n");
43 }
44
45 if (wifi.joinAP(SSID, PASSWORD)) {
46 Serial.print("Join AP success\r\n");
47 Serial.print("IP: ");
48 Serial.println(wifi.getLocalIP().c_str());
49 } else {
50 Serial.print("Join AP failure\r\n");
51 }
52
53 if (wifi.disableMUX()) {
54 Serial.print("single ok\r\n");
55 } else {
56 Serial.print("single err\r\n");
57 }
58
59 Serial.print("setup end\r\n");
60 }
61
62 void loop(void)
63 {
64 uint8_t buffer[128] = {0};
65
66 if (wifi.registerUDP(HOST_NAME, HOST_PORT)) {
67 Serial.print("register udp ok\r\n");
68 } else {
69 Serial.print("register udp err\r\n");
70 }
71
72 char *hello = "Hello, this is client!";
73 wifi.send((const uint8_t*)hello, strlen(hello));
74
75 uint32_t len = wifi.recv(buffer, sizeof(buffer), 10000);
76 if (len > 0) {
77 Serial.print("Received:[");
78 for(uint32_t i = 0; i < len; i++) {
79 Serial.print((char)buffer[i]);
80 }
81 Serial.print("]\r\n");
82 }
83
84 if (wifi.unregisterUDP()) {
85 Serial.print("unregister udp ok\r\n");
86 } else {
87 Serial.print("unregister udp err\r\n");
88 }
89 delay(5000);
90 }
91
ESP8266::send
bool send(const uint8_t *buffer, uint32_t len)
Send data based on TCP or UDP builded already in single mode.
Definition: ESP8266.cpp:261
ESP8266::getVersion
String getVersion(void)
Get the version of AT Command Set.
Definition: ESP8266.cpp:80
ESP8266::recv
uint32_t recv(uint8_t *buffer, uint32_t buffer_size, uint32_t timeout=1000)
Receive data from TCP or UDP builded already in single mode.
Definition: ESP8266.cpp:271
ESP8266::getLocalIP
String getLocalIP(void)
Get the IP address of ESP8266.
Definition: ESP8266.cpp:174
ESP8266.h
The definition of class ESP8266.
ESP8266::setOprToStationSoftAP
bool setOprToStationSoftAP(void)
Set operation mode to station + softap.
Definition: ESP8266.cpp:121
ESP8266::unregisterUDP
bool unregisterUDP(void)
Unregister UDP port number in single mode.
Definition: ESP8266.cpp:206
ESP8266::disableMUX
bool disableMUX(void)
Disable IP MUX(single connection mode).
Definition: ESP8266.cpp:186
ESP8266::joinAP
bool joinAP(String ssid, String pwd)
Join in AP.
Definition: ESP8266.cpp:145
ESP8266::registerUDP
bool registerUDP(String addr, uint32_t port)
Register UDP port number in single mode.
Definition: ESP8266.cpp:201
ESP8266
Provide an easy-to-use way to manipulate ESP8266.
Definition: ESP8266.h:38


API: doxygen.h File Reference

API
  • Related Pages
  • Classes
  • Files
  • Examples
  • File List
doxygen.h File Reference

Define modules in API doc. More...

Go to the source code of this file.

Detailed Description

Define modules in API doc.

Author
Wu Pengfei (email:pengf.nosp@m.ei.w.nosp@m.u@ite.nosp@m.ad.c.nosp@m.c)
Date
2014/11/20
Copyright
Copyright (C) 2013-2014 ITEAD Intelligent Systems Co., Ltd.
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.

Definition in file doxygen.h.


API: ESP8266.cpp File Reference

API
  • Related Pages
  • Classes
  • Files
  • Examples
  • File List
ESP8266.cpp File Reference

The implementation of class ESP8266. More...

#include "ESP8266.h"

Go to the source code of this file.

Detailed Description

The implementation of class ESP8266.

Author
Wu Pengfeipengf.nosp@m.ei.w.nosp@m.u@ite.nosp@m.ad.c.nosp@m.c
Date
2015.02
Copyright:
Copyright (c) 2015 ITEAD Intelligent Systems Co., Ltd.

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.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Definition in file ESP8266.cpp.


API: ESP8266.h File Reference

API
  • Related Pages
  • Classes
  • Files
  • Examples
  • File List
Classes
ESP8266.h File Reference

The definition of class ESP8266. More...

#include "Arduino.h"

Go to the source code of this file.

Classes

class ESP8266
Provide an easy-to-use way to manipulate ESP8266. More...

Detailed Description

The definition of class ESP8266.

Author
Wu Pengfeipengf.nosp@m.ei.w.nosp@m.u@ite.nosp@m.ad.c.nosp@m.c
Date
2015.02
Copyright:
Copyright (c) 2015 ITEAD Intelligent Systems Co., Ltd.

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.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Definition in file ESP8266.h.


API: Examples

API
  • Related Pages
  • Classes
  • Files
  • Examples
Examples
Here is a list of all examples:
  • ConnectWiFi.ino
  • HTTPGET.ino
  • TCPClientMultiple.ino
  • TCPClientSingle.ino
  • TCPClientSingleUNO.ino
  • TCPServer.ino
  • UDPClientMultiple.ino
  • UDPClientSingle.ino


API: ConnectWiFi.ino

API
  • Related Pages
  • Classes
  • Files
  • Examples
ConnectWiFi.ino

The ConnectWiFi demo of library WeeESP8266.

Author
Wu Pengfeipengf.nosp@m.ei.w.nosp@m.u@ite.nosp@m.ad.c.nosp@m.c
Date
2015.03
Copyright:
Copyright (c) 2015 ITEAD Intelligent Systems Co., Ltd.

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.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include "ESP8266.h"
#define SSID "ITEAD"
#define PASSWORD "12345678"
ESP8266 wifi(Serial1);
void setup(void)
{
Serial.begin(9600);
Serial.print("setup begin\r\n");
Serial.print("FW Version: ");
Serial.println(wifi.getVersion().c_str());
if (wifi.setOprToStation()) {
Serial.print("to station ok\r\n");
} else {
Serial.print("to station err\r\n");
}
if (wifi.joinAP(SSID, PASSWORD)) {
Serial.print("Join AP success\r\n");
Serial.print("IP: ");
Serial.println(wifi.getLocalIP().c_str());
} else {
Serial.print("Join AP failure\r\n");
}
Serial.print("setup end\r\n");
}
void loop(void)
{
}


API: HTTPGET.ino

API
  • Related Pages
  • Classes
  • Files
  • Examples
HTTPGET.ino

The HTTPGET demo of library WeeESP8266.

Author
Wu Pengfeipengf.nosp@m.ei.w.nosp@m.u@ite.nosp@m.ad.c.nosp@m.c
Date
2015.03
Copyright:
Copyright (c) 2015 ITEAD Intelligent Systems Co., Ltd.

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.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include "ESP8266.h"
#define SSID "ITEAD"
#define PASSWORD "12345678"
#define HOST_NAME "www.baidu.com"
#define HOST_PORT (80)
ESP8266 wifi(Serial1);
void setup(void)
{
Serial.begin(9600);
Serial.print("setup begin\r\n");
Serial.print("FW Version:");
Serial.println(wifi.getVersion().c_str());
if (wifi.setOprToStationSoftAP()) {
Serial.print("to station + softap ok\r\n");
} else {
Serial.print("to station + softap err\r\n");
}
if (wifi.joinAP(SSID, PASSWORD)) {
Serial.print("Join AP success\r\n");
Serial.print("IP:");
Serial.println( wifi.getLocalIP().c_str());
} else {
Serial.print("Join AP failure\r\n");
}
if (wifi.disableMUX()) {
Serial.print("single ok\r\n");
} else {
Serial.print("single err\r\n");
}
Serial.print("setup end\r\n");
}
void loop(void)
{
uint8_t buffer[1024] = {0};
if (wifi.createTCP(HOST_NAME, HOST_PORT)) {
Serial.print("create tcp ok\r\n");
} else {
Serial.print("create tcp err\r\n");
}
char *hello = "GET / HTTP/1.1\r\nHost: www.baidu.com\r\nConnection: close\r\n\r\n";
wifi.send((const uint8_t*)hello, strlen(hello));
uint32_t len = wifi.recv(buffer, sizeof(buffer), 10000);
if (len > 0) {
Serial.print("Received:[");
for(uint32_t i = 0; i < len; i++) {
Serial.print((char)buffer[i]);
}
Serial.print("]\r\n");
}
if (wifi.releaseTCP()) {
Serial.print("release tcp ok\r\n");
} else {
Serial.print("release tcp err\r\n");
}
while(1);
}


API: TCPClientMultiple.ino

API
  • Related Pages
  • Classes
  • Files
  • Examples
TCPClientMultiple.ino

The TCPClientMultiple demo of library WeeESP8266.

Author
Wu Pengfeipengf.nosp@m.ei.w.nosp@m.u@ite.nosp@m.ad.c.nosp@m.c
Date
2015.02
Copyright:
Copyright (c) 2015 ITEAD Intelligent Systems Co., Ltd.

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.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include "ESP8266.h"
#define SSID "ITEAD"
#define PASSWORD "12345678"
#define HOST_NAME "172.16.5.12"
#define HOST_PORT (8090)
ESP8266 wifi(Serial1);
void setup(void)
{
Serial.begin(9600);
Serial.print("setup begin\r\n");
Serial.print("FW Version: ");
Serial.println(wifi.getVersion().c_str());
if (wifi.setOprToStationSoftAP()) {
Serial.print("to station + softap ok\r\n");
} else {
Serial.print("to station + softap err\r\n");
}
if (wifi.joinAP(SSID, PASSWORD)) {
Serial.print("Join AP success\r\n");
Serial.print("IP: ");
Serial.println(wifi.getLocalIP().c_str());
} else {
Serial.print("Join AP failure\r\n");
}
if (wifi.enableMUX()) {
Serial.print("multiple ok\r\n");
} else {
Serial.print("multiple err\r\n");
}
Serial.print("setup end\r\n");
}
void loop(void)
{
uint8_t buffer[128] = {0};
static uint8_t mux_id = 0;
if (wifi.createTCP(mux_id, HOST_NAME, HOST_PORT)) {
Serial.print("create tcp ");
Serial.print(mux_id);
Serial.println(" ok");
} else {
Serial.print("create tcp ");
Serial.print(mux_id);
Serial.println(" err");
}
char *hello = "Hello, this is client!";
if (wifi.send(mux_id, (const uint8_t*)hello, strlen(hello))) {
Serial.println("send ok");
} else {
Serial.println("send err");
}
uint32_t len = wifi.recv(mux_id, buffer, sizeof(buffer), 10000);
if (len > 0) {
Serial.print("Received:[");
for(uint32_t i = 0; i < len; i++) {
Serial.print((char)buffer[i]);
}
Serial.print("]\r\n");
}
if (wifi.releaseTCP(mux_id)) {
Serial.print("release tcp ");
Serial.print(mux_id);
Serial.println(" ok");
} else {
Serial.print("release tcp ");
Serial.print(mux_id);
Serial.println(" err");
}
delay(3000);
mux_id++;
if (mux_id >= 5) {
mux_id = 0;
}
}


API: TCPClientSingle.ino

API
  • Related Pages
  • Classes
  • Files
  • Examples
TCPClientSingle.ino

The TCPClientSingle demo of library WeeESP8266.

Author
Wu Pengfeipengf.nosp@m.ei.w.nosp@m.u@ite.nosp@m.ad.c.nosp@m.c
Date
2015.02
Copyright:
Copyright (c) 2015 ITEAD Intelligent Systems Co., Ltd.

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.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include "ESP8266.h"
#define SSID "ITEAD"
#define PASSWORD "12345678"
#define HOST_NAME "172.16.5.12"
#define HOST_PORT (8090)
ESP8266 wifi(Serial1);
void setup(void)
{
Serial.begin(9600);
Serial.print("setup begin\r\n");
Serial.print("FW Version:");
Serial.println(wifi.getVersion().c_str());
if (wifi.setOprToStationSoftAP()) {
Serial.print("to station + softap ok\r\n");
} else {
Serial.print("to station + softap err\r\n");
}
if (wifi.joinAP(SSID, PASSWORD)) {
Serial.print("Join AP success\r\n");
Serial.print("IP:");
Serial.println( wifi.getLocalIP().c_str());
} else {
Serial.print("Join AP failure\r\n");
}
if (wifi.disableMUX()) {
Serial.print("single ok\r\n");
} else {
Serial.print("single err\r\n");
}
Serial.print("setup end\r\n");
}
void loop(void)
{
uint8_t buffer[128] = {0};
if (wifi.createTCP(HOST_NAME, HOST_PORT)) {
Serial.print("create tcp ok\r\n");
} else {
Serial.print("create tcp err\r\n");
}
char *hello = "Hello, this is client!";
wifi.send((const uint8_t*)hello, strlen(hello));
uint32_t len = wifi.recv(buffer, sizeof(buffer), 10000);
if (len > 0) {
Serial.print("Received:[");
for(uint32_t i = 0; i < len; i++) {
Serial.print((char)buffer[i]);
}
Serial.print("]\r\n");
}
if (wifi.releaseTCP()) {
Serial.print("release tcp ok\r\n");
} else {
Serial.print("release tcp err\r\n");
}
delay(5000);
}


API: TCPClientSingleUNO.ino

API
  • Related Pages
  • Classes
  • Files
  • Examples
TCPClientSingleUNO.ino

The TCPClientSingleUNO demo of library WeeESP8266.

Author
Wu Pengfeipengf.nosp@m.ei.w.nosp@m.u@ite.nosp@m.ad.c.nosp@m.c
Date
2015.03
Copyright:
Copyright (c) 2015 ITEAD Intelligent Systems Co., Ltd.

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.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include "ESP8266.h"
#include <SoftwareSerial.h>
#define SSID "ITEAD"
#define PASSWORD "12345678"
#define HOST_NAME "172.16.5.12"
#define HOST_PORT (8090)
SoftwareSerial mySerial(3, 2); /* RX:D3, TX:D2 */
ESP8266 wifi(mySerial);
void setup(void)
{
Serial.begin(9600);
Serial.print("setup begin\r\n");
Serial.print("FW Version:");
Serial.println(wifi.getVersion().c_str());
if (wifi.setOprToStationSoftAP()) {
Serial.print("to station + softap ok\r\n");
} else {
Serial.print("to station + softap err\r\n");
}
if (wifi.joinAP(SSID, PASSWORD)) {
Serial.print("Join AP success\r\n");
Serial.print("IP:");
Serial.println( wifi.getLocalIP().c_str());
} else {
Serial.print("Join AP failure\r\n");
}
if (wifi.disableMUX()) {
Serial.print("single ok\r\n");
} else {
Serial.print("single err\r\n");
}
Serial.print("setup end\r\n");
}
void loop(void)
{
uint8_t buffer[128] = {0};
if (wifi.createTCP(HOST_NAME, HOST_PORT)) {
Serial.print("create tcp ok\r\n");
} else {
Serial.print("create tcp err\r\n");
}
char *hello = "Hello, this is client!";
wifi.send((const uint8_t*)hello, strlen(hello));
uint32_t len = wifi.recv(buffer, sizeof(buffer), 10000);
if (len > 0) {
Serial.print("Received:[");
for(uint32_t i = 0; i < len; i++) {
Serial.print((char)buffer[i]);
}
Serial.print("]\r\n");
}
if (wifi.releaseTCP()) {
Serial.print("release tcp ok\r\n");
} else {
Serial.print("release tcp err\r\n");
}
delay(5000);
}


API: TCPServer.ino

API
  • Related Pages
  • Classes
  • Files
  • Examples
TCPServer.ino

The TCPServer demo of library WeeESP8266.

Author
Wu Pengfeipengf.nosp@m.ei.w.nosp@m.u@ite.nosp@m.ad.c.nosp@m.c
Date
2015.02
Copyright:
Copyright (c) 2015 ITEAD Intelligent Systems Co., Ltd.

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.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include "ESP8266.h"
#define SSID "ITEAD"
#define PASSWORD "12345678"
ESP8266 wifi(Serial1);
void setup(void)
{
Serial.begin(9600);
Serial.print("setup begin\r\n");
Serial.print("FW Version:");
Serial.println(wifi.getVersion().c_str());
if (wifi.setOprToStationSoftAP()) {
Serial.print("to station + softap ok\r\n");
} else {
Serial.print("to station + softap err\r\n");
}
if (wifi.joinAP(SSID, PASSWORD)) {
Serial.print("Join AP success\r\n");
Serial.print("IP: ");
Serial.println(wifi.getLocalIP().c_str());
} else {
Serial.print("Join AP failure\r\n");
}
if (wifi.enableMUX()) {
Serial.print("multiple ok\r\n");
} else {
Serial.print("multiple err\r\n");
}
if (wifi.startTCPServer(8090)) {
Serial.print("start tcp server ok\r\n");
} else {
Serial.print("start tcp server err\r\n");
}
if (wifi.setTCPServerTimeout(10)) {
Serial.print("set tcp server timout 10 seconds\r\n");
} else {
Serial.print("set tcp server timout err\r\n");
}
Serial.print("setup end\r\n");
}
void loop(void)
{
uint8_t buffer[128] = {0};
uint8_t mux_id;
uint32_t len = wifi.recv(&mux_id, buffer, sizeof(buffer), 100);
if (len > 0) {
Serial.print("Status:[");
Serial.print(wifi.getIPStatus().c_str());
Serial.println("]");
Serial.print("Received from :");
Serial.print(mux_id);
Serial.print("[");
for(uint32_t i = 0; i < len; i++) {
Serial.print((char)buffer[i]);
}
Serial.print("]\r\n");
if(wifi.send(mux_id, buffer, len)) {
Serial.print("send back ok\r\n");
} else {
Serial.print("send back err\r\n");
}
if (wifi.releaseTCP(mux_id)) {
Serial.print("release tcp ");
Serial.print(mux_id);
Serial.println(" ok");
} else {
Serial.print("release tcp");
Serial.print(mux_id);
Serial.println(" err");
}
Serial.print("Status:[");
Serial.print(wifi.getIPStatus().c_str());
Serial.println("]");
}
}


API: UDPClientMultiple.ino

API
  • Related Pages
  • Classes
  • Files
  • Examples
UDPClientMultiple.ino

The UDPClientMultiple demo of library WeeESP8266.

Author
Wu Pengfeipengf.nosp@m.ei.w.nosp@m.u@ite.nosp@m.ad.c.nosp@m.c
Date
2015.02
Copyright:
Copyright (c) 2015 ITEAD Intelligent Systems Co., Ltd.

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.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include "ESP8266.h"
#define SSID "ITEAD"
#define PASSWORD "12345678"
#define HOST_NAME "172.16.5.12"
#define HOST_PORT (5416)
ESP8266 wifi(Serial1);
void setup(void)
{
Serial.begin(9600);
Serial.print("setup begin\r\n");
Serial.print("FW Version:");
Serial.println(wifi.getVersion().c_str());
if (wifi.setOprToStationSoftAP()) {
Serial.print("to station + softap ok\r\n");
} else {
Serial.print("to station + softap err\r\n");
}
if (wifi.joinAP(SSID, PASSWORD)) {
Serial.print("Join AP success\r\n");
Serial.print("IP: ");
Serial.println(wifi.getLocalIP().c_str());
} else {
Serial.print("Join AP failure\r\n");
}
if (wifi.enableMUX()) {
Serial.print("multiple ok\r\n");
} else {
Serial.print("multiple err\r\n");
}
Serial.print("setup end\r\n");
}
void loop(void)
{
uint8_t buffer[128] = {0};
static uint8_t mux_id = 0;
if (wifi.registerUDP(mux_id, HOST_NAME, HOST_PORT)) {
Serial.print("register udp ");
Serial.print(mux_id);
Serial.println(" ok");
} else {
Serial.print("register udp ");
Serial.print(mux_id);
Serial.println(" err");
}
char *hello = "Hello, this is client!";
wifi.send(mux_id, (const uint8_t*)hello, strlen(hello));
uint32_t len = wifi.recv(mux_id, buffer, sizeof(buffer), 10000);
if (len > 0) {
Serial.print("Received:[");
for(uint32_t i = 0; i < len; i++) {
Serial.print((char)buffer[i]);
}
Serial.print("]\r\n");
}
if (wifi.unregisterUDP(mux_id)) {
Serial.print("unregister udp ");
Serial.print(mux_id);
Serial.println(" ok");
} else {
Serial.print("unregister udp ");
Serial.print(mux_id);
Serial.println(" err");
}
delay(5000);
mux_id++;
if (mux_id >= 5) {
mux_id = 0;
}
}


API: UDPClientSingle.ino

API
  • Related Pages
  • Classes
  • Files
  • Examples
UDPClientSingle.ino

The UDPClientSingle demo of library WeeESP8266.

Author
Wu Pengfeipengf.nosp@m.ei.w.nosp@m.u@ite.nosp@m.ad.c.nosp@m.c
Date
2015.02
Copyright:
Copyright (c) 2015 ITEAD Intelligent Systems Co., Ltd.

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.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include "ESP8266.h"
#define SSID "ITEAD"
#define PASSWORD "12345678"
#define HOST_NAME "172.16.5.12"
#define HOST_PORT (5416)
ESP8266 wifi(Serial1);
void setup(void)
{
Serial.begin(9600);
Serial.print("setup begin\r\n");
Serial.print("FW Version:");
Serial.println(wifi.getVersion().c_str());
if (wifi.setOprToStationSoftAP()) {
Serial.print("to station + softap ok\r\n");
} else {
Serial.print("to station + softap err\r\n");
}
if (wifi.joinAP(SSID, PASSWORD)) {
Serial.print("Join AP success\r\n");
Serial.print("IP: ");
Serial.println(wifi.getLocalIP().c_str());
} else {
Serial.print("Join AP failure\r\n");
}
if (wifi.disableMUX()) {
Serial.print("single ok\r\n");
} else {
Serial.print("single err\r\n");
}
Serial.print("setup end\r\n");
}
void loop(void)
{
uint8_t buffer[128] = {0};
if (wifi.registerUDP(HOST_NAME, HOST_PORT)) {
Serial.print("register udp ok\r\n");
} else {
Serial.print("register udp err\r\n");
}
char *hello = "Hello, this is client!";
wifi.send((const uint8_t*)hello, strlen(hello));
uint32_t len = wifi.recv(buffer, sizeof(buffer), 10000);
if (len > 0) {
Serial.print("Received:[");
for(uint32_t i = 0; i < len; i++) {
Serial.print((char)buffer[i]);
}
Serial.print("]\r\n");
}
if (wifi.unregisterUDP()) {
Serial.print("unregister udp ok\r\n");
} else {
Serial.print("unregister udp err\r\n");
}
delay(5000);
}


API: ESP8266.cpp Source File

API
  • Related Pages
  • Classes
  • Files
  • Examples
  • File List
ESP8266.cpp
Go to the documentation of this file.
1
21 #include "ESP8266.h"
22
23 #define LOG_OUTPUT_DEBUG (1)
24 #define LOG_OUTPUT_DEBUG_PREFIX (1)
25
26 #define logDebug(arg)\
27 do {\
28 if (LOG_OUTPUT_DEBUG)\
29 {\
30 if (LOG_OUTPUT_DEBUG_PREFIX)\
31 {\
32 Serial.print("[LOG Debug: ");\
33 Serial.print((const char*)__FILE__);\
34 Serial.print(",");\
35 Serial.print((unsigned int)__LINE__);\
36 Serial.print(",");\
37 Serial.print((const char*)__FUNCTION__);\
38 Serial.print("] ");\
39 }\
40 Serial.print(arg);\
41 }\
42 } while(0)
43
44 #ifdef ESP8266_USE_SOFTWARE_SERIAL
45 ESP8266::ESP8266(SoftwareSerial &uart, uint32_t baud): m_puart(&uart)
46 {
47 m_puart->begin(baud);
48 rx_empty();
49 }
50 #else
51 ESP8266::ESP8266(HardwareSerial &uart, uint32_t baud): m_puart(&uart)
52 {
53 m_puart->begin(baud);
54 rx_empty();
55 }
56 #endif
57
58 bool ESP8266::kick(void)
59 {
60 return eAT();
61 }
62
63 bool ESP8266::restart(void)
64 {
65 unsigned long start;
66 if (eATRST()) {
67 delay(2000);
68 start = millis();
69 while (millis() - start < 3000) {
70 if (eAT()) {
71 delay(1500); /* Waiting for stable */
72 return true;
73 }
74 delay(100);
75 }
76 }
77 return false;
78 }
79
80 String ESP8266::getVersion(void)
81 {
82 String version;
83 eATGMR(version);
84 return version;
85 }
86
87 bool ESP8266::setOprToStation(void)
88 {
89 uint8_t mode;
90 if (!qATCWMODE(&mode)) {
91 return false;
92 }
93 if (mode == 1) {
94 return true;
95 } else {
96 if (sATCWMODE(1) && restart()) {
97 return true;
98 } else {
99 return false;
100 }
101 }
102 }
103
104 bool ESP8266::setOprToSoftAP(void)
105 {
106 uint8_t mode;
107 if (!qATCWMODE(&mode)) {
108 return false;
109 }
110 if (mode == 2) {
111 return true;
112 } else {
113 if (sATCWMODE(2) && restart()) {
114 return true;
115 } else {
116 return false;
117 }
118 }
119 }
120
121 bool ESP8266::setOprToStationSoftAP(void)
122 {
123 uint8_t mode;
124 if (!qATCWMODE(&mode)) {
125 return false;
126 }
127 if (mode == 3) {
128 return true;
129 } else {
130 if (sATCWMODE(3) && restart()) {
131 return true;
132 } else {
133 return false;
134 }
135 }
136 }
137
138 String ESP8266::getAPList(void)
139 {
140 String list;
141 eATCWLAP(list);
142 return list;
143 }
144
145 bool ESP8266::joinAP(String ssid, String pwd)
146 {
147 return sATCWJAP(ssid, pwd);
148 }
149
150 bool ESP8266::leaveAP(void)
151 {
152 return eATCWQAP();
153 }
154
155 bool ESP8266::setSoftAPParam(String ssid, String pwd, uint8_t chl, uint8_t ecn)
156 {
157 return sATCWSAP(ssid, pwd, chl, ecn);
158 }
159
160 String ESP8266::getJoinedDeviceIP(void)
161 {
162 String list;
163 eATCWLIF(list);
164 return list;
165 }
166
167 String ESP8266::getIPStatus(void)
168 {
169 String list;
170 eATCIPSTATUS(list);
171 return list;
172 }
173
174 String ESP8266::getLocalIP(void)
175 {
176 String list;
177 eATCIFSR(list);
178 return list;
179 }
180
181 bool ESP8266::enableMUX(void)
182 {
183 return sATCIPMUX(1);
184 }
185
186 bool ESP8266::disableMUX(void)
187 {
188 return sATCIPMUX(0);
189 }
190
191 bool ESP8266::createTCP(String addr, uint32_t port)
192 {
193 return sATCIPSTARTSingle("TCP", addr, port);
194 }
195
196 bool ESP8266::releaseTCP(void)
197 {
198 return eATCIPCLOSESingle();
199 }
200
201 bool ESP8266::registerUDP(String addr, uint32_t port)
202 {
203 return sATCIPSTARTSingle("UDP", addr, port);
204 }
205
206 bool ESP8266::unregisterUDP(void)
207 {
208 return eATCIPCLOSESingle();
209 }
210
211 bool ESP8266::createTCP(uint8_t mux_id, String addr, uint32_t port)
212 {
213 return sATCIPSTARTMultiple(mux_id, "TCP", addr, port);
214 }
215
216 bool ESP8266::releaseTCP(uint8_t mux_id)
217 {
218 return sATCIPCLOSEMulitple(mux_id);
219 }
220
221 bool ESP8266::registerUDP(uint8_t mux_id, String addr, uint32_t port)
222 {
223 return sATCIPSTARTMultiple(mux_id, "UDP", addr, port);
224 }
225
226 bool ESP8266::unregisterUDP(uint8_t mux_id)
227 {
228 return sATCIPCLOSEMulitple(mux_id);
229 }
230
231 bool ESP8266::setTCPServerTimeout(uint32_t timeout)
232 {
233 return sATCIPSTO(timeout);
234 }
235
236 bool ESP8266::startTCPServer(uint32_t port)
237 {
238 if (sATCIPSERVER(1, port)) {
239 return true;
240 }
241 return false;
242 }
243
244 bool ESP8266::stopTCPServer(void)
245 {
246 sATCIPSERVER(0);
247 restart();
248 return false;
249 }
250
251 bool ESP8266::startServer(uint32_t port)
252 {
253 return startTCPServer(port);
254 }
255
256 bool ESP8266::stopServer(void)
257 {
258 return stopTCPServer();
259 }
260
261 bool ESP8266::send(const uint8_t *buffer, uint32_t len)
262 {
263 return sATCIPSENDSingle(buffer, len);
264 }
265
266 bool ESP8266::send(uint8_t mux_id, const uint8_t *buffer, uint32_t len)
267 {
268 return sATCIPSENDMultiple(mux_id, buffer, len);
269 }
270
271 uint32_t ESP8266::recv(uint8_t *buffer, uint32_t buffer_size, uint32_t timeout)
272 {
273 return recvPkg(buffer, buffer_size, NULL, timeout, NULL);
274 }
275
276 uint32_t ESP8266::recv(uint8_t mux_id, uint8_t *buffer, uint32_t buffer_size, uint32_t timeout)
277 {
278 uint8_t id;
279 uint32_t ret;
280 ret = recvPkg(buffer, buffer_size, NULL, timeout, &id);
281 if (ret > 0 && id == mux_id) {
282 return ret;
283 }
284 return 0;
285 }
286
287 uint32_t ESP8266::recv(uint8_t *coming_mux_id, uint8_t *buffer, uint32_t buffer_size, uint32_t timeout)
288 {
289 return recvPkg(buffer, buffer_size, NULL, timeout, coming_mux_id);
290 }
291
292 /*----------------------------------------------------------------------------*/
293
294 uint32_t ESP8266::recvPkg(uint8_t *buffer, uint32_t buffer_size, uint32_t *data_len, uint32_t timeout, uint8_t *coming_mux_id)
295 {
296 String data;
297 char a;
298 int32_t index_PIPDcomma = -1;
299 int32_t index_colon = -1; /* : */
300 int32_t index_comma = -1; /* , */
301 int32_t len = -1;
302 int8_t id = -1;
303 bool has_data = false;
304 //logDebug("start recv pkg");
305
306 unsigned long start = millis();
307 while (millis() - start < timeout) {
308 while(m_puart->available() > 0) {
309 a = m_puart->read();
310 data += a;
311 }
312
313 index_PIPDcomma = data.indexOf("+IPD,");
314 if (index_PIPDcomma != -1) {
315 //logDebug("index_PIPDcomma found = %d", index_PIPDcomma);
316 index_colon = data.indexOf(':', index_PIPDcomma + 5);
317 if (index_colon != -1) {
318 //logDebug("data1 = %s\r\n", data.c_str());
319 //logDebug("index_colon found = %d", index_colon);
320
321 index_comma = data.indexOf(',', index_PIPDcomma + 5);
322 //logDebug("index_comma found = %d", index_comma);
323
324 if (index_comma != -1 && index_comma < index_colon) { /* +IPD,id,len:data */
325 //logDebug("id = %d", id);
326 id = data.substring(index_PIPDcomma + 5, index_comma).toInt();
327 //logDebug("id = %d", id);
328 if (id < 0 || id > 4) {
329 return 0;
330 }
331 //logDebug("len = %d", len);
332 len = data.substring(index_comma + 1, index_colon).toInt();
333 //logDebug("len = %d", len);
334 if (len <= 0) {
335 return 0;
336 }
337 //logDebug("has id");
338 } else { /* +IPD,len:data */
339 len = data.substring(index_PIPDcomma + 5, index_colon).toInt();
340 //logDebug("len = %d", len);
341 if (len <= 0) {
342 return 0;
343 }
344 //logDebug("no id");
345 }
346 has_data = true;
347 //logDebug("has_data true");
348 break;
349 }
350 }
351 }
352 //logDebug("has_data = %u\r\n", has_data);
353 //logDebug("data2 = %s\r\n", data.c_str());
354
355 if (has_data) {
356 start = millis();
357 while (millis() - start < 3000) {
358 while(m_puart->available() > 0) {
359 a = m_puart->read();
360 data += a;
361 }
362 //logDebug("data3 = %s\r\n", data.c_str());
363 if (data.length() >= index_colon + 1 + len) {
364 if (data_len) {
365 *data_len = len;
366 }
367 if (index_comma != -1 && coming_mux_id) {
368 *coming_mux_id = id;
369 }
370 //logDebug("len = %d", len);
371 //logDebug("buffer_size = %d", buffer_size);
372 uint32_t ret = len > buffer_size ? buffer_size : len;
373
374 memcpy(buffer,
375 data.substring(index_colon + 1, index_colon + 1 + len).c_str(),
376 ret);
377 //logDebug("ret = %u\r\n", ret);
378 return ret;
379 }
380 }
381 }
382 //logDebug("end recv pkg");
383 return 0;
384 }
385
386 void ESP8266::rx_empty(void)
387 {
388 while(m_puart->available() > 0) {
389 m_puart->read();
390 }
391 }
392
393 String ESP8266::recvString(String target, uint32_t timeout)
394 {
395 String data;
396 char a;
397 unsigned long start = millis();
398 while (millis() - start < timeout) {
399 while(m_puart->available() > 0) {
400 a = m_puart->read();
401 if(a == '\0') continue;
402 data += a;
403 }
404 if (data.indexOf(target) != -1) {
405 break;
406 }
407 }
408 return data;
409 }
410
411 String ESP8266::recvString(String target1, String target2, uint32_t timeout)
412 {
413 String data;
414 char a;
415 unsigned long start = millis();
416 while (millis() - start < timeout) {
417 while(m_puart->available() > 0) {
418 a = m_puart->read();
419 if(a == '\0') continue;
420 data += a;
421 }
422 if (data.indexOf(target1) != -1) {
423 break;
424 } else if (data.indexOf(target2) != -1) {
425 break;
426 }
427 }
428 return data;
429 }
430
431 String ESP8266::recvString(String target1, String target2, String target3, uint32_t timeout)
432 {
433 String data;
434 char a;
435 unsigned long start = millis();
436 while (millis() - start < timeout) {
437 while(m_puart->available() > 0) {
438 a = m_puart->read();
439 if(a == '\0') continue;
440 data += a;
441 }
442 if (data.indexOf(target1) != -1) {
443 break;
444 } else if (data.indexOf(target2) != -1) {
445 break;
446 } else if (data.indexOf(target3) != -1) {
447 break;
448 }
449 }
450 return data;
451 }
452
453 bool ESP8266::recvFind(String target, uint32_t timeout)
454 {
455 String data_tmp;
456 data_tmp = recvString(target, timeout);
457 if (data_tmp.indexOf(target) != -1) {
458 return true;
459 }
460 return false;
461 }
462
463 bool ESP8266::recvFindAndFilter(String target, String begin, String end, String &data, uint32_t timeout)
464 {
465 String data_tmp;
466 data_tmp = recvString(target, timeout);
467 if (data_tmp.indexOf(target) != -1) {
468 int32_t index1 = data_tmp.indexOf(begin);
469 int32_t index2 = data_tmp.indexOf(end);
470 if (index1 != -1 && index2 != -1) {
471 index1 += begin.length();
472 data = data_tmp.substring(index1, index2);
473 return true;
474 }
475 }
476 data = "";
477 return false;
478 }
479
480 bool ESP8266::eAT(void)
481 {
482 rx_empty();
483 m_puart->println("AT");
484 return recvFind("OK");
485 }
486
487 bool ESP8266::eATRST(void)
488 {
489 rx_empty();
490 m_puart->println("AT+RST");
491 return recvFind("OK");
492 }
493
494 bool ESP8266::eATGMR(String &version)
495 {
496 rx_empty();
497 m_puart->println("AT+GMR");
498 return recvFindAndFilter("OK", "\r\r\n", "\r\n\r\nOK", version);
499 }
500
501 bool ESP8266::qATCWMODE(uint8_t *mode)
502 {
503 String str_mode;
504 bool ret;
505 if (!mode) {
506 return false;
507 }
508 rx_empty();
509 m_puart->println("AT+CWMODE?");
510 ret = recvFindAndFilter("OK", "+CWMODE:", "\r\n\r\nOK", str_mode);
511 if (ret) {
512 *mode = (uint8_t)str_mode.toInt();
513 return true;
514 } else {
515 return false;
516 }
517 }
518
519 bool ESP8266::sATCWMODE(uint8_t mode)
520 {
521 String data;
522 rx_empty();
523 m_puart->print("AT+CWMODE=");
524 m_puart->println(mode);
525
526 data = recvString("OK", "no change");
527 if (data.indexOf("OK") != -1 || data.indexOf("no change") != -1) {
528 return true;
529 }
530 return false;
531 }
532
533 bool ESP8266::sATCWJAP(String ssid, String pwd)
534 {
535 String data;
536 rx_empty();
537 m_puart->print("AT+CWJAP=\"");
538 m_puart->print(ssid);
539 m_puart->print("\",\"");
540 m_puart->print(pwd);
541 m_puart->println("\"");
542
543 data = recvString("OK", "FAIL", 10000);
544 if (data.indexOf("OK") != -1) {
545 return true;
546 }
547 return false;
548 }
549
550 bool ESP8266::eATCWLAP(String &list)
551 {
552 String data;
553 rx_empty();
554 m_puart->println("AT+CWLAP");
555 return recvFindAndFilter("OK", "\r\r\n", "\r\n\r\nOK", list, 10000);
556 }
557
558 bool ESP8266::eATCWQAP(void)
559 {
560 String data;
561 rx_empty();
562 m_puart->println("AT+CWQAP");
563 return recvFind("OK");
564 }
565
566 bool ESP8266::sATCWSAP(String ssid, String pwd, uint8_t chl, uint8_t ecn)
567 {
568 String data;
569 rx_empty();
570 m_puart->print("AT+CWSAP=\"");
571 m_puart->print(ssid);
572 m_puart->print("\",\"");
573 m_puart->print(pwd);
574 m_puart->print("\",");
575 m_puart->print(chl);
576 m_puart->print(",");
577 m_puart->println(ecn);
578
579 data = recvString("OK", "ERROR", 5000);
580 if (data.indexOf("OK") != -1) {
581 return true;
582 }
583 return false;
584 }
585
586 bool ESP8266::eATCWLIF(String &list)
587 {
588 String data;
589 rx_empty();
590 m_puart->println("AT+CWLIF");
591 return recvFindAndFilter("OK", "\r\r\n", "\r\n\r\nOK", list);
592 }
593 bool ESP8266::eATCIPSTATUS(String &list)
594 {
595 String data;
596 delay(100);
597 rx_empty();
598 m_puart->println("AT+CIPSTATUS");
599 return recvFindAndFilter("OK", "\r\r\n", "\r\n\r\nOK", list);
600 }
601 bool ESP8266::sATCIPSTARTSingle(String type, String addr, uint32_t port)
602 {
603 String data;
604 rx_empty();
605 m_puart->print("AT+CIPSTART=\"");
606 m_puart->print(type);
607 m_puart->print("\",\"");
608 m_puart->print(addr);
609 m_puart->print("\",");
610 m_puart->println(port);
611
612 data = recvString("OK", "ERROR", "ALREADY CONNECT", 10000);
613 if (data.indexOf("OK") != -1 || data.indexOf("ALREADY CONNECT") != -1) {
614 return true;
615 }
616 return false;
617 }
618 bool ESP8266::sATCIPSTARTMultiple(uint8_t mux_id, String type, String addr, uint32_t port)
619 {
620 String data;
621 rx_empty();
622 m_puart->print("AT+CIPSTART=");
623 m_puart->print(mux_id);
624 m_puart->print(",\"");
625 m_puart->print(type);
626 m_puart->print("\",\"");
627 m_puart->print(addr);
628 m_puart->print("\",");
629 m_puart->println(port);
630
631 data = recvString("OK", "ERROR", "ALREADY CONNECT", 10000);
632 if (data.indexOf("OK") != -1 || data.indexOf("ALREADY CONNECT") != -1) {
633 return true;
634 }
635 return false;
636 }
637 bool ESP8266::sATCIPSENDSingle(const uint8_t *buffer, uint32_t len)
638 {
639 rx_empty();
640 m_puart->print("AT+CIPSEND=");
641 m_puart->println(len);
642 if (recvFind(">", 5000)) {
643 rx_empty();
644 for (uint32_t i = 0; i < len; i++) {
645 m_puart->write(buffer[i]);
646 }
647 return recvFind("SEND OK", 10000);
648 }
649 return false;
650 }
651 bool ESP8266::sATCIPSENDMultiple(uint8_t mux_id, const uint8_t *buffer, uint32_t len)
652 {
653 rx_empty();
654 m_puart->print("AT+CIPSEND=");
655 m_puart->print(mux_id);
656 m_puart->print(",");
657 m_puart->println(len);
658 if (recvFind(">", 5000)) {
659 rx_empty();
660 for (uint32_t i = 0; i < len; i++) {
661 m_puart->write(buffer[i]);
662 }
663 return recvFind("SEND OK", 10000);
664 }
665 return false;
666 }
667 bool ESP8266::sATCIPCLOSEMulitple(uint8_t mux_id)
668 {
669 String data;
670 rx_empty();
671 m_puart->print("AT+CIPCLOSE=");
672 m_puart->println(mux_id);
673
674 data = recvString("OK", "link is not", 5000);
675 if (data.indexOf("OK") != -1 || data.indexOf("link is not") != -1) {
676 return true;
677 }
678 return false;
679 }
680 bool ESP8266::eATCIPCLOSESingle(void)
681 {
682 rx_empty();
683 m_puart->println("AT+CIPCLOSE");
684 return recvFind("OK", 5000);
685 }
686 bool ESP8266::eATCIFSR(String &list)
687 {
688 rx_empty();
689 m_puart->println("AT+CIFSR");
690 return recvFindAndFilter("OK", "\r\r\n", "\r\n\r\nOK", list);
691 }
692 bool ESP8266::sATCIPMUX(uint8_t mode)
693 {
694 String data;
695 rx_empty();
696 m_puart->print("AT+CIPMUX=");
697 m_puart->println(mode);
698
699 data = recvString("OK", "Link is builded");
700 if (data.indexOf("OK") != -1) {
701 return true;
702 }
703 return false;
704 }
705 bool ESP8266::sATCIPSERVER(uint8_t mode, uint32_t port)
706 {
707 String data;
708 if (mode) {
709 rx_empty();
710 m_puart->print("AT+CIPSERVER=1,");
711 m_puart->println(port);
712
713 data = recvString("OK", "no change");
714 if (data.indexOf("OK") != -1 || data.indexOf("no change") != -1) {
715 return true;
716 }
717 return false;
718 } else {
719 rx_empty();
720 m_puart->println("AT+CIPSERVER=0");
721 return recvFind("\r\r\n");
722 }
723 }
724 bool ESP8266::sATCIPSTO(uint32_t timeout)
725 {
726 rx_empty();
727 m_puart->print("AT+CIPSTO=");
728 m_puart->println(timeout);
729 return recvFind("OK");
730 }
731
ESP8266::send
bool send(const uint8_t *buffer, uint32_t len)
Send data based on TCP or UDP builded already in single mode.
Definition: ESP8266.cpp:261
ESP8266::getVersion
String getVersion(void)
Get the version of AT Command Set.
Definition: ESP8266.cpp:80
ESP8266::releaseTCP
bool releaseTCP(void)
Release TCP connection in single mode.
Definition: ESP8266.cpp:196
ESP8266::recv
uint32_t recv(uint8_t *buffer, uint32_t buffer_size, uint32_t timeout=1000)
Receive data from TCP or UDP builded already in single mode.
Definition: ESP8266.cpp:271
ESP8266::enableMUX
bool enableMUX(void)
Enable IP MUX(multiple connection mode).
Definition: ESP8266.cpp:181
ESP8266::getLocalIP
String getLocalIP(void)
Get the IP address of ESP8266.
Definition: ESP8266.cpp:174
ESP8266::setOprToSoftAP
bool setOprToSoftAP(void)
Set operation mode to softap.
Definition: ESP8266.cpp:104
ESP8266.h
The definition of class ESP8266.
ESP8266::setOprToStationSoftAP
bool setOprToStationSoftAP(void)
Set operation mode to station + softap.
Definition: ESP8266.cpp:121
ESP8266::createTCP
bool createTCP(String addr, uint32_t port)
Create TCP connection in single mode.
Definition: ESP8266.cpp:191
ESP8266::unregisterUDP
bool unregisterUDP(void)
Unregister UDP port number in single mode.
Definition: ESP8266.cpp:206
ESP8266::startServer
bool startServer(uint32_t port=333)
Start Server(Only in multiple mode).
Definition: ESP8266.cpp:251
ESP8266::stopTCPServer
bool stopTCPServer(void)
Stop TCP Server(Only in multiple mode).
Definition: ESP8266.cpp:244
ESP8266::stopServer
bool stopServer(void)
Stop Server(Only in multiple mode).
Definition: ESP8266.cpp:256
ESP8266::disableMUX
bool disableMUX(void)
Disable IP MUX(single connection mode).
Definition: ESP8266.cpp:186
ESP8266::restart
bool restart(void)
Restart ESP8266 by "AT+RST".
Definition: ESP8266.cpp:63
ESP8266::kick
bool kick(void)
Verify ESP8266 whether live or not.
Definition: ESP8266.cpp:58
ESP8266::joinAP
bool joinAP(String ssid, String pwd)
Join in AP.
Definition: ESP8266.cpp:145
ESP8266::registerUDP
bool registerUDP(String addr, uint32_t port)
Register UDP port number in single mode.
Definition: ESP8266.cpp:201
ESP8266::leaveAP
bool leaveAP(void)
Leave AP joined before.
Definition: ESP8266.cpp:150
ESP8266::setTCPServerTimeout
bool setTCPServerTimeout(uint32_t timeout=180)
Set the timeout of TCP Server.
Definition: ESP8266.cpp:231
ESP8266::startTCPServer
bool startTCPServer(uint32_t port=333)
Start TCP Server(Only in multiple mode).
Definition: ESP8266.cpp:236
ESP8266::setSoftAPParam
bool setSoftAPParam(String ssid, String pwd, uint8_t chl=7, uint8_t ecn=4)
Set SoftAP parameters.
Definition: ESP8266.cpp:155
ESP8266::setOprToStation
bool setOprToStation(void)
Set operation mode to staion.
Definition: ESP8266.cpp:87
ESP8266::getAPList
String getAPList(void)
Search available AP list and return it.
Definition: ESP8266.cpp:138
ESP8266::getIPStatus
String getIPStatus(void)
Get the current status of connection(UDP and TCP).
Definition: ESP8266.cpp:167
ESP8266::getJoinedDeviceIP
String getJoinedDeviceIP(void)
Get the IP list of devices connected to SoftAP.
Definition: ESP8266.cpp:160


API: ESP8266.h Source File

API
  • Related Pages
  • Classes
  • Files
  • Examples
  • File List
ESP8266.h
Go to the documentation of this file.
1
21 #ifndef __ESP8266_H__
22 #define __ESP8266_H__
23
24 #include "Arduino.h"
25
26
27 //#define ESP8266_USE_SOFTWARE_SERIAL
28
29
30 #ifdef ESP8266_USE_SOFTWARE_SERIAL
31 #include "SoftwareSerial.h"
32 #endif
33
34
38 class ESP8266 {
39 public:
40
41 #ifdef ESP8266_USE_SOFTWARE_SERIAL
42 /*
43 * Constuctor.
44 *
45 * @param uart - an reference of SoftwareSerial object.
46 * @param baud - the buad rate to communicate with ESP8266(default:9600).
47 *
48 * @warning parameter baud depends on the AT firmware. 9600 is an common value.
49 */
50 ESP8266(SoftwareSerial &uart, uint32_t baud = 9600);
51 #else /* HardwareSerial */
52 /*
53 * Constuctor.
54 *
55 * @param uart - an reference of HardwareSerial object.
56 * @param baud - the buad rate to communicate with ESP8266(default:9600).
57 *
58 * @warning parameter baud depends on the AT firmware. 9600 is an common value.
59 */
60 ESP8266(HardwareSerial &uart, uint32_t baud = 9600);
61 #endif
62
63
72 bool kick(void);
73
82 bool restart(void);
83
89 String getVersion(void);
90
97 bool setOprToStation(void);
98
105 bool setOprToSoftAP(void);
106
113 bool setOprToStationSoftAP(void);
114
122 String getAPList(void);
123
133 bool joinAP(String ssid, String pwd);
134
141 bool leaveAP(void);
142
153 bool setSoftAPParam(String ssid, String pwd, uint8_t chl = 7, uint8_t ecn = 4);
154
161 String getJoinedDeviceIP(void);
162
168 String getIPStatus(void);
169
175 String getLocalIP(void);
176
186 bool enableMUX(void);
187
196 bool disableMUX(void);
197
198
207 bool createTCP(String addr, uint32_t port);
208
215 bool releaseTCP(void);
216
225 bool registerUDP(String addr, uint32_t port);
226
233 bool unregisterUDP(void);
234
244 bool createTCP(uint8_t mux_id, String addr, uint32_t port);
245
253 bool releaseTCP(uint8_t mux_id);
254
264 bool registerUDP(uint8_t mux_id, String addr, uint32_t port);
265
273 bool unregisterUDP(uint8_t mux_id);
274
275
283 bool setTCPServerTimeout(uint32_t timeout = 180);
284
300 bool startTCPServer(uint32_t port = 333);
301
308 bool stopTCPServer(void);
309
320 bool startServer(uint32_t port = 333);
321
328 bool stopServer(void);
329
338 bool send(const uint8_t *buffer, uint32_t len);
339
349 bool send(uint8_t mux_id, const uint8_t *buffer, uint32_t len);
350
359 uint32_t recv(uint8_t *buffer, uint32_t buffer_size, uint32_t timeout = 1000);
360
370 uint32_t recv(uint8_t mux_id, uint8_t *buffer, uint32_t buffer_size, uint32_t timeout = 1000);
371
384 uint32_t recv(uint8_t *coming_mux_id, uint8_t *buffer, uint32_t buffer_size, uint32_t timeout = 1000);
385
386 private:
387
388 /*
389 * Empty the buffer or UART RX.
390 */
391 void rx_empty(void);
392
393 /*
394 * Recvive data from uart. Return all received data if target found or timeout.
395 */
396 String recvString(String target, uint32_t timeout = 1000);
397
398 /*
399 * Recvive data from uart. Return all received data if one of target1 and target2 found or timeout.
400 */
401 String recvString(String target1, String target2, uint32_t timeout = 1000);
402
403 /*
404 * Recvive data from uart. Return all received data if one of target1, target2 and target3 found or timeout.
405 */
406 String recvString(String target1, String target2, String target3, uint32_t timeout = 1000);
407
408 /*
409 * Recvive data from uart and search first target. Return true if target found, false for timeout.
410 */
411 bool recvFind(String target, uint32_t timeout = 1000);
412
413 /*
414 * Recvive data from uart and search first target and cut out the substring between begin and end(excluding begin and end self).
415 * Return true if target found, false for timeout.
416 */
417 bool recvFindAndFilter(String target, String begin, String end, String &data, uint32_t timeout = 1000);
418
419 /*
420 * Receive a package from uart.
421 *
422 * @param buffer - the buffer storing data.
423 * @param buffer_size - guess what!
424 * @param data_len - the length of data actually received(maybe more than buffer_size, the remained data will be abandoned).
425 * @param timeout - the duration waitting data comming.
426 * @param coming_mux_id - in single connection mode, should be NULL and not NULL in multiple.
427 */
428 uint32_t recvPkg(uint8_t *buffer, uint32_t buffer_size, uint32_t *data_len, uint32_t timeout, uint8_t *coming_mux_id);
429
430
431 bool eAT(void);
432 bool eATRST(void);
433 bool eATGMR(String &version);
434
435 bool qATCWMODE(uint8_t *mode);
436 bool sATCWMODE(uint8_t mode);
437 bool sATCWJAP(String ssid, String pwd);
438 bool eATCWLAP(String &list);
439 bool eATCWQAP(void);
440 bool sATCWSAP(String ssid, String pwd, uint8_t chl, uint8_t ecn);
441 bool eATCWLIF(String &list);
442
443 bool eATCIPSTATUS(String &list);
444 bool sATCIPSTARTSingle(String type, String addr, uint32_t port);
445 bool sATCIPSTARTMultiple(uint8_t mux_id, String type, String addr, uint32_t port);
446 bool sATCIPSENDSingle(const uint8_t *buffer, uint32_t len);
447 bool sATCIPSENDMultiple(uint8_t mux_id, const uint8_t *buffer, uint32_t len);
448 bool sATCIPCLOSEMulitple(uint8_t mux_id);
449 bool eATCIPCLOSESingle(void);
450 bool eATCIFSR(String &list);
451 bool sATCIPMUX(uint8_t mode);
452 bool sATCIPSERVER(uint8_t mode, uint32_t port = 333);
453 bool sATCIPSTO(uint32_t timeout);
454
455 /*
456 * +IPD,len:data
457 * +IPD,id,len:data
458 */
459
460 #ifdef ESP8266_USE_SOFTWARE_SERIAL
461 SoftwareSerial *m_puart; /* The UART to communicate with ESP8266 */
462 #else
463 HardwareSerial *m_puart; /* The UART to communicate with ESP8266 */
464 #endif
465 };
466
467 #endif /* #ifndef __ESP8266_H__ */
468
ESP8266::send
bool send(const uint8_t *buffer, uint32_t len)
Send data based on TCP or UDP builded already in single mode.
Definition: ESP8266.cpp:261
ESP8266::getVersion
String getVersion(void)
Get the version of AT Command Set.
Definition: ESP8266.cpp:80
ESP8266::releaseTCP
bool releaseTCP(void)
Release TCP connection in single mode.
Definition: ESP8266.cpp:196
ESP8266::recv
uint32_t recv(uint8_t *buffer, uint32_t buffer_size, uint32_t timeout=1000)
Receive data from TCP or UDP builded already in single mode.
Definition: ESP8266.cpp:271
ESP8266::enableMUX
bool enableMUX(void)
Enable IP MUX(multiple connection mode).
Definition: ESP8266.cpp:181
ESP8266::getLocalIP
String getLocalIP(void)
Get the IP address of ESP8266.
Definition: ESP8266.cpp:174
ESP8266::setOprToSoftAP
bool setOprToSoftAP(void)
Set operation mode to softap.
Definition: ESP8266.cpp:104
ESP8266::setOprToStationSoftAP
bool setOprToStationSoftAP(void)
Set operation mode to station + softap.
Definition: ESP8266.cpp:121
ESP8266::createTCP
bool createTCP(String addr, uint32_t port)
Create TCP connection in single mode.
Definition: ESP8266.cpp:191
ESP8266::unregisterUDP
bool unregisterUDP(void)
Unregister UDP port number in single mode.
Definition: ESP8266.cpp:206
ESP8266::startServer
bool startServer(uint32_t port=333)
Start Server(Only in multiple mode).
Definition: ESP8266.cpp:251
ESP8266::stopTCPServer
bool stopTCPServer(void)
Stop TCP Server(Only in multiple mode).
Definition: ESP8266.cpp:244
ESP8266::stopServer
bool stopServer(void)
Stop Server(Only in multiple mode).
Definition: ESP8266.cpp:256
ESP8266::disableMUX
bool disableMUX(void)
Disable IP MUX(single connection mode).
Definition: ESP8266.cpp:186
ESP8266::restart
bool restart(void)
Restart ESP8266 by "AT+RST".
Definition: ESP8266.cpp:63
ESP8266::kick
bool kick(void)
Verify ESP8266 whether live or not.
Definition: ESP8266.cpp:58
ESP8266::joinAP
bool joinAP(String ssid, String pwd)
Join in AP.
Definition: ESP8266.cpp:145
ESP8266::registerUDP
bool registerUDP(String addr, uint32_t port)
Register UDP port number in single mode.
Definition: ESP8266.cpp:201
ESP8266::leaveAP
bool leaveAP(void)
Leave AP joined before.
Definition: ESP8266.cpp:150
ESP8266::setTCPServerTimeout
bool setTCPServerTimeout(uint32_t timeout=180)
Set the timeout of TCP Server.
Definition: ESP8266.cpp:231
ESP8266
Provide an easy-to-use way to manipulate ESP8266.
Definition: ESP8266.h:38
ESP8266::startTCPServer
bool startTCPServer(uint32_t port=333)
Start TCP Server(Only in multiple mode).
Definition: ESP8266.cpp:236
ESP8266::setSoftAPParam
bool setSoftAPParam(String ssid, String pwd, uint8_t chl=7, uint8_t ecn=4)
Set SoftAP parameters.
Definition: ESP8266.cpp:155
ESP8266::setOprToStation
bool setOprToStation(void)
Set operation mode to staion.
Definition: ESP8266.cpp:87
ESP8266::getAPList
String getAPList(void)
Search available AP list and return it.
Definition: ESP8266.cpp:138
ESP8266::getIPStatus
String getIPStatus(void)
Get the current status of connection(UDP and TCP).
Definition: ESP8266.cpp:167
ESP8266::getJoinedDeviceIP
String getJoinedDeviceIP(void)
Get the IP list of devices connected to SoftAP.
Definition: ESP8266.cpp:160


API: README.md Source File

API
  • Related Pages
  • Classes
  • Files
  • Examples
  • File List
README.md
1 @mainpage
2
3 # WeeESP8266
4
5 An ESP8266 library for Arduino providing an easy-to-use way to manipulate ESP8266.
6
7 # Source
8
9 Source can be download at <https://github.com/itead/ITEADLIB_Arduino_WeeESP8266>.
10
11 You can clone it by:
12
13 git clone https://github.com/itead/ITEADLIB_Arduino_WeeESP8266.git
14
15 # Documentation
16
17 Online API documentation can be reached at <http://docs.iteadstudio.com/ITEADLIB_Arduino_WeeESP8266/index.html>.
18
19 Offline API documentation can be found under directory
20 [doc](https://github.com/itead/ITEADLIB_Arduino_WeeESP8266/tree/master/doc).
21
22 # How to get started
23
24 On the home page of API documentation, the tabs of Examples, Classes and Modules
25 will be useful for Arduino lovers.
26
27 # API List
28
29 bool kick (void) : Verify ESP8266 whether live or not.
30
31 bool restart (void) : Restart ESP8266 by "AT+RST".
32
33 String getVersion (void) : Get the version of AT Command Set.
34
35 bool setOprToStation (void) : Set operation mode to staion.
36
37 bool setOprToSoftAP (void) : Set operation mode to softap.
38
39 bool setOprToStationSoftAP (void) : Set operation mode to station + softap.
40
41 String getAPList (void) : Search available AP list and return it.
42
43 bool joinAP (String ssid, String pwd) : Join in AP.
44
45 bool leaveAP (void) : Leave AP joined before.
46
47 bool setSoftAPParam (String ssid, String pwd, uint8_t chl=7, uint8_t ecn=4) : Set SoftAP parameters.
48
49 String getJoinedDeviceIP (void) : Get the IP list of devices connected to SoftAP.
50
51 String getIPStatus (void) : Get the current status of connection(UDP and TCP).
52
53 String getLocalIP (void) : Get the IP address of ESP8266.
54
55 bool enableMUX (void) : Enable IP MUX(multiple connection mode).
56
57 bool disableMUX (void) : Disable IP MUX(single connection mode).
58
59 bool createTCP (String addr, uint32_t port) : Create TCP connection in single mode.
60
61 bool releaseTCP (void) : Release TCP connection in single mode.
62
63 bool registerUDP (String addr, uint32_t port) : Register UDP port number in single mode.
64
65 bool unregisterUDP (void) : Unregister UDP port number in single mode.
66
67 bool createTCP (uint8_t mux_id, String addr, uint32_t port) : Create TCP connection in multiple mode.
68
69 bool releaseTCP (uint8_t mux_id) : Release TCP connection in multiple mode.
70
71 bool registerUDP (uint8_t mux_id, String addr, uint32_t port) : Register UDP port number in multiple mode.
72
73 bool unregisterUDP (uint8_t mux_id) : Unregister UDP port number in multiple mode.
74
75 bool setTCPServerTimeout (uint32_t timeout=180) : Set the timeout of TCP Server.
76
77 bool startServer (uint32_t port=333) ： Start Server(Only in multiple mode).
78
79 bool stopServer (void) : Stop Server(Only in multiple mode).
80
81 bool startTCPServer (uint32_t port=333) : Start TCP Server(Only in multiple mode).
82
83 bool stopTCPServer (void) : Stop TCP Server(Only in multiple mode).
84
85 bool send (const uint8_t *buffer, uint32_t len) : Send data based on TCP or UDP builded already in single mode.
86
87 bool send (uint8_t mux_id, const uint8_t *buffer, uint32_t len) : Send data based on one of TCP or UDP builded already in multiple mode.
88
89 uint32_t recv (uint8_t *buffer, uint32_t buffer_size, uint32_t timeout=1000) : Receive data from TCP or UDP builded already in single mode.
90
91 uint32_t recv (uint8_t mux_id, uint8_t *buffer, uint32_t buffer_size, uint32_t timeout=1000) : Receive data from one of TCP or UDP builded already in multiple mode.
92
93 uint32_t recv (uint8_t *coming_mux_id, uint8_t *buffer, uint32_t buffer_size, uint32_t timeout=1000) : Receive data from all of TCP or UDP builded already in multiple mode.
94
95
96 # Mainboard Requires
97
98 - RAM: not less than 2KBytes
99 - Serial: one serial (HardwareSerial or SoftwareSerial) at least
100
101 # Suppported Mainboards
102
103 - Arduino UNO and its derivatives
104 - Arduino MEGA and its derivatives
105 - [Iteaduino UNO](http://imall.iteadstudio.com/im130312001.html)
106 - [WBoard Pro](http://imall.iteadstudio.com/im141125005.html)
107
108 # Using SoftwareSerial
109
110 If you want to use SoftwareSerial to communicate with ESP8266, you need to modify
111 the line in file `ESP8266.h`:
112
113 //#define ESP8266_USE_SOFTWARE_SERIAL
114
115 After modification, it should be:
116
117 #define ESP8266_USE_SOFTWARE_SERIAL
118
119
120 # Hardware Connection
121
122 WeeESP8266 library only needs an uart for hardware connection. All communications
123 are done via uart. In each example, you must specify the uart used by mainboard
124 to communicate with ESP8266 flashed AT firmware.
125
126 ## MEGA and WBoard Pro
127
128 For MEGA and WBoard Pro, `Serial1` will be used if you create an object (named wifi)
129 of class ESP8266 in your code like this:
130
131 #include "ESP8266.h"
132 ESP8266 wifi(Serial1);
133
134 The connection should be like these:
135
136 ESP8266_TX->RX1(D19)
137 ESP8266_RX->TX1(D18)
138 ESP8266_CH_PD->3.3V
139 ESP8266_VCC->3.3V
140 ESP8266_GND->GND
141
142 ## UNO
143
144 To use SoftwareSerial, `mySerial` will be used if you create an object (named wifi)
145 of class ESP8266 in your code like this:
146
147 #include "ESP8266.h"
148 #include <SoftwareSerial.h>
149
150 SoftwareSerial mySerial(3, 2); /* RX:D3, TX:D2 */
151 ESP8266 wifi(mySerial);
152
153 The connection should be like these:
154
155 ESP8266_TX->RX(D3)
156 ESP8266_RX->TX(D2)
157 ESP8266_CH_PD->3.3V
158 ESP8266_VCC->3.3V
159 ESP8266_GND->GND
160
161 # Attention
162
163 The size of data from ESP8266 is too big for arduino sometimes, so the library can't
164 receive the whole buffer because the size of the hardware serial buffer which is
165 defined in HardwareSerial.h is too small.
166
167 Open the file from `\arduino\hardware\arduino\avr\cores\arduino\HardwareSerial.h`.
168 See the follow line in the HardwareSerial.h file.
169
170 #define SERIAL_BUFFER_SIZE 64
171
172 The default size of the buffer is 64. Change it into a bigger number, like 256 or more.
173
174
175 -------------------------------------------------------------------------------
176
177 # The End!
178
179 -------------------------------------------------------------------------------
ESP8266
Provide an easy-to-use way to manipulate ESP8266.
Definition: ESP8266.h:38


API: Member List

API
  • Related Pages
  • Classes
  • Files
  • Examples
  • Class List
  • Class Index
  • Class Members
ESP8266 Member List

This is the complete list of members for ESP8266, including all inherited members.

createTCP(String addr, uint32_t port) | ESP8266
createTCP(uint8_t mux_id, String addr, uint32_t port) | ESP8266
disableMUX(void) | ESP8266
enableMUX(void) | ESP8266
getAPList(void) | ESP8266
getIPStatus(void) | ESP8266
getJoinedDeviceIP(void) | ESP8266
getLocalIP(void) | ESP8266
getVersion(void) | ESP8266
joinAP(String ssid, String pwd) | ESP8266
kick(void) | ESP8266
leaveAP(void) | ESP8266
recv(uint8_t *buffer, uint32_t buffer_size, uint32_t timeout=1000) | ESP8266
recv(uint8_t mux_id, uint8_t *buffer, uint32_t buffer_size, uint32_t timeout=1000) | ESP8266
recv(uint8_t *coming_mux_id, uint8_t *buffer, uint32_t buffer_size, uint32_t timeout=1000) | ESP8266
registerUDP(String addr, uint32_t port) | ESP8266
registerUDP(uint8_t mux_id, String addr, uint32_t port) | ESP8266
releaseTCP(void) | ESP8266
releaseTCP(uint8_t mux_id) | ESP8266
restart(void) | ESP8266
send(const uint8_t *buffer, uint32_t len) | ESP8266
send(uint8_t mux_id, const uint8_t *buffer, uint32_t len) | ESP8266
setOprToSoftAP(void) | ESP8266
setOprToStation(void) | ESP8266
setOprToStationSoftAP(void) | ESP8266
setSoftAPParam(String ssid, String pwd, uint8_t chl=7, uint8_t ecn=4) | ESP8266
setTCPServerTimeout(uint32_t timeout=180) | ESP8266
startServer(uint32_t port=333) | ESP8266
startTCPServer(uint32_t port=333) | ESP8266
stopServer(void) | ESP8266
stopTCPServer(void) | ESP8266
unregisterUDP(void) | ESP8266
unregisterUDP(uint8_t mux_id) | ESP8266


API: doxygen.h Source File

API
  • Related Pages
  • Classes
  • Files
  • Examples
  • File List
doxygen.h
Go to the documentation of this file.
1
16 #ifndef __IOTGO_DOXYGEN_H__
17 #define __IOTGO_DOXYGEN_H__
18
19
20
21 #endif /* #ifndef __IOTGO_DOXYGEN_H__ */


API: Main Page

API
  • Related Pages
  • Classes
  • Files
  • Examples
API Documentation

WeeESP8266

An ESP8266 library for Arduino providing an easy-to-use way to manipulate ESP8266.

Source

Source can be download at https://github.com/itead/ITEADLIB_Arduino_WeeESP8266.

You can clone it by:

git clone https://github.com/itead/ITEADLIB_Arduino_WeeESP8266.git

Documentation

Online API documentation can be reached at http://docs.iteadstudio.com/ITEADLIB_Arduino_WeeESP8266/index.html.

Offline API documentation can be found under directory doc.

How to get started

On the home page of API documentation, the tabs of Examples, Classes and Modules will be useful for Arduino lovers.

API List

bool    kick (void) : Verify ESP8266 whether live or not.

bool    restart (void) : Restart ESP8266 by "AT+RST".

String  getVersion (void) : Get the version of AT Command Set.

bool    setOprToStation (void) : Set operation mode to staion.

bool    setOprToSoftAP (void) : Set operation mode to softap.

bool    setOprToStationSoftAP (void) : Set operation mode to station + softap.

String  getAPList (void) : Search available AP list and return it.

bool    joinAP (String ssid, String pwd) : Join in AP.

bool    leaveAP (void) : Leave AP joined before.

bool    setSoftAPParam (String ssid, String pwd, uint8_t chl=7, uint8_t ecn=4) : Set SoftAP parameters.

String  getJoinedDeviceIP (void) : Get the IP list of devices connected to SoftAP.

String  getIPStatus (void) : Get the current status of connection(UDP and TCP).

String  getLocalIP (void) : Get the IP address of ESP8266.

bool    enableMUX (void) : Enable IP MUX(multiple connection mode).

bool    disableMUX (void) : Disable IP MUX(single connection mode).

bool    createTCP (String addr, uint32_t port) : Create TCP connection in single mode.

bool    releaseTCP (void) : Release TCP connection in single mode.

bool    registerUDP (String addr, uint32_t port) : Register UDP port number in single mode.

bool    unregisterUDP (void) : Unregister UDP port number in single mode.

bool    createTCP (uint8_t mux_id, String addr, uint32_t port) : Create TCP connection in multiple mode.

bool    releaseTCP (uint8_t mux_id) : Release TCP connection in multiple mode.

bool    registerUDP (uint8_t mux_id, String addr, uint32_t port) : Register UDP port number in multiple mode.

bool    unregisterUDP (uint8_t mux_id) : Unregister UDP port number in multiple mode.

bool    setTCPServerTimeout (uint32_t timeout=180) : Set the timeout of TCP Server.

bool    startServer (uint32_t port=333) ： Start Server(Only in multiple mode).

bool    stopServer (void) : Stop Server(Only in multiple mode).

bool    startTCPServer (uint32_t port=333) : Start TCP Server(Only in multiple mode).

bool    stopTCPServer (void) : Stop TCP Server(Only in multiple mode).

bool    send (const uint8_t *buffer, uint32_t len) : Send data based on TCP or UDP builded already in single mode.

bool    send (uint8_t mux_id, const uint8_t *buffer, uint32_t len) : Send data based on one of TCP or UDP builded already in multiple mode.

uint32_t    recv (uint8_t *buffer, uint32_t buffer_size, uint32_t timeout=1000) : Receive data from TCP or UDP builded already in single mode.

uint32_t    recv (uint8_t mux_id, uint8_t *buffer, uint32_t buffer_size, uint32_t timeout=1000) : Receive data from one of TCP or UDP builded already in multiple mode.

uint32_t    recv (uint8_t *coming_mux_id, uint8_t *buffer, uint32_t buffer_size, uint32_t timeout=1000) : Receive data from all of TCP or UDP builded already in multiple mode.

Mainboard Requires

  • RAM: not less than 2KBytes
  • Serial: one serial (HardwareSerial or SoftwareSerial) at least

Suppported Mainboards

  • Arduino UNO and its derivatives
  • Arduino MEGA and its derivatives
  • Iteaduino UNO
  • WBoard Pro

Using SoftwareSerial

If you want to use SoftwareSerial to communicate with ESP8266, you need to modify the line in file ESP8266.h:

//#define ESP8266_USE_SOFTWARE_SERIAL

After modification, it should be:

#define ESP8266_USE_SOFTWARE_SERIAL

Hardware Connection

WeeESP8266 library only needs an uart for hardware connection. All communications are done via uart. In each example, you must specify the uart used by mainboard to communicate with ESP8266 flashed AT firmware.

MEGA and WBoard Pro

For MEGA and WBoard Pro, Serial1 will be used if you create an object (named wifi) of class ESP8266 in your code like this:

#include "ESP8266.h"
ESP8266 wifi(Serial1);

The connection should be like these:

ESP8266_TX->RX1(D19)
ESP8266_RX->TX1(D18)
ESP8266_CH_PD->3.3V
ESP8266_VCC->3.3V
ESP8266_GND->GND

UNO

To use SoftwareSerial, mySerial will be used if you create an object (named wifi) of class ESP8266 in your code like this:

#include "ESP8266.h"
#include <SoftwareSerial.h>

SoftwareSerial mySerial(3, 2); /* RX:D3, TX:D2 */
ESP8266 wifi(mySerial);

The connection should be like these:

ESP8266_TX->RX(D3)
ESP8266_RX->TX(D2)
ESP8266_CH_PD->3.3V
ESP8266_VCC->3.3V
ESP8266_GND->GND

Attention

The size of data from ESP8266 is too big for arduino sometimes, so the library can't receive the whole buffer because the size of the hardware serial buffer which is defined in HardwareSerial.h is too small.

Open the file from \arduino\hardware\arduino\avr\cores\arduino\HardwareSerial.h. See the follow line in the HardwareSerial.h file.

#define SERIAL_BUFFER_SIZE 64

The default size of the buffer is 64. Change it into a bigger number, like 256 or more.

The End!

Generated on Tue Mar 17 2015 10:34:17 for API by doxygen 1.8.7


API: Related Pages

API
  • Related Pages
  • Classes
  • Files
  • Examples
Related Pages
Here is a list of all related documentation pages:
README