22 #include <SoftwareSerial.h>
25 #define PASSWORD "12345678"
26 #define HOST_NAME "172.16.5.12"
27 #define HOST_PORT (8090)
29 SoftwareSerial mySerial(3, 2);
35 Serial.print(
"setup begin\r\n");
37 Serial.print(
"FW Version:");
41 Serial.print(
"to station + softap ok\r\n");
43 Serial.print(
"to station + softap err\r\n");
46 if (wifi.
joinAP(SSID, PASSWORD)) {
47 Serial.print(
"Join AP success\r\n");
51 Serial.print(
"Join AP failure\r\n");
55 Serial.print(
"single ok\r\n");
57 Serial.print(
"single err\r\n");
60 Serial.print(
"setup end\r\n");
65 uint8_t buffer[128] = {0};
67 if (wifi.
createTCP(HOST_NAME, HOST_PORT)) {
68 Serial.print(
"create tcp ok\r\n");
70 Serial.print(
"create tcp err\r\n");
73 char *hello =
"Hello, this is client!";
74 wifi.
send((
const uint8_t*)hello, strlen(hello));
76 uint32_t len = wifi.
recv(buffer,
sizeof(buffer), 10000);
78 Serial.print(
"Received:[");
79 for(uint32_t i = 0; i < len; i++) {
80 Serial.print((
char)buffer[i]);
82 Serial.print(
"]\r\n");
86 Serial.print(
"release tcp ok\r\n");
88 Serial.print(
"release tcp err\r\n");
bool send(const uint8_t *buffer, uint32_t len)
Send data based on TCP or UDP builded already in single mode.
bool joinAP(String ssid, String pwd, uint8_t pattern=3)
Join in AP.
String getVersion(void)
Get the version of AT Command Set.
bool releaseTCP(void)
Release TCP connection in single 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.
String getLocalIP(void)
Get the IP address of ESP8266.
The definition of class ESP8266.
bool createTCP(String addr, uint32_t port)
Create TCP connection in single mode.
bool disableMUX(void)
Disable IP MUX(single connection mode).
bool setOprToStationSoftAP(uint8_t pattern1=3, uint8_t pattern2=3)
Set operation mode to station + softap.
Provide an easy-to-use way to manipulate ESP8266.