| API For Arduino developers

- Main Page
- Related Pages
- Classes
- Files
- Examples

- File List
- File Members

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:386
ESP8266::joinAP
bool joinAP(String ssid, String pwd, uint8_t pattern=3)
Join in AP.
Definition: ESP8266.cpp:178
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:396
ESP8266::getLocalIP
String getLocalIP(void)
Get the IP address of ESP8266.
Definition: ESP8266.cpp:281
ESP8266.h
The definition of class ESP8266.
ESP8266::unregisterUDP
bool unregisterUDP(void)
Unregister UDP port number in single mode.
Definition: ESP8266.cpp:313
ESP8266::disableMUX
bool disableMUX(void)
Disable IP MUX(single connection mode).
Definition: ESP8266.cpp:293
ESP8266::registerUDP
bool registerUDP(String addr, uint32_t port)
Register UDP port number in single mode.
Definition: ESP8266.cpp:308
ESP8266::setOprToStationSoftAP
bool setOprToStationSoftAP(uint8_t pattern1=3, uint8_t pattern2=3)
Set operation mode to station + softap.
Definition: ESP8266.cpp:146
ESP8266
Provide an easy-to-use way to manipulate ESP8266.
Definition: ESP8266.h:42