Setting Up Wi-Fi Control with ESP32
Overview
Wi-Fi control using UDP is the fastest and most responsive connection method in RoboLink. This tutorial covers setting up an ESP32 as a Wi-Fi access point and communicating with the app.
Why UDP?
RoboLink uses UDP (User Datagram Protocol) instead of TCP for wireless communication. Here's why:
- Lower latency — No connection handshake overhead
- Real-time performance — Packets are sent immediately
- Better for control — Dropped packets are acceptable; old data is replaced by new data
UDP does not guarantee delivery, which is actually ideal for real-time control applications. If a joystick position packet is lost, the next one arrives milliseconds later with updated data.
Hardware Setup
You'll need:
- ESP32 development board (any variant)
- USB cable for programming
- Your robot's motor/servo hardware
Setting Up the Access Point
The ESP32 can create its own Wi-Fi network, so you don't need a router:
#include <RoboLinkWiFi.h>
RoboLinkWiFi robolink;
void setup() {
Serial.begin(115200);
// Create an access point named "RoboLink_Robot"
// on port 4210 with 50ms update interval
robolink.beginAP("RoboLink_Robot", "password123", 4210);
Serial.println("Access point started!");
Serial.print("IP: ");
Serial.println(WiFi.softAPIP());
}
void loop() {
robolink.update();
// Get joystick values (-255 to 255)
int steerX = robolink.getValue("steerX");
int steerY = robolink.getValue("steerY");
// Get button states (0 or 1)
int horn = robolink.getValue("horn");
int lights = robolink.getValue("lights");
// Get slider values (0 to 255)
int speed = robolink.getValue("speed");
}
Connecting from the App
- Connect your phone to the ESP32's Wi-Fi network ("RoboLink_Robot")
- Open RoboLink
- Tap the connection button
- Select Wi-Fi / UDP
- Enter port 4210
- Set interval to 50 ms (default)
- Tap Connect
The status indicator will turn green when connected.
Configuring Update Interval
The update interval controls how frequently the app sends control data:
| Interval | Use Case |
|---|---|
| 20 ms | High-speed racing, precise servo control |
| 50 ms | General purpose (recommended) |
| 100 ms | Battery saving, slow robots |
| 200 ms | Minimal updates, sensor reading only |
Setting the interval below 20ms may cause network congestion on some ESP32 boards. Start with 50ms and decrease only if needed.
Reading Multiple Values
RoboLink sends all widget values as key-value pairs. Each widget has a configurable key that you use to read its value:
void loop() {
robolink.update();
// Joystick axes
int x = robolink.getValue("steerX"); // -255 to 255
int y = robolink.getValue("steerY"); // -255 to 255
// Buttons (momentary)
int horn = robolink.getValue("horn"); // 0 or 1
int brake = robolink.getValue("brake"); // 0 or 1
// Toggles (latching)
int lights = robolink.getValue("lights"); // 0 or 1
int rev = robolink.getValue("rev"); // 0 or 1
// Sliders
int speed = robolink.getValue("speed"); // 0 to 255
}
Troubleshooting
Can't connect?
- Verify your phone is connected to the ESP32's network
- Check that the port number matches
- Restart both the ESP32 and the app
High latency?
- Reduce the update interval
- Move closer to the ESP32
- Check for Wi-Fi interference
Values not changing?
- Ensure widget keys match the
getValue()parameter names - Check the Serial Monitor for incoming data
Next Steps
Once you have basic Wi-Fi control working, explore:
- Adding camera streaming with ESP32-CAM
- Creating custom controller layouts
- Implementing motor control logic