In our loop() function we will continuously check to see if a UDP packet has been received. We will keep things nice and simple so that you gain and understanding of how it works, then you can copy and paste the code and expand on it for your own project! Adding UDP supportįirst we need to add an include for the WiFi UDP library. Now that we have the basic code placed in a new Arduino IDE project, we can start to add the additional code for sending and receiving UDP. put your main code here, to run repeatedly: Loop continuously while WiFi is not connected #define WIFI_SSID "YOUR WIFI NETWORK SSID"
Alternatively you can use a different method to send and receive the UDP packets if you prefer. I would also recommend that you use PacketSender to test communications after you flash the device, you can download it for free. The tutorial is written for the Wemos D1 Mini but it applies to any ESP-based board compatible with the Arduino ESP core.
I would recommend that you first follow my tutorial on how to configure the Arduino IDE for ESP devices and connect your device to WiFi. You will also need an ESP-based board such as the Wemos D1 Mini, as this will not work with a standard Arduino board. You will need to have the Arduino IDE installed and configured to flash ESP devices. In this tutorial we will write a simple application in the Arduino IDE that will receive a text string over UDP, print it to the serial console and then respond back with a confirmation message. You can use UDP to communicate with other ESP8266 devices, your computer or many other WiFi devices. Looking for the easiest way to send and receive data from an ESP8266? A great starting point is understanding how to configure your ESP8266 to send and receive a UDP packet.