11

Networking and Communications

Week 11 · Wi-Fi AP + web control for the Tableside Interactive Robot

Assignment Overview

  • Group: Send a message between two projects. Document on the group page; reflect here.
  • Individual: Design, build, and connect wired or wireless node(s) with network or bus addresses — and document how they talk.

For this week I document the networking path of my final project: the phone / laptop joins a Wi‑Fi access point on the XIAO ESP32-C6, opens a web page, and drives the chassis over HTTP. Web coding and radio networking are one loop — the UI is the remote node, the C6 is the addressed board on the car.

1. Group Work

Lab group documentation:

What I learned from the group work

Shared lab tests and settings are on the UNNC group page; I use those notes for my individual build on this page.

2. Individual Work

Individual idea — web coding + networked car

The Tableside Interactive Robot is a small car with arm and face. Local colour vision and I²C face/servo buses stay on-board; remote driving is networking week:

  1. C6 starts a Wi‑Fi softAP (Robot / 12345678) at fixed IP 192.168.4.1.
  2. Phone or laptop joins that AP and opens http://192.168.4.1 (or the Operation HTML against the same origin).
  3. The page is plain HTML + CSS + JavaScript: buttons and a steering wheel call fetch() to REST-style routes on the board.
  4. Firmware maps those routes to motor GPIO pulses and PCA9685 steering / arm targets, with a FreeRTOS watchdog so a dropped Wi‑Fi client cannot leave motors running.
Diagram: phone or laptop to ESP32-C6 Wi-Fi AP to motors and servos
Network path — STA browser → softAP WebServer → drive / steer actuators

Full system context (camera, dual-rail power, packaging) is on Week 16 and the final project page; this week stays on addresses, protocols, and the web↔car link.

Addresses and nodes

NodeAddress / linkRole
XIAO ESP32-C6 (final PCB) Wi‑Fi AP 192.168.4.1, HTTP port 80 Networked controller; serves UI; runs /api/*
Phone / laptop browser DHCP client on 192.168.4.x Web UI node — drive, steer, stop, state poll
MaixCAM UART 115200 on C6 GPIO 17/16 Sends one-letter colour codes (r/g/b/…) into the same firmware
PCA9685 / screen I²C 0x40 / 0x32 Local bus actuators / face (not Wi‑Fi, but same master)

Photos TBD: phone Wi‑Fi joined to SSID Robot, browser open at 192.168.4.1, car moving from hold-to-drive.

Photo slot — AP join + web UI controlling the car

SoftAP + HTTP server on the C6

Firmware lives in RobotMaster.ino with the embedded page in ControlPage.h (same sources under data-final/RobotMaster/). After motors and the watchdog task start, setup brings up the AP and registers routes:

WiFi.mode(WIFI_AP);
WiFi.softAPConfig(IPAddress(192, 168, 4, 1),
                  IPAddress(192, 168, 4, 1),
                  IPAddress(255, 255, 255, 0));
WiFi.softAP("Robot", "12345678");

server.on("/", HTTP_GET, []() {
  server.send_P(200, "text/html; charset=utf-8", CONTROL_PAGE);
});
server.on("/api/state", HTTP_GET, sendState);
server.on("/api/drive", HTTP_POST, handleDrive);
server.on("/api/drive-stop", HTTP_POST, handleStop);
server.on("/api/steer", HTTP_POST, handleSteer);
server.on("/api/stop", HTTP_POST, handleEmergencyStop);
server.begin();

The fixed AP IP means every STA can bookmark the same URL. loop() only calls server.handleClient() plus camera/servo upkeep — networking stays cooperative with local I/O.

Optional: Serial Monitor screenshot showing “Open http://192.168.4.1”.

API — how the web page talks to the car

Commands are POST form bodies; state is GET JSON. CORS headers allow opening the Operation HTML from the site folder while still targeting the board origin during development.

RouteMethodPurpose
/api/stateGETMotors, epoch, PCA/screen/camera flags, servo targets
/api/drivePOSTdirection=forward|reverse + epoch — short pulse; UI repeats while held
/api/drive-stopPOSTStop motors only
/api/steerPOSTangle, mode (counter / parallel / front) + controlEpoch
/api/stopPOSTEmergency: motors off, freeze servos, bump controlEpoch
/api/servo · /api/face · /api/cameraPOSTArm / shade / expressions / vision follow (same network)

Drive heartbeat (web side)

Holding ▲ / ▼ does not stream raw GPIO forever. The JS keeps posting /api/drive about every 180 ms with the current epoch. Firmware accepts only a matching epoch, writes motor pins for ~650 ms, and the FreeRTOS watchdog forces a stop if pulses expire — so a crashed tab or lost Wi‑Fi cannot leave the car running.

async function heartbeat(token) {
  if (!online || !moving || token !== op) return;
  const work = request('/api/drive', { direction: moving, epoch: state.epoch });
  await work;
  if (token === op && moving) heart = setTimeout(() => heartbeat(token), 180);
}

State JSON (board side excerpt)

{"firmware":"robot-v3.11","pins":[0,1,2,21],
 "motorA":0,"motorB":0,"remainingMs":0,"cooldownMs":0,
 "epoch":3,"controlEpoch":1,"watchdogReady":true,
 "pcaFound":true,"cameraOnline":false,"steeringAngle":0,
 "servos":[...]}

The UI refuses to connect if firmware or motor pin list does not match — networking and web coding stay version-locked together.

Web UI files

  • ControlPage.h — English Operation UI served from flash at / (full drive + calibrate + faces).
  • Robot-Operation.html — English Operation edition (same API; used as the polished remote UI).
  • Robot-Test.html — Test edition for motor / invert calibration before free driving.

UI features that matter for networking week: connect to http://192.168.4.1, poll /api/state, hold-to-drive with heartbeat, steering wheel → /api/steer, big stop → /api/stop, and reconnect lockout if fetch fails.

Connect from the laptop

Join the robot softAP from the Mac Wi‑Fi menu, open the Operation page, keep C6 address as http://192.168.4.1, then click Connect. Password for the AP is 12345678 (SSID softAP name in firmware: Robot; macOS may show the Chinese label 机器人 when that network is selected).

Mac joined robot Wi-Fi; Operation page with C6 address 192.168.4.1 and Connect button
Joined the robot Wi‑Fi → Operation UI → Connect to http://192.168.4.1

More screenshots TBD: connected badge / live state; forward held; stop pressed.

How to run (reproduce)

  1. Flash RobotMaster.ino (+ ControlPage.h in the sketch folder) to the XIAO ESP32-C6 board in Arduino IDE.
  2. Power the logic rail; confirm Serial: Wi‑Fi SSID and http://192.168.4.1.
  3. On phone/laptop: join Wi‑Fi Robot / 机器人, password 12345678.
  4. Open http://192.168.4.1 or load Robot-Operation.html, confirm C6 address, click Connect.
  5. Center steering, hold Forward briefly with wheels clear, then Stop.

Chassis packaging and dual-rail power notes: Week 16.

Results

  • Wireless node with a fixed network address (C6 softAP at 192.168.4.1).
  • Second node = browser on STA; messages = HTTP GET/POST with JSON state.
  • Car motion and steering proven through that link; fail-safe stop on timeout / emergency API.
  • Same stack reused by the final project remote UI.

Demo photo / short clip of networked drive still to drop in.

Hero / demo — web-controlled car motion

Files

Notes

  • Why AP mode: no lab router required; phone always finds the same IP on the robot’s own network.
  • Why HTTP + JSON instead of raw sockets: the browser already speaks fetch; one page can drive motors and show live state without a native app.
  • Safety: pulse + epoch + watchdog + emergency stop — networking demos must assume the radio will drop.
  • Challenge: keeping server.handleClient() responsive while UART camera traffic arrives — bounded UART reads and a short delay(2) keep the HTTP service alive.