Level 6 · socketio
Robot Car Client
A Python client that connects to the robot car over Wi-Fi and sends movement commands (go, stop, left, right, back). Connect your laptop to the car's hotspot before running.
What it teaches: Network clients, real-time commands, robot control
How to run
Starter file: robot_car_client.py
python robot_car_client.pyStarter code
import socketio
import time
SERVER = 'http://192.168.4.1:5000'
sio = socketio.Client()
@sio.event
def connect():
print(f'server connected: {SERVER}')
@sio.event
def disconnect():
print('server disconnected')
@sio.on('status')
def on_status(data):
print('server response:', data)
def send(action):
sio.emit('cmd', {'action': action})
time.sleep(0.1) #
sio.connect(SERVER)
while True:
direction = input("Enter direction: ")
if direction == "go":
send('go')
elif direction == "stop":
send('stop')
if direction == "left":
send('left')
elif direction == "right":
send('right')
elif direction == "back":
send('back')
sio.disconnect()
Challenge ideas
Easy
- Add a help command that prints all available directions.
- Change the delay in send() to make commands faster or slower.
- Add quit or exit to break out of the loop cleanly.
Medium
- Replace keyboard input with arrow-key controls using a library like keyboard or pynput.
- Add error handling if the server is unreachable (try/except around sio.connect).
- Log every command and server response to a text file.
Hard
- Build a guizero GUI (Level 2) with on-screen buttons that send go/stop/left/right/back.
- Add a sequence mode: type a series of moves like "go,left,go,stop" and run them automatically.
- Combine with pygame (Level 4) to draw a simple remote-control dashboard.
Ask your AI tool
“How do I add a timeout and auto-reconnect if my socketio robot car client loses Wi-Fi connection?”