The Official ESP32 Book

Page 31

CHAPTER 10 • REMOTE CONTROL USING MOBILE PHONE

10.3 Mobile Phone Application In this project an Android based mobile phone is used to send the UDP commands. Although one could develop a mobile application to send the UDP commands, there are many freely available UDP apps in the Play Store that can be used to send and/or receive UDP packets. The one used in this project is called UDP RECEIVE and SEND by Wezzi Studios (version 4.0). This application can send and receive UDP packets from any other device running the UDP protocol. The screen is in two parts: the upper Sender part and the lower Receiver part (see Figure 10.2). The user must specify the destination IP address, port number, and the message to be sent. Before sending a packet the user must enter the destination IP address, port number, and the message to be sent. Clicking the SEND UDP MESSAGE button will send the packet to its destination. In the Receiver part the local IP address is given The user must specify the required port number. Received packets will then be displayed on the screen.

Figure 10.2 Android UDP send/receive apps In this program, the IP address of the ESP32 DevKitC was 192.168.1.156. 10.4 ESP32 DevKitC Program Listing Figure 10.3 shows the complete program (program: UDPControl). At the beginning of the program, the Wi-Fi library headers are included in the program, LED0 and LED1 are assigned to GPIO ports 23 and 22 respectively, local port number is defined, and the local Wi-Fi name and password are defined. Function Connect_WiFi connects to the local Wi-Fi network. Inside the setup routine the LED ports are configured as outputs and both LEDs are turned OFF to start with. Then function Connect_WiFi is called to connect to local Wi-Fi and UDP is started on the local port. The remainder of the program is executed in an endless loop. Inside this loop the program

â—? 249

ESP32 UK 170828.indd 249

26-09-17 15:28


Turn static files into dynamic content formats.

Create a flipbook
Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.
The Official ESP32 Book by Elektor - Issuu