The Shell class provides a Unix-like shell for issuing commands to the Arduino. The LoginShell class extends Shell to also include login functionality. The user is prompted for username and password before access is granted to shell commands.
This example shows how to use LoginShell to provide command-line access over the Internet via the telnet protocol. The example has one command "led" for turning the status LED on D13 on and off.
The full source code for the example follows:
#include <SPI.h>
#include <Ethernet.h>
#include <Shell.h>
#include <LoginShell.h>
byte macAddress[6] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
};
int ledPin = 13;
EthernetServer server(23);
EthernetClient client;
bool haveClient = false;
{
if (argc > 1 && !strcmp(argv[1], "on"))
digitalWrite(ledPin, HIGH);
else
digitalWrite(ledPin, LOW);
}
ShellCommand(led,
"Turns the status LED on or off", cmdLed);
void setup()
{
pinMode(ledPin, OUTPUT);
digitalWrite(ledPin, LOW);
Serial.begin(9600);
Serial.println();
Serial.print("Acquiring IP address ... ");
if (Ethernet.begin(macAddress))
Serial.println(Ethernet.localIP());
else
Serial.println("failed");
server.begin();
shell.setMachineName("Arduino");
}
void loop()
{
Ethernet.maintain();
if (!haveClient) {
if (client) {
haveClient = true;
}
} else if (!client.connected()) {
client.stop();
client = EthernetClient();
haveClient = false;
}
}