README
ยถ
Ultron Control
A ComputerCraft turtle control system with real-time command execution and comprehensive API.
๐ Quick Start
Start the Server
go run main.go
# Server runs on http://localhost:3300
Execute Commands (Synchronous - Default)
# Get turtle status
Invoke-RestMethod -Uri "http://localhost:3300/api/turtle/0" -Method GET
# Execute command with immediate result (default behavior)
Invoke-RestMethod -Uri "http://localhost:3300/api/turtle/0" -Method POST -ContentType "text/plain" -Body 'return turtle.getFuelLevel()'
# Queue command for background execution (legacy mode)
Invoke-RestMethod -Uri "http://localhost:3300/api/turtle/0" -Method POST -ContentType "text/plain" -Headers @{"X-Execution-Mode"="async"} -Body 'print("Background task")'
๐ฏ Key Features
โก Real-Time Command Execution (Default)
- Synchronous execution: Commands execute immediately with real-time results
- 30-second timeout: Automatic timeout protection
- Error handling: Immediate error feedback and debugging
- Interactive: Perfect for data retrieval and interactive operations
๐ Queue-Based Execution (Legacy)
- Asynchronous execution: Commands queue for background processing
- Batch operations: Multiple commands in sequence
- Long-running tasks: No timeout limitations
- Fire-and-forget: Ideal for automation and background tasks
๐ WebSocket Connection Tracking
- Enhanced connection management: Real-time turtle connection monitoring
- Automatic cleanup: Proper disconnection handling
- Debug logging: Comprehensive WebSocket event logging
- Turtle ID 0 support: Full support for all turtle IDs including 0
๐ API Documentation
Execution Modes
| Mode | Default | Header Required | Use Case | Response Time |
|---|---|---|---|---|
| Synchronous | โ Yes | None (or X-Execution-Mode: sync) |
Data retrieval, interactive commands | Immediate |
| Asynchronous | โ No | X-Execution-Mode: async |
Batch operations, long tasks | Queue confirmation |
Basic API Endpoints
GET /api/turtle- List all turtlesGET /api/turtle/{id}- Get turtle dataPOST /api/turtle/{id}- Execute command (sync by default)GET /api/turtle/usage- API usage documentation
Command Examples
Synchronous Commands (Default)
# Get fuel level (immediate result)
Invoke-RestMethod -Uri "http://localhost:3300/api/turtle/0" -Method POST -ContentType "text/plain" -Body 'return turtle.getFuelLevel()'
# Get inventory (immediate result)
Invoke-RestMethod -Uri "http://localhost:3300/api/turtle/0" -Method POST -ContentType "text/plain" -Body 'return turtle.list()'
# Move turtle (immediate success/failure)
Invoke-RestMethod -Uri "http://localhost:3300/api/turtle/0" -Method POST -ContentType "text/plain" -Body 'return turtle.forward()'
Asynchronous Commands (Legacy)
# Queue multiple commands
Invoke-RestMethod -Uri "http://localhost:3300/api/turtle/0" -Method POST -ContentType "application/json" -Headers @{"X-Execution-Mode"="async"} -Body '["turtle.forward()", "turtle.turnRight()", "turtle.forward()"]'
# Background task
Invoke-RestMethod -Uri "http://localhost:3300/api/turtle/0" -Method POST -ContentType "text/plain" -Headers @{"X-Execution-Mode"="async"} -Body 'for i=1,10 do turtle.forward() end'
๐๏ธ Architecture
Server Components
- Go HTTP Server: RESTful API with Gorilla mux
- WebSocket Handler: Real-time turtle communication
- Connection Tracking: Active connection management per turtle
- Command Execution: Hybrid sync/async execution engine
Client Components
- ComputerCraft Lua: Enhanced turtle scripts
- WebSocket Client: Real-time server communication
- Command Processing: Structured command handling
- Result Formatting: Comprehensive execution metadata
Communication Protocol
- Legacy Messages: JSON turtle data updates
- Structured Messages: Type-based message handling
- Command Responses: Request/response correlation
- Connection Management: Registration and cleanup
๐ Project Structure
โโโ main.go # Application entry point
โโโ config.toml # Configuration file
โโโ api/
โ โโโ init.go # Connection management & sync execution
โ โโโ turtle.go # Main turtle API handlers
โ โโโ global.go # Shared data structures
โ โโโ setup.go # API route setup
โโโ static/
โ โโโ turtle.lua # Main turtle program
โ โโโ ultron.lua # Enhanced turtle library
โ โโโ pastebin.lua # Auto-update utility
โ โโโ startup.lua # Turtle startup script
โโโ .copilot/
โโโ api-documentation.md # Complete API documentation
โโโ test-commands.md # Test commands and results
โโโ session-notes.md # Development notes
๐งช Testing
Automated Tests
# Test basic turtle status
Invoke-RestMethod -Uri "http://localhost:3300/api/turtle" -Method GET
# Test default sync execution
Invoke-RestMethod -Uri "http://localhost:3300/api/turtle/0" -Method POST -ContentType "text/plain" -Body 'return "test"'
# Test legacy async execution
Invoke-RestMethod -Uri "http://localhost:3300/api/turtle/0" -Method POST -ContentType "text/plain" -Headers @{"X-Execution-Mode"="async"} -Body 'print("test")'
Development Tools
- Air: Live reload development server
- PowerShell: Windows-compatible testing commands
- VS Code: Integrated development environment
- ComputerCraft: Minecraft mod for turtle execution
๐ง Configuration
Server Configuration (config.toml)
[server]
port = 3300
static_dir = "static"
work_dir = "workdir"
Environment Setup
- Install Go 1.19+
- Install ComputerCraft mod
- Configure turtle scripts
- Start development server with Air
๐ Deployment
Development
# Install Air for live reload
go install github.com/cosmtrek/air@latest
# Start development server
air
Production
# Build binary
go build -o ultron-control
# Run server
./ultron-control
๐ฎ ComputerCraft Setup
Turtle Installation
-- Run this in ComputerCraft turtle to install Ultron scripts
shell.run("rm", "startup.lua")
shell.run("pastebin", "get", "XWDutV7S", "startup.lua")
shell.run("startup.lua")
Turtle Requirements
- ComputerCraft mod installed
- Turtle with networking capability
- Connection to server (localhost:3300)
๐ Recent Updates
v2.0 - Synchronous Default
- โก Default Mode Change: Synchronous execution is now default
- ๐ Enhanced WebSocket: Improved connection tracking and cleanup
- ๐ Turtle ID 0 Fix: Full support for turtle ID 0
- ๐ Better Logging: Comprehensive debug output
- ๐ Documentation: Complete API documentation and examples
v1.0 - Foundation
- ๐๏ธ Core API: Basic turtle control API
- ๐ Async Commands: Queue-based command execution
- ๐ก WebSocket Communication: Real-time turtle communication
- ๐ฎ ComputerCraft Integration: Lua script integration
๐ค Contributing
- Fork the repository
- Create feature branch (
git checkout -b feature/amazing-feature) - Commit changes (
git commit -m 'Add amazing feature') - Push to branch (
git push origin feature/amazing-feature) - Open Pull Request
๐ License
This project is licensed under the MIT License - see the LICENSE file for details.
๐โโ๏ธ Support
For questions, issues, or contributions:
- Check the API Documentation
- Review Test Commands
- Open an issue for bugs or feature requests
Documentation
ยถ
There is no documentation for this package.
Click to show internal directories.
Click to hide internal directories.