WebSocket Command Guide
1. System Overview
| Component | Role |
|---|---|
| Controller | Wireless command hub, wired bus master |
| Motor Boards | Individual motor control, position sensing, addressable 0โ15 |
| Wired Bus Modules | Signal transceivers between Controller and Motor Boards |
| Browser / Grasshopper | WebSocket client sending commands |
Network Details
| Parameter | Value |
|---|---|
| Network Mode | Station (connects to existing Wi-Fi network) |
| WebSocket URL | ws://<CONTROLLER_IP>:81 |
| Web Control Page | http://<CONTROLLER_IP>/ |
| Wireless Discovery Name | MT_A0-<CONTROLLER_IP> |
| Bus Speed | 9600, 8N1 |
1.1 Create the Access Point (Mobile Hotspot)
The Controller is hard-coded to connect to a Wi-Fi network with fixed credentials. Before powering on the Controller, you must create this network using a mobile hotspot.
| Parameter | Value |
|---|---|
| Hotspot SSID | AP |
| Hotspot Password | 56784321 |
| Security | WPA2-PSK (recommended) |
| Band | 2.4 GHz (required โ 5 GHz is not supported) |
Steps to create the hotspot:
- On your mobile phone, open Settings โ Hotspot & Tethering (or Personal Hotspot on iOS).
- Set the Network Name (SSID) to exactly
APโ case-sensitive. - Set the Password to exactly
56784321. - Ensure the hotspot is using 2.4 GHz band (some phones let you choose; on iOS, enable Maximize Compatibility).
- Turn the hotspot ON.
AP and 56784321.
1.2 Power On the Controller
Once the hotspot is active, power on the Motor Tile Controller. It will:
- Boot and initialise the wired bus.
- Automatically scan for and connect to the Wi-Fi network named
AP. - Obtain an IP address from the mobile hotspot (typically in the
192.168.x.xrange). - Start its WebSocket server on port 81 and its web page on port 80.
- Broadcast its IP over the wireless discovery name
MT_A0-<IP>.
1.3 Connect Your Computer to the Same Network
For a computer (Windows / macOS / Linux) to send commands to the Controller, it must be on the same network โ i.e., connected to the same mobile hotspot you created in step 1.1.
Steps:
- On your computer, open Wi-Fi settings.
- Select the network named
APfrom the list of available networks. - Enter the password
56784321. - Wait for the connection to establish (the computer will receive its own IP from the hotspot).
- Verify connectivity by opening a browser and navigating to
http://<CONTROLLER_IP>/.
1.4 Finding the Controller IP Address
The Controller's IP address can be obtained using any one of the following methods. You do not need to use all of them โ pick whichever is most convenient for your setup.
- Wireless Scan โ open any Bluetooth scanner app, look for
MT_A0-192.168.x.x. The IP is embedded in the discovery name. - Serial Monitor โ connect via USB at 115200 baud. The IP is printed on boot.
- Router / Hotspot Admin โ check the connected devices list for hostname
MT_A0. - Mobile Hotspot Client List โ most phones show connected devices under Hotspot settings; look for
MT_A0.
MT_A0-192.168.1.45 means the Controller is at 192.168.1.45.
2. Connecting via WebSocket
Open a WebSocket connection to:
ws://<CONTROLLER_IP>:81
On successful connection, the Controller sends a welcome message:
Connected to Motor Tile
2.1 Verify the Connection with Reference Tools
Before integrating with your own software, confirm that the Controller is reachable and responding. Use the following online tools:
Standalone WebSocket Tester โ send raw text or binary commands and view responses.
Motor Tiles Web Control Page โ full grid interface with click-to-move, patterns, and live log.
Test procedure:
- Open the Standalone WebSocket Tester in a browser.
- Enter the WebSocket URL:
ws://<CONTROLLER_IP>:81. - Click Connect. The status should change to Connected.
- Send the query command:
? - You should receive a response like
OK ?followed by the address digits of all connected Motor Boards (e.g.,0,1,2โฆ). - Send a test move:
M 0 1 1500 400 - You should receive
OK Mand the motor should physically move.
OK M in the log and the motor moves, the Controller is confirmed working end-to-end. You can now proceed with your own integration.
2.2 Connection Requirements
- Client and Controller must be on the same network / subnet (see section 1.3).
- Port 81 must be reachable (no firewall blocking).
- Mobile hotspots must not have "client isolation" enabled.
file:// pages. Always load the control page from http://<CONTROLLER_IP>/ on mobile devices.
3. Command Reference
All commands are sent as plain text UTF-8 strings over the WebSocket. No framing, no length prefix, no termination character required.
3.1 Motor Movement
Format:
M <addr> <dir> <delay> <steps>
| Field | Type | Description | Range |
|---|---|---|---|
M | literal | Move command prefix | โ |
addr | hex char | Motor address | 0โ9, AโF (0โ15) |
dir | char | Direction | 1=Clockwise, 0=Counter-clockwise |
delay | int | Step delay (ยตs) | 1000โ65535 |
steps | int | Number of steps | 1โ65535 |
Examples:
M 0 1 1500 800 โ Motor 0, CW, 1500 ยตs delay, 800 steps
M 5 0 2000 1200 โ Motor 5, CCW, 2000 ยตs delay, 1200 steps
M A 1 1200 400 โ Motor 10, CW, 1200 ยตs delay, 400 steps
Response: OK M
3.2 Homing
| Command | Action | Response |
|---|---|---|
H <addr> | Home a specific motor (uses onboard position sensor) | OK H |
HA | Home all motors (broadcast) | OK HA |
Examples:
H 0 โ Home motor 0
H F โ Home motor 15
HA โ Home all motors
RDY when done. Wait ~5 seconds before sending the next command.3.3 Dynamic Home Management
In addition to the factory absolute zero, Motor Boards can be taught a custom "Zero" position. This is useful for aligning tiles that have mechanical offsets or specific physical starting points.
| Command | Action | Response |
|---|---|---|
T <addr> | Teach: Saves the motor's current physical position as the new Home. | SAVED_T |
U <addr> | Unset: Clears the custom home and reverts to the factory absolute zero. | SAVED_U |
G <addr> | Get: Queries the current saved home status. | HOME:VALID:XXXX or HOME:FACTORY:0 |
Examples:
T 0 โ Teach motor 0's current position as home
U 5 โ Unset custom home for motor 5 (revert to factory)
G A โ Query motor 10 to see if it has a custom home
H or HA commands.3.4 Query
| Command | Action | Response |
|---|---|---|
? | Query all Motor Board addresses on the bus | Hex digit(s) e.g. 0, 5, A |
3.5 System Reset
| Command | Action | Response |
|---|---|---|
X | Software reset all Motor Boards | OK X |
X resets every board on the bus. Use only when the system is idle.
4. Response Codes Summary
| Response | Meaning |
|---|---|
Connected to Motor Tile | WebSocket handshake succeeded |
OK M | Motor move command accepted |
OK H | Home command accepted |
OK HA | Home-all accepted |
OK X | Reset command accepted |
OK ASCII | Generic passthrough command forwarded |
OK ? | Query sent (no board replied within 300 ms) |
ERR M | Malformed move command |
SAVED_T | Custom home taught successfully |
SAVED_U | Custom home unset, reverted to factory |
HOME:VALID:XXXX | Current custom home angle (e.g., 1234) |
HOME:FACTORY:0 | No custom home saved |
RDY / HOMEFAIL | From Motor Board (visible in Serial Monitor only) |
5. Grasshopper Integration
5.1 Architecture
Grasshopper (Rhino)
โ
โ HTTP POST (localhost:8080)
โผ
Python Bridge Server โโโโ WebSocket (ws://CONTROLLER_IP:81) โโโโโบ Controller
โฒ
โ HTTP response (status)
โ
Grasshopper Python Component
The Python bridge is required because Grasshopper runs on a single UI thread and cannot safely block on WebSocket replies.
5.2 Python Bridge Server
import asyncio, websockets
from http.server import HTTPServer, BaseHTTPRequestHandler
CONTROLLER_IP = "192.168.x.x" # โ replace
HTTP_PORT = 8080
async def send_to_controller(message):
try:
async with websockets.connect(f"ws://{CONTROLLER_IP}:81") as ws:
await ws.send(message)
try:
resp = await asyncio.wait_for(ws.recv(), timeout=0.5)
print(f"Controller: {resp}")
except asyncio.TimeoutError:
pass
except Exception as e:
print(f"WS error: {e}")
class Handler(BaseHTTPRequestHandler):
def do_POST(self):
n = int(self.headers['Content-Length'])
cmd = self.rfile.read(n).decode()
print(f"GH โ {cmd}")
asyncio.run(send_to_controller(cmd))
self.send_response(200)
self.end_headers()
self.wfile.write(b"OK")
def do_GET(self):
self.send_response(200)
self.end_headers()
self.wfile.write(b"Bridge running")
HTTPServer(('0.0.0.0', HTTP_PORT), Handler).serve_forever()
Run: python bridge.py
5.3 Grasshopper Python Component
import urllib.request
if send and command:
data = command.encode('utf-8')
req = urllib.request.Request(
"http://localhost:8080",
data=data, method='POST')
try:
with urllib.request.urlopen(req, timeout=1) as r:
status = r.read().decode()
except Exception as e:
status = f"ERR: {e}"
else:
status = "IDLE"
Inputs: command (String), send (Boolean)
Output: status (String)
5.4 Grasshopper Command Examples
| Action | Command String |
|---|---|
| Move motor 0 CW, 800 steps | M 0 1 1500 800 |
| Move motor 5 CCW, 1200 steps | M 5 0 2000 1200 |
| Home motor 3 | H 3 |
| Home all | HA |
| Query bus | ? |
| Reset all | X |
5.5 Generating Patterns in Grasshopper
Build a list of command strings using standard GH components and send them sequentially. Example using a Series component + Format to generate moves:
M {0} 1 1500 800 โ for addr = 0..15
Feed each string into the Python component, toggling send with a Button or Trigger.
6. Testing Guide
- Create the mobile hotspot (SSID:
AP, password:56784321) โ see section 1.1. - Power the Controller and Motor Boards. Wait for the Controller to connect to the hotspot.
- Connect your computer to the same hotspot โ see section 1.3.
- Confirm the Controller IP using any one method from section 1.4.
- Verify the connection using the Standalone WebSocket Tester โ see section 2.1.
- Send
?โ confirm you receive the address replies from all boards. - Send
M 0 1 1500 400โ confirm the motor moves and you receiveOK M. - Start the Python bridge on your PC.
- Open Grasshopper with the Python component.
- Send
M 0 1 1500 400from Grasshopper โ the motor should move.
6.1 Online Reference Tools
Standalone WebSocket Tester โ browser-based tool for sending raw text or binary commands to the Controller without installing any software.
Motor Tiles Web Control Page โ full grid interface with click-to-move, pattern library, and live log. Open this from any device on the same network.
7. Troubleshooting
| Symptom | Cause | Fix |
|---|---|---|
| Controller never connects to hotspot | SSID or password mismatch | Verify SSID is exactly AP and password is 56784321 (case-sensitive) |
| Controller connects but computer cannot reach it | Computer on different network | Join the same hotspot on the computer โ see section 1.3 |
| Hotspot rejects Controller | Device limit reached or 5 GHz band | Increase device limit or switch hotspot to 2.4 GHz |
[0] WS Disconnected | Page loaded from file:// on mobile | Open from http://<CONTROLLER_IP>/ |
| WebSocket never connects | Client isolation on hotspot | Disable client isolation in hotspot settings |
| Commands send but motors don't move | Bus A/B swapped or GND missing | Swap A/B, ensure common GND |
| Motor moves wrong direction | Direction wiring reversed | Swap motor coil A/B or use opposite dir value |
| Only some motors respond | Address mismatch | Verify DIP switches match command address |
| Random resets during patterns | Bus noise / no termination | Add 120 ฮฉ termination at both bus ends |
Wireless name shows -NOIP | Network failed to connect | Check SSID/password on hotspot (must be AP / 56784321) |
8. Safety Notes
- Never send motor commands while a homing sequence is in progress.
- Always issue
HAon power-up before running patterns. - Use
Xonly when all motors are idle. - Do not exceed step delay below 1000 ยตs โ may cause motor stall.
- Keep the bus cable away from motor power lines to reduce noise.