const char* ssid = "YOUR_WIFI_SSID";
const char* password = "YOUR_WIFI_PASSWORD";
WebServer server(80);
void setup() {
Serial.begin(115200);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.println("Connecting to WiFi...");
}
Serial.println("WiFi connected");
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
server.on("/", handleRoot);
server.begin();
}
void loop() {
server.handleClient();
}
void handleRoot() {
server.send(200, "text/plain", "Chotu Robo Server Running");
}
</code></pre>
void loop() {
if (Serial.available() > 0) {
String command = Serial.readStringUntil('\n');
processCommand(command);
}
}
void processCommand(String command) {
// Process serial commands
if (command == "LED_ON") {
digitalWrite(13, HIGH);
Serial.println("LED turned ON");
} else if (command == "LED_OFF") {
digitalWrite(13, LOW);
Serial.println("LED turned OFF");
}
}
</code></pre>
// Initialize the MCP Server
const server = new McpServer();
const transport = new StdioServerTransport();
server.connect(transport);
// Connect to the Arduino board
const board = new Board();
board.on('ready', function() {
console.log('Board is ready!');
// Initialize components
const led = new Led(13);
const servo = new Servo(9);
const motor = new Motor([10, 11]);
// Define MCP tools
server.tool('blinkLED', async ({ time }) => {
led.blink(500);
await new Promise(resolve => setTimeout(resolve, time * 1000));
led.stop();
return { status: 'success', message: LED blinked for ${time} seconds
};
});
server.tool('moveServo', async ({ angle }) => {
servo.to(angle);
return { status: 'success', message: Servo moved to ${angle} degrees
};
});
server.tool('runMotor', async ({ speed, time }) => {
motor.speed(speed);
await new Promise(resolve => setTimeout(resolve, time * 1000));
motor.stop();
return { status: 'success', message: Motor ran at speed ${speed} for ${time} seconds
};
});
// Add more tools as needed
});
// Start the server
server.start();
</code></pre>
// Example command to read distance
{
"command": "readDistance"
}
</code></pre>
{
"command": "blinkLED",
"params": {
"time": 3
}
}
</code></pre>
const char* ssid = "YOUR_WIFI_SSID";
const char* password = "YOUR_WIFI_PASSWORD";
WebServer server(80);
void setup() {
Serial.begin(115200);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.println("Connecting to WiFi...");
}
Serial.println("WiFi connected");
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
server.on("/", handleRoot);
server.begin();
}
void loop() {
server.handleClient();
}
void handleRoot() {
server.send(200, "text/plain", "Chotu Robo Server Running");
}
</code></pre>
void loop() {
if (Serial.available() > 0) {
String command = Serial.readStringUntil('\n');
processCommand(command);
}
}
void processCommand(String command) {
// Process serial commands
if (command == "LED_ON") {
digitalWrite(13, HIGH);
Serial.println("LED turned ON");
} else if (command == "LED_OFF") {
digitalWrite(13, LOW);
Serial.println("LED turned OFF");
}
}
</code></pre>
// Initialize the MCP Server
const server = new McpServer();
const transport = new StdioServerTransport();
server.connect(transport);
// Connect to the Arduino board
const board = new Board();
board.on('ready', function() {
console.log('Board is ready!');
// Initialize components
const led = new Led(13);
const servo = new Servo(9);
const motor = new Motor([10, 11]);
// Define MCP tools
server.tool('blinkLED', async ({ time }) => {
led.blink(500);
await new Promise(resolve => setTimeout(resolve, time * 1000));
led.stop();
return { status: 'success', message: LED blinked for ${time} seconds
};
});
server.tool('moveServo', async ({ angle }) => {
servo.to(angle);
return { status: 'success', message: Servo moved to ${angle} degrees
};
});
server.tool('runMotor', async ({ speed, time }) => {
motor.speed(speed);
await new Promise(resolve => setTimeout(resolve, time * 1000));
motor.stop();
return { status: 'success', message: Motor ran at speed ${speed} for ${time} seconds
};
});
// Add more tools as needed
});
// Start the server
server.start();
</code></pre>
// Example command to read distance
{
"command": "readDistance"
}
</code></pre>
{
"command": "blinkLED",
"params": {
"time": 3
}
}
</code></pre>