### AsyncUdpNTPClient Example Source: https://github.com/khoih-prog/asyncudp_esp32_ethernet/blob/main/README.md This example demonstrates how to use the AsyncUDP library to fetch time from an NTP server. It shows the setup for an NTP client, sending a request, and processing the received time data. This is useful for synchronizing device clocks. ```cpp #include #include #include // Define NTP Time Server const char* ntpServerName = "pool.ntp.org"; const int timeZone = 1; // Central European Time AsyncUDP udp; NTPClient timeClient(udp, ntpServerName, NTP_OFFSET, NTP_INTERVAL); void setup() { Serial.begin(115200); Serial.println("Starting AsyncUdpNTPClient example..."); WiFi.begin(ssid, password); while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); } Serial.println(""); Serial.println("WiFi connected"); Serial.println("IP address: "); Serial.println(WiFi.localIP()); timeClient.begin(); } void loop() { timeClient.update(); Serial.print("Current Time: "); Serial.println(timeClient.getFormattedTime()); delay(1000); } ``` -------------------------------- ### AsyncUDPServer Example Source: https://github.com/khoih-prog/asyncudp_esp32_ethernet/blob/main/README.md This example sets up a basic UDP server that listens on a specified port. It handles incoming UDP packets, prints their content, and can optionally send a response back to the sender. This is a foundational example for creating network services. ```cpp #include #include AsyncUDP udp; void setup() { Serial.begin(115200); Serial.println("Starting AsyncUDPServer example..."); WiFi.begin(ssid, password); while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); } Serial.println(""); Serial.println("WiFi connected"); Serial.println("IP address: "); Serial.println(WiFi.localIP()); // Start UDP server on port 8888 if (udp.listen(8888)) { Serial.print("UDP listening on IP: "); Serial.println(WiFi.localIP()); udp.onPacket(handlePacket); } } void loop() { // The library handles UDP events asynchronously } void handlePacket(AsyncUDPPacket packet) { Serial.print("UDP Packet received from "); Serial.print(packet.remoteIP()); Serial.print(":"); Serial.print(packet.remotePort()); Serial.print(" Data: "); Serial.write(packet.data(), packet.length()); Serial.println(); // Send a reply udp.send("Hello Client", packet.remoteIP(), packet.remotePort()); } ``` -------------------------------- ### AsyncUDPSendReceive Example Source: https://github.com/khoih-prog/asyncudp_esp32_ethernet/blob/main/README.md This example showcases sending and receiving UDP packets asynchronously. It sets up a basic UDP client that can send messages to a specified IP address and port, and also listen for incoming packets. This is fundamental for network communication. ```cpp #include #include AsyncUDP udp; void setup() { Serial.begin(115200); Serial.println("Starting AsyncUDPSendReceive example..."); WiFi.begin(ssid, password); while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); } Serial.println(""); Serial.println("WiFi connected"); Serial.println("IP address: "); Serial.println(WiFi.localIP()); // Start UDP server on port 8888 if (udp.listen(8888)) { Serial.print("UDP listening on IP: "); Serial.println(WiFi.localIP()); udp.onPacket(handlePacket); } } void loop() { // Send a message every 5 seconds static unsigned long lastSend = 0; if (millis() - lastSend > 5000) { lastSend = millis(); udp.sendTo("Hello Server", "192.168.1.100", 8888); Serial.println("Sent 'Hello Server'"); } } void handlePacket(AsyncUDPPacket packet) { Serial.print("UDP Packet received from "); Serial.print(packet.remoteIP()); Serial.print(":"); Serial.print(packet.remotePort()); Serial.print(" Data: "); Serial.write(packet.data(), packet.length()); Serial.println(); } ``` -------------------------------- ### AsyncUDPMulticastServer Example Source: https://github.com/khoih-prog/asyncudp_esp32_ethernet/blob/main/README.md This example demonstrates setting up a UDP server to send and receive data using multicast. Multicast allows a single UDP packet to be sent to multiple recipients simultaneously. This is efficient for broadcasting information to a group of devices on the network. ```cpp #include #include AsyncUDP udp; // Multicast group address IPAddress multicastGroup(239, 1, 2, 3); void setup() { Serial.begin(115200); Serial.println("Starting AsyncUDPMulticastServer example..."); WiFi.begin(ssid, password); while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); } Serial.println(""); Serial.println("WiFi connected"); Serial.println("IP address: "); Serial.println(WiFi.localIP()); // Join the multicast group if (udp.listenMulticast(multicastGroup, 8888)) { Serial.print("Listening on multicast group "); Serial.print(multicastGroup); Serial.println(":8888"); udp.onPacket(handlePacket); } } void loop() { // Send a multicast message every 5 seconds static unsigned long lastSend = 0; if (millis() - lastSend > 5000) { lastSend = millis(); udp.sendTo("Hello Multicast Group", multicastGroup, 8888); Serial.println("Sent 'Hello Multicast Group'"); } } void handlePacket(AsyncUDPPacket packet) { Serial.print("UDP Packet received from "); Serial.print(packet.remoteIP()); Serial.print(":"); Serial.print(packet.remotePort()); Serial.print(" Data: "); Serial.write(packet.data(), packet.length()); Serial.println(); } ``` -------------------------------- ### Fix Multiple Definitions Linker Error (h) Source: https://github.com/khoih-prog/asyncudp_esp32_ethernet/blob/main/README.md Include this header file in only one main source file (e.g., main.cpp, .ino with setup()) to prevent linker errors. Ensure it's not included by other files. ```cpp // To be included only in main(), .ino with setup() to avoid `Multiple Definitions` Linker Error #include "AsyncUDP_ESP32_Ethernet.h" //https://github.com/khoih-prog/AsyncUDP_ESP32_Ethernet ``` -------------------------------- ### ESP32 W5500: Async UDP NTP Client Source: https://github.com/khoih-prog/asyncudp_esp32_ethernet/blob/main/README.md Displays terminal output for an ESP32 using the W5500 Ethernet module and the AsyncUDP_ESP32_Ethernet library for asynchronous NTP time retrieval. It shows the setup and the received UTC/GMT time. ```cpp Start AsyncUdpNTPClient on ESP32_DEV with ESP32_W5500 WebServer_ESP32_W5500 v1.5.2 for core v2.0.0+ AsyncUDP_ESP32_Ethernet v2.1.0 for core v2.0.0+ [UDP] Default SPI pinout: [UDP] SPI_HOST: 2 [UDP] MOSI: 23 [UDP] MISO: 19 [UDP] SCK: 18 [UDP] CS: 5 [UDP] INT: 4 [UDP] SPI Clock (MHz): 25 [UDP] ========================= ETH Started ETH Connected ETH MAC: 0C:B8:15:D8:01:D7, IPv4: 192.168.2.34 FULL_DUPLEX, 100Mbps AsyncUDPSendReceive started @ IP address: 192.168.2.34 UDP connected ============= createNTPpacket ============= Received UDP Packet Type: Unicast From: 208.81.1.244:123, To: 192.168.2.34:62164, Length: 48 Seconds since Jan 1 1900 = 3882392857 Epoch/Unix time = 1673404057 The UTC/GMT time is Wed 2023-01-11 02:27:37 GMT ``` -------------------------------- ### ESP32 ENC28J60 AsyncUDP SendReceive Debug Output Source: https://github.com/khoih-prog/asyncudp_esp32_ethernet/blob/main/README.md Terminal debug output from the AsyncUDPSendReceive example running on ESP32_ENC28J60. It shows network connection details, UDP packet reception from an NTP server, and the processed UTC time. ```cpp Start AsyncUDPSendReceive on ESP32_DEV with ESP32_ENC28J60 WebServer_ESP32_ENC v1.5.1 for core v2.0.0+ AsyncUDP_ESP32_Ethernet v2.1.0 for core v2.0.0+ [UDP] Default SPI pinout: [UDP] SPI_HOST: 2 [UDP] MOSI: 23 [UDP] MISO: 19 [UDP] SCK: 18 [UDP] CS: 5 [UDP] INT: 4 [UDP] SPI Clock (MHz): 25 [UDP] ========================= ETH Started ETH Connected ETH MAC: 0C:B8:15:D8:01:D7, IPv4: 192.168.2.34 FULL_DUPLEX, 10Mbps AsyncUDPSendReceive started @ IP address: 192.168.2.34 Starting connection to server... UDP connected ============= createNTPpacket ============= Received UDP Packet Type: Unicast From: 208.81.1.244:123, To: 192.168.2.34:62164, Length: 48 Seconds since Jan 1 1900 = 3882392797 Epoch/Unix time = 1673403997 The UTC/GMT time is Wed 2023-01-11 02:26:37 GMT ============= sendACKPacket ============= ``` -------------------------------- ### Reformat Library Code with astyle Source: https://github.com/khoih-prog/asyncudp_esp32_ethernet/blob/main/CONTRIBUTING.md This snippet demonstrates the shell commands required to reformat the library's code using the 'astyle' tool. It involves navigating to the library's directory and executing the reformatting script. ```Shell xy@xy-Inspiron-3593:~$ cd Arduino/xy/AsyncUDP_ESP32_Ethernet_GitHub/ xy@xy-Inspiron-3593:~/Arduino/xy/AsyncUDP_ESP32_Ethernet_GitHub$ bash utils/restyle.sh ``` -------------------------------- ### AsyncUDP_ESP32_Ethernet Debugging Configuration Source: https://github.com/khoih-prog/asyncudp_esp32_ethernet/blob/main/README.md Configuration macros to enable and set the debugging log level for the AsyncUDP_ESP32_Ethernet library. Higher log levels provide more verbose output. ```cpp #define ASYNC_UDP_ESP32_ETHERNET_DEBUG_PORT Serial // Use from 0 to 4. Higher number, more debugging messages and memory usage. #define _ASYNC_UDP_ESP32_ETHERNET_LOGLEVEL_ 1 ``` ```cpp #define ASYNC_UDP_ESP32_ETHERNET_DEBUG_PORT Serial // Use from 0 to 4. Higher number, more debugging messages and memory usage. #define _ASYNC_UDP_ESP32_ETHERNET_LOGLEVEL_ 4 ``` -------------------------------- ### Fix Multiple Definitions Linker Error (hpp) Source: https://github.com/khoih-prog/asyncudp_esp32_ethernet/blob/main/README.md Include this header file in multiple source files to avoid linker errors. It's designed for safe multiple inclusions. ```cpp // Can be included as many times as necessary, without `Multiple Definitions` Linker Error #include "AsyncUDP_ESP32_Ethernet.hpp" //https://github.com/khoih-prog/AsyncUDP_ESP32_Ethernet ``` -------------------------------- ### ESP32 W6100: Async UDP NTP Client Source: https://github.com/khoih-prog/asyncudp_esp32_ethernet/blob/main/README.md Shows terminal output for an ESP32 using the AsyncUDP_ESP32_Ethernet library to asynchronously retrieve NTP time from a server. It details the connection process, packet reception, and time decoding. ```cpp Start AsyncUdpNTPClient on ESP32_DEV with ESP32_W6100 WebServer_ESP32_W6100 v1.5.2 for core v2.0.0+ AsyncUDP_ESP32_Ethernet v2.1.0 for core v2.0.0+ [UDP] Default SPI pinout: [UDP] SPI_HOST: 2 [UDP] MOSI: 23 [UDP] MISO: 19 [UDP] SCK: 18 [UDP] CS: 5 [UDP] INT: 4 [UDP] SPI Clock (MHz): 25 [UDP] ========================= ETH Started ETH Connected ETH MAC: 0C:B8:15:D8:01:D7, IPv4: 192.168.2.34 FULL_DUPLEX, 100Mbps AsyncUdpNTPClient started @ IP address: 192.168.2.34 UDP connected ============= createNTPpacket ============= Received UDP Packet Type: Unicast From: 208.81.1.244:123, To: 192.168.2.34:55314, Length: 48 Seconds since Jan 1 1900 = 3882392659 Epoch/Unix time = 1673403859 The UTC/GMT time is Wed 2023-01-11 02:24:19 GMT ``` -------------------------------- ### AsyncUDP_ESP32_Ethernet Library Features Source: https://github.com/khoih-prog/asyncudp_esp32_ethernet/blob/main/README.md This library provides a fully asynchronous UDP communication for ESP32 microcontrollers. It is designed to handle multiple network connections efficiently and supports Unicast, Broadcast, and Multicast communication modes. The library is compatible with ESP32 boards utilizing W5500, W6100, or ENC28J60 Ethernet controllers. ```cpp #include // Initialize AsyncUDP object AsyncUDP udp; void setup() { Serial.begin(115200); Serial.println("Starting AsyncUDP_ESP32_Ethernet example..."); // Start UDP server on port 8888 if (udp.listen(8888)) { Serial.print("UDP listening on IP: "); Serial.println(WiFi.localIP()); udp.onPacket(handlePacket); } } void loop() { // The library handles UDP events asynchronously } void handlePacket(AsyncUDPPacket packet) { Serial.print("UDP Packet received from "); Serial.print(packet.remoteIP()); Serial.print(":"); Serial.print(packet.remotePort()); Serial.print(" Data: "); Serial.write(packet.data(), packet.length()); Serial.println(); // Send a reply udp.send("Hello Client", packet.remoteIP(), packet.remotePort()); } ``` -------------------------------- ### ESP32 Ethernet Module Pinout Source: https://github.com/khoih-prog/asyncudp_esp32_ethernet/blob/main/README.md Specifies the SPI and control pin connections between ESP32 and Ethernet modules (W5500, W6100, ENC28J60). ```APIDOC Ethernet Module <-> ESP32 Pin Mapping: | Module Pin | ESP32 Pin | |------------|-----------| | MOSI | GPIO23 | | MISO | GPIO19 | | SCK | GPIO18 | | CS/SS | GPIO5 | | INT | GPIO4 | | RST | RST | | GND | GND | | 3.3V | 3.3V | ``` -------------------------------- ### ESP32 W6100: Async UDP Send Receive (NTP + ACK) Source: https://github.com/khoih-prog/asyncudp_esp32_ethernet/blob/main/README.md Illustrates terminal output for an ESP32 with W6100 Ethernet, using AsyncUDP_ESP32_Ethernet to fetch NTP time and subsequently send an ACK packet. It shows the asynchronous reception and processing of NTP packets. ```cpp Start AsyncUDPSendReceive on ESP32_DEV with ESP32_W6100 WebServer_ESP32_W6100 v1.5.2 for core v2.0.0+ AsyncUDP_ESP32_Ethernet v2.1.0 for core v2.0.0+ [UDP] Default SPI pinout: [UDP] SPI_HOST: 2 [UDP] MOSI: 23 [UDP] MISO: 19 [UDP] SCK: 18 [UDP] CS: 5 [UDP] INT: 4 [UDP] SPI Clock (MHz): 25 [UDP] ========================= ETH Started ETH Connected ETH MAC: 0C:B8:15:D8:01:D7, IPv4: 192.168.2.34 FULL_DUPLEX, 100Mbps AsyncUDPSendReceive started @ IP address: 192.168.2.34 Starting connection to server... UDP connected ============= createNTPpacket ============= Received UDP Packet Type: Unicast From: 208.81.1.244:123, To: 192.168.2.34:62164, Length: 48 Seconds since Jan 1 1900 = 3882392738 Epoch/Unix time = 1673403938 The UTC/GMT time is Wed 2023-01-11 02:25:38 GMT ============= sendACKPacket ============= ============= createNTPpacket ============= Received UDP Packet Type: Unicast From: 208.81.1.244:123, To: 192.168.2.34:62164, Length: 48 Seconds since Jan 1 1900 = 3882392797 Epoch/Unix time = 1673403997 The UTC/GMT time is Wed 2023-01-11 02:26:37 GMT ============= sendACKPacket ============== ``` -------------------------------- ### Ethernet Module INT Pin Configuration Source: https://github.com/khoih-prog/asyncudp_esp32_ethernet/blob/main/README.md Defines the GPIO pin connected to the interrupt (INT) line of Ethernet modules like W5500, W6100, or ENC28J60. The default is GPIO4. ```cpp // Must connect INT to GPIOxx or not working #define INT_GPIO 4 ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.